Memory Fault
Henry Spencer
henry at zoo.toronto.edu
Sun Jul 22 13:57:15 AEST 1990
In article <189 at S5000.UUCP> gh at S5000.UUCP (Sys Admin) writes:
> * CODE NOT TESTED, HOWEVER IT SHOULD WORK FINE FOR simped.
"Code not tested" means "code contains bugs". Always.
>if (buffer = (char *) malloc(strlen(string)) == NULL)
Try
if ((buffer = (char *) malloc(strlen(string)+1)) == NULL)
instead. The turkey has forgotten that == binds tighter than =, and that
strlen does not count the terminating NUL.
While you're at it, you might change that ridiculous final loop to
something like "strcpy(buffer, string);", which would be clearer and
much faster.
If this is the standard of quality of the rest of the code, I strongly
urge that you never use this editor for anything important. The author
clearly does not know C.
--
NFS: all the nice semantics of MSDOS, | Henry Spencer at U of Toronto Zoology
and its performance and security too. | henry at zoo.toronto.edu utzoo!henry
More information about the Comp.lang.c
mailing list