On Thu, 22 Feb 2001, Tony Lambiris wrote:

> struct utsname *host_uname;
> 
> os_version = malloc(strlen(host_uname->release));
> os_version = (host_uname->release);
> 
> it gives me 2.4.1, no problem... but when I try to get the OS name,
> 
> system_os = malloc(strlen(host_uname->sysname));
> system_os = (host_uname->sysname);
> 
> it gives me garbage, more precisely: �K@�K@

In both cases, you're malloc'ing one byte too little. You need to malloc
enough space to hold the string plus the terminating null byte:

    os_version = malloc(1 + strlen(host_uname->release));
    system_os = malloc(1 + strlen(host_uname->sysname));

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

--
John Abreau / Executive Director, Boston Linux & Unix 
ICQ#28611923 / AIM abreauj / Email [EMAIL PROTECTED]


**********************************************************
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