[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [or-cvs] Force tor_malloc(0) to always be sane
- To: or-dev@freehaven.net
- Subject: Re: [or-cvs] Force tor_malloc(0) to always be sane
- From: Ben Laurie <ben@algroup.co.uk>
- Date: Thu, 08 Apr 2004 18:36:59 +0100
- Cc: or-cvs@freehaven.net
- Delivered-to: archiver@seul.org
- Delivered-to: or-dev-outgoing@seul.org
- Delivered-to: or-dev@seul.org
- Delivery-date: Thu, 08 Apr 2004 13:37:19 -0400
- In-reply-to: <20040408030510.A33D733B69@moria.seul.org>
- References: <20040408030510.A33D733B69@moria.seul.org>
- Reply-to: or-dev@freehaven.net
- Sender: owner-or-dev@freehaven.net
- User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7b) Gecko/20040316
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