pointers are not arrays are not strings ;-)
sizeof(buf) =3D=3D ?
buf is of type 'char *' and therefore sizeof(buf) =3D=3D 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 <jaz...@gmail.com> wrote:
> hello,
> =A0 =A0 =A0#include <openssl/bio.h>
> =A02 int main() =A0{
> =A03 =A0 =A0 BIO * b;
> =A04 =A0 =A0char buf[100] =3D "hello world \n";
> =A05 =A0 =A0 b =3D BIO_new(BIO_s_file());
> =A06 =A0 =A0 BIO_set_fp(b, stdout, BIO_NOCLOSE);
> =A07 =A0 =A0 BIO_write(b, buf, sizeof(buf));
> =A08 =A0 =A0 return 0;
> =A09 }
> after compile , and run, i can see the hello world
> but if the source code be changed like this
> =A01 #include <openssl/bio.h>
> =A02 int biotest(char * buf) =A0{
> =A03 =A0 =A0 BIO * b;
> =A04 // =A0char buf[100] =3D "hello world \n";
> =A05 =A0 =A0 b =3D BIO_new(BIO_s_file());
> =A06 =A0 =A0 BIO_set_fp(b, stdout, BIO_NOCLOSE);
> =A07 =A0 =A0 BIO_write(b, buf, sizeof(buf));
> =A08 =A0 =A0 return 0;
> =A09 }
> =A010 int main()
> =A011 {
> =A012 =A0 =A0 char buf[100] =3D "hello world\n";
> =A013 =A0 =A0 biotest(buf);
> =A014 =A0 =A0 return 0;
> =A015 }
> compile and run, i can only see the hell on my terminal , who knows why, =
thank
> ______________________________________________________________________
> OpenSSL Project =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 http://www.openssl.org
> User Support Mailing List =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0openssl-=
us...@openssl.org
> Automated List Manager =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 majo...@openssl.org
>
>
--=20
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
--------------------------------------------------
> 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))
Only if the data is text. Using strlen() on binary data is another
classic/basic 'C' programming mistake.
--
Viktor.
=D4=DA2009-05-28=A3=AC"Victor Duchovni" <Victor....@morganstanley.com>=
=D0=B4=B5=C0=A3=BA
>On Thu, May 28, 2009 at 11:51:42AM +0200, Ger Hobbelt wrote:
>
>> This is a classic/basic 'C' programming mistake you made, not an OpenSSL=
one:
>>=20
>> pointers are not arrays are not strings ;-)
>>=20
>> sizeof(buf) =3D=3D ?
>>=20
>> buf is of type 'char *' and therefore sizeof(buf) =3D=3D 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:
>>=20
>> either
>>=20
>> BIO_puts(b, buf) -- which does this internally
>>=20
>> or
>>=20
>> BIO_write(b, buf, strlen(buf))
>
>Only if the data is text. Using strlen() on binary data is another
>classic/basic 'C' programming mistake.
if it is binary data, what to do ? Use a Variable to send the the size ?
>
>--=20
>=09Viktor.
>______________________________________________________________________
>OpenSSL Project http://www.openssl.org
>User Support Mailing List openss...@openssl.org
>Automated List Manager majo...@openssl.org
------=_Part_8222_32006444.1243560439637
Content-Type: text/html; charset=gbk
Content-Transfer-Encoding: quoted-printable
<div><br><br></div><div></div><br><pre>=D4=DA2009-05-28=A3=AC"Victor Duchov=
ni" <Victor....@morganstanley.com> =D0=B4=B5=C0=A3=BA<br>>On =
Thu, May 28, 2009 at 11:51:42AM +0200, Ger Hobbelt wrote:<br>><br>>&g=
t; This is a classic/basic 'C' programming mistake you made, not an OpenSSL=
one:<br>>> <br>>> pointers are not arrays are not strings ;-)<=
br>>> <br>>> sizeof(buf) =3D=3D ?<br>>> <br>>> buf =
is of type 'char *' and therefore sizeof(buf) =3D=3D sizeof(char *)<br>>=
> which is probably 4 or 8, depending on what platform you build this<br=
>>> for.<br>>> If you wish to provide the length of the C strin=
g data, pointed at by<br>>> pointer 'buf', then strlen() is your man:=
<br>>> <br>>> either<br>>> <br>>> BIO_puts(b, buf) =
-- which does this internally<br>>> <br>>> or<br>>> <br>&=
gt;> BIO_write(b, buf, strlen(buf))<br>><br>>Only if the data is t=
ext. Using strlen() on binary data is another<br>>classic/basic 'C' prog=
ramming mistake.<br>if it is binary data, what to do ? Use a Variable to s=
end the the size ?<br>>
>--=20
>=09Viktor.
>______________________________________________________________________
>OpenSSL Project http://www.openssl.org
>User Support Mailing List openss...@openssl.org
>Automated List Manager majo...@openssl.org
</pre><br><!-- footer --><br><span title=3D"neteasefooter"/><hr/>
<a href=3D"http://512.mail.163.com/mailstamp/stamp/dz/activity.do?from=3Dfo=
oter">=B4=A9=D4=BD=B5=D8=D5=F0=B4=F8 =BC=CD=C4=EE=E3=EB=B4=A8=B5=D8=D5=F0=
=D2=BB=D6=DC=C4=EA</a>
</span>
------=_Part_8222_32006444.1243560439637--
yes.
Just like the BIO_read, BIO_write, fwrite, etc. APIs all do too: pass
along a pointer /and/ a length parameter.
--
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
--------------------------------------------------
=D4=DA2009-05-29=A3=AC"Ger Hobbelt" <g...@hobbelt.com> =D0=B4=B5=C0=A3=BA
>2009/5/29 jazeltq <jaz...@163.com>:
>> =D4=DA2009-05-28=A3=AC"Victor Duchovni" <Victor.Duchovni@morganstanley.c=
om> =D0=B4=B5=C0=A3=BA
>>>On Thu, May 28, 2009 at 11:51:42AM +0200, Ger Hobbelt wrote:
>>>
>>>Only if the data is text. Using strlen() on binary data is another
>>>classic/basic 'C' programming mistake.
>> if it is binary data, what to do ? Use a Variable to send the the size =
?
>
>yes.
>
>Just like the BIO_read, BIO_write, fwrite, etc. APIs all do too: pass
>along a pointer /and/ a length parameter.
Thank you, i get it
>
>--=20
>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 openss...@openssl.org
>Automated List Manager majo...@openssl.org
------=_Part_74341_12357036.1243643778317
Content-Type: text/html; charset=gbk
Content-Transfer-Encoding: quoted-printable
<div><br><br></div><div></div><br><pre>=D4=DA2009-05-29=A3=AC"Ger Hobbelt" =
<g...@hobbelt.com> =D0=B4=B5=C0=A3=BA
>2009/5/29 jazeltq <jaz...@163.com>:
>> =D4=DA2009-05-28=A3=AC"Victor Duchovni" <Victor.Duchovni@morgan=
stanley.com> =D0=B4=B5=C0=A3=BA
>>>On Thu, May 28, 2009 at 11:51:42AM +0200, Ger Hobbelt wrote:
>>>
>>>Only if the data is text. Using strlen() on binary data is anot=
her
>>>classic/basic 'C' programming mistake.
>> if it is binary data, what to do ? Use a Variable to send the the=
size ?
>
>yes.
>
>Just like the BIO_read, BIO_write, fwrite, etc. APIs all do too: pass
>along a pointer /and/ a length parameter.
Thank you, i get it<br>>
>--=20
>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 openss...@openssl.org
>Automated List Manager majo...@openssl.org
</pre><br><!-- footer --><br><span title=3D"neteasefooter"/><hr/>
<a href=3D"http://512.mail.163.com/mailstamp/stamp/dz/activity.do?from=3Dfo=
oter">=B4=A9=D4=BD=B5=D8=D5=F0=B4=F8 =BC=CD=C4=EE=E3=EB=B4=A8=B5=D8=D5=F0=
=D2=BB=D6=DC=C4=EA</a>
</span>
------=_Part_74341_12357036.1243643778317--