On Thu, 22 Feb 2001, John Abreau wrote:
>> system_os = malloc(strlen(host_uname->sysname));
>> system_os = (host_uname->sysname);
> 
> In both cases, you're malloc'ing one byte too little.

  Actually, in both cases, the OP is malloc'ing way too many bytes.  Any
amount is too many, you see.  The OP immediately loses the pointer he just got
from malloc by replacing it with the value in the host_uname->sysname pointer.  
He should either use strcpy(), or not bother allocating a second buffer at
all.

> You got lucky on the first malloc, in that the memory location where the
> null byte was written apparently didn't break anything.

#ifdef PEDANTIC

  NUL bytes terminate a string.

  NULL pointers point to nothing.

#endif

  ;-)

-- 
Ben Scott <[EMAIL PROTECTED]>
Net Technologies, Inc. <http://www.ntisys.com>
Voice: (800)905-3049 x18   Fax: (978)499-7839


**********************************************************
To unsubscribe from this list, send mail to
[EMAIL PROTECTED] with the following text in the
*body* (*not* the subject line) of the letter:
unsubscribe gnhlug
**********************************************************

Reply via email to