[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [or-cvs] Force tor_malloc(0) to always be sane



Nick Mathewson wrote:

Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv29516/src/common

Modified Files:
util.c Log Message:
Force tor_malloc(0) to always be sane

Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -d -r1.84 -r1.85
--- util.c 7 Apr 2004 21:36:03 -0000 1.84
+++ util.c 8 Apr 2004 03:05:08 -0000 1.85
@@ -69,6 +69,10 @@
void *tor_malloc(size_t size) {
void *result;
+ /* Some libcs don't do the right thing on size==0. Override them. */
+ if (size==0) {
+ size=1;
+ }
result = malloc(size);
if(!result) {
Interesting. I've always thought the sane thing to do for a 0 allocation is to return NULL.

Cheers,

Ben.

--
http://www.apache-ssl.org/ben.html http://www.thebunker.net/

"There is no limit to what a man can do or how far he can go if he
doesn't mind who gets the credit." - Robert Woodruff