Novice question about malloc and pointers
John F. Woods
jfw at ksr.com
Tue Apr 23 02:48:37 AEST 1991
scs at adam.mit.edu (Steve Summit) writes:
>In article <3182 at ksr.com> jfw at ksr.com (John F. Woods) writes:
>> /* Treasure the line in a copy */
>> if ((str[i] = malloc(strlen(buf))) == NULL) {
>Make that malloc(strlen(buf) + 1). (Side note: never tangle your
>fingers and type malloc(strlen(buf + 1)), either.)
Oops.
Consider that another reason to use strdup() if you've got it.
Assuming the library writer didn't screw up, too. :-)
More information about the Comp.lang.c
mailing list