FreeBSD's malloc problem ?

Anton Alin-Adrian aanton at reversedhell.net
Sat Apr 24 11:58:36 PDT 2004


Nicolas Rachinsky wrote:
> * Anton Alin-Adrian <aanton at reversedhell.net> [2004-04-24 21:27 +0300]:
> 
>>	tmp = (char *) malloc(strlen(s)); // line 68
> 
> 
> Hmm, you need strlen(s)+1 bytes to store the string -- don't forget
> the trailing null byte.
> 
> Nicolas

And let there be light... DANG.. well it almost blinded me. I was confusing 
with char[16], which has the +1 byte for the null terminating, but the 
malloc(16) hasn't...

Probably doesn't crash on Linux because the malloced space is not adjacent.

Thanks for the candle.

Appologises to everyone.

-- 
Alin-Adrian Anton
Reversed Hell Networks
GPG keyID 0x1E2FFF2E (2963 0C11 1AF1 96F6 0030 6EE9 D323 639D 1E2F FF2E)
gpg --keyserver pgp.mit.edu --recv-keys 1E2FFF2E


More information about the freebsd-hackers mailing list