httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "César Leonardo Blum Silveira" <cesa...@gmail.com>
Subject Re: Question regarding the use of DBMs
Date Tue, 06 May 2008 17:20:34 GMT
On Mon, May 5, 2008 at 7:11 PM, ed <ed-http@s5h.net> wrote:
>
> On Mon, 5 May 2008 18:04:15 -0300
>  "César Leonardo Blum Silveira" <cesarbs@gmail.com> wrote:
>
>  > Hello,
>  >
>  > What is the correct way to fill the dsize field in apr_datum_t? I am
>  > not sure whether I should do it like this
>  >
>  > apr_datum_t d;
>  >
>  > d.dptr = "hello, world";
>  > d.dsize = strlen(d.dptr);
>  >
>  > or like this
>  >
>  > apr_datum_t d;
>  >
>  > d.dptr = "hello, world";
>  > d.dsize = strlen(d.dptr) + 1;
>  >
>  > Could anyone tell me whether the +1 in the second case is really
>  > necessary?
>  >
>  > Thanks,
>
>  "hello" =
>
>   +---+---+---+---+---+---+
>   | h | e | l | l | o | 0 |
>   +---+---+---+---+---+---+
>
>  That 0 at the end is the null terminator. It is automatically included
>  in the string literal "hello, world". Although you did not explicitly
>  put it there it will still be required during string operations
>  otherwise you will enter overflow.
>
>  If on the other hand you're just using it as a raw memory (for image
>  data etc) then it's not required, but you're unlikely to use strncpy on
>  this sort of data.
>
>  strlen will return 5 when you give it the string "hello", but if you
>  want to put "hello" into some memory then you better have 6 bytes of
>  memory ready.
>

Thanks. The thing is that I didn't know whether DBMs "expected"
strings or could store any kind of data. Now it makes more sense to
add the +1 after strlen

>
>  --
>  The DS3 to the Xbox is toast because of All your base are belong to us.
>  Earthlink is being bought by AOL.
>  :: http://www.s5h.net/ :: http://www.s5h.net/gpg.html
>



-- 
César L. B. Silveira

Mime
View raw message