Chad <> writes:
> When the following functions takes the string "this is a string"
>
> static void *build_string(char *s)
> {
> int k;
> char *start;
> size_t len;
> size_t max;
>
> len = strlen(s);
>
> if(len == 0) {
> fprintf(stderr,"Zero length");
> exit(EXIT_FAILURE);
> }
>
> max = 1024/len;
>
> char *p = malloc((max*len) + sizeof(p));
[snip]
You already mentioned the lack of space for the '\0', but why the
"sizeof(p)" term? Why do you need to allocate space for a pointer in
a character array?
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"