Newsgroups: comp.lang.c Path: utzoo!henry From: henry@zoo.toronto.edu (Henry Spencer) Subject: Re: Memory Fault Message-ID: <1990Jul22.035715.12899@zoo.toronto.edu> Organization: U of Toronto Zoology References: <189@S5000.UUCP> Date: Sun, 22 Jul 90 03:57:15 GMT In article <189@S5000.UUCP> gh@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@zoo.toronto.edu utzoo!henry