This is a classic/basic 'C' programming mistake you made, not an OpenSSL one:

pointers are not arrays are not strings ;-)

sizeof(buf) == ?

buf is of type 'char *' and therefore sizeof(buf) == sizeof(char *)
which is probably 4 or 8, depending on what platform you build this
for.
If you wish to provide the length of the C string data, pointed at by
pointer 'buf', then strlen() is your man:

either

BIO_puts(b, buf) -- which does this internally

or

BIO_write(b, buf, strlen(buf))



On Thu, May 28, 2009 at 10:15 AM, jaze lee <jaze...@gmail.com> wrote:
> hello,
>      #include <openssl/bio.h>
>  2 int main()  {
>  3     BIO * b;
>  4    char buf[100] = "hello world \n";
>  5     b = BIO_new(BIO_s_file());
>  6     BIO_set_fp(b, stdout, BIO_NOCLOSE);
>  7     BIO_write(b, buf, sizeof(buf));
>  8     return 0;
>  9 }
> after compile , and run, i can see the hello world
> but if the source code be changed like this
>  1 #include <openssl/bio.h>
>  2 int biotest(char * buf)  {
>  3     BIO * b;
>  4 //  char buf[100] = "hello world \n";
>  5     b = BIO_new(BIO_s_file());
>  6     BIO_set_fp(b, stdout, BIO_NOCLOSE);
>  7     BIO_write(b, buf, sizeof(buf));
>  8     return 0;
>  9 }
>  10 int main()
>  11 {
>  12     char buf[100] = "hello world\n";
>  13     biotest(buf);
>  14     return 0;
>  15 }
> compile and run, i can only see the hell on my terminal , who knows why, thank
> ______________________________________________________________________
> OpenSSL Project                                 http://www.openssl.org
> User Support Mailing List                    openssl-us...@openssl.org
> Automated List Manager                           majord...@openssl.org
>
>



-- 
Met vriendelijke groeten / Best regards,

Ger Hobbelt

--------------------------------------------------
web:    http://www.hobbelt.com/
        http://www.hebbut.net/
mail:   g...@hobbelt.com
mobile: +31-6-11 120 978
--------------------------------------------------
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to