Memory Fault

Barry Margolin barmar at think.com
Sun Jul 22 13:32:14 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.

Famous last words...

>if (buffer = (char *) malloc(strlen(string)) == NULL)

Common error: it should be strlen(string)+1.  Strlen() doesn't include the
trailing '\0' in its result, but you need to allocate room for it.
--
Barry Margolin, Thinking Machines Corp.

barmar at think.com
{uunet,harvard}!think!barmar



More information about the Comp.lang.c mailing list