Skip to contentSkip to conversation

kmalloc() with size zero

DISCUSSION Stephane Eranian 6 participants 7 messages Mar 23, 2007 – Mar 29, 2007

lore
Share & tools
lore
#0 lore raw

Hello,

I ran into an issue with perfmon where I ended up calling kmalloc() with a size of zero. To my surprise, this did not return NULL but a valid data address.

I am wondering if this is a property of kmalloc() or simply a bug. It is the case that the __kmalloc() code does not check for zero size.

Thanks,

Signature · 1 line
-Stephane
#1 lore raw
Quoted 10 lines · Stephane Eranian

Hello,

I ran into an issue with perfmon where I ended up calling kmalloc() with a size of zero. To my surprise, this did not return NULL but a valid data address.

I am wondering if this is a property of kmalloc() or simply a bug. It is the case that the __kmalloc() code does not check for zero size.

I'd say "feature", glibc's malloc also returns an address on malloc(0).

Jan

#2 lore raw
Quoted 6 lines · Jan Engelhardt
Quoted 1 line · Stephane Eranian

I'd say "feature", glibc's malloc also returns an address on malloc(0).

This is implementation defined-the standard allows for return of either null or an address.

Quoted 11 lines

Jan
--
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 4 lines
Regards,  
Vignesh Babu BM  
_____________________________________________________________  
"Why is it that every time I'm with you, makes me believe in magic?"
#3 lore raw
Quoted 5 lines
Quoted 3 lines

I'd say "feature", glibc's malloc also returns an address on malloc(0).

This is implementation defined-the standard allows for return of either null or an address.

Entirely for entertainment: AIX (5.3) returns NULL, IRIX returns a valid address.

Folkert van Heusden

Signature · 5 lines
MultiTail är en flexibel redskap för att fälja logfilar, utför av
commandoer, filtrera, ge färg, sammanfoga, o.s.v. följa.
http://www.vanheusden.com/multitail/
----------------------------------------------------------------------
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
#4 lore raw

Hi,

Quoted 9 lines · Folkert van Heusden
Quoted 5 lines
Quoted 3 lines

I'd say "feature", glibc's malloc also returns an address on malloc(0).

This is implementation defined-the standard allows for return of either null or an address.

Entirely for entertainment: AIX (5.3) returns NULL, IRIX returns a valid address.

That's interesting, so many different behaviors! Personally, I still prefer when malloc(0) returns zero because it makes it easier to catch errors.

Signature · 1 line
-Stephane
#5 lore raw
Quoted 6 lines · Stephane Eranian

Hi,

Quoted 3 lines · Folkert van Heusden
Quoted 3 lines
Quoted 3 lines

I'd say "feature", glibc's malloc also returns an address on malloc(0).

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

This is implementation defined-the standard allows for return of either null or an address.

Entirely for entertainment: AIX (5.3) returns NULL, IRIX returns a valid address.

That's interesting, so many different behaviors! Personally, I still prefer when malloc(0) returns zero because it makes it easier to catch errors.

Exactly, the address returned is not really useful, the improved error checking is useful.

Signature · 3 lines
Bill Davidsen <[email protected]>
  "We have more to fear from the bungling of the incompetent than from
the machinations of the wicked."  - from Slashdot
#6 lore raw
In reply to Stephane Eranian
Quoted 7 lines · Stephane Eranian

I ran into an issue with perfmon where I ended up calling kmalloc() with a size of zero. To my surprise, this did not return NULL but a valid data address.

I am wondering if this is a property of kmalloc() or simply a bug. It is the case that the __kmalloc() code does not check for zero size.

Correct SLAB will give you the smallest possible allocation. I'd say these calls should be fixed. SLUB does check for zero and will throw a stack dump.