
alvaro at sun
May 26, 2008, 10:27 PM
Post #2 of 5
(276 views)
Permalink
|
On 27 May 2008, at 03:42, Stefan de Konink wrote: > I think I cannot sleep if someone doesn't pick this one up. > > Could any of the core devs *verify* the correct working of > cherokee_buffer_add > > Shouldn't this end up in the same output? > > cherokee_buffer_add(buf, "TEST", sizeof("TEST")); I bet you meant strlen() rather than sizeof(). :-) sizeof() gives you the total amount of memory that a certain static data or data type requires. In this case it returns 5 because that is actually the memory that it needed to allocate to copy the string: "TEST\0". > cherokee_buffer_add_str(buf, "TEST"); Yeah, this is kind of tricky. By Cherokee's notation, *_str() means that the method works with an *STATIC* string. Even it they look very similar there is a quite big difference between static data and pointers to data: /* sizeof ("hello world") = 12 */ /* strlen ("hello world") = 11 */ and char *test = "hello world"; /* sizeof (test) = 4 */ /* strlen (test) = 11 */ .. the joys of C, you know! > In the first line, the output gets an extra garbage char. I hope I've got back to you quick enough for you to have some sleeping :-) -- Greetings, alo. _______________________________________________ Cherokee mailing list Cherokee[at]cherokee-project.com http://cherokee-project.com/cgi-bin/mailman/listinfo/cherokee
|