Path: utzoo!utgpu!cunews!cognos!jimp From: jimp@cognos.UUCP (Jim Patterson) Newsgroups: comp.lang.c Subject: Re: Dynamic Storage Allocator Pros and Cons Message-ID: <9052@cognos.UUCP> Date: 15 Nov 90 19:43:56 GMT References: <241@smds.UUCP> Reply-To: jimp@cognos.UUCP (Jim Patterson) Organization: Cognos Inc., Ottawa, Canada Lines: 35 In article <241@smds.UUCP> rh@smds.UUCP (Richard Harter) writes: >Security and Error Checking: > >This is the reason for using G/R, if it matters to you. Specifically >the features are: > >(A) All invalid size requests (zero, negative, too large) are trapped. ^^^^ Whether a 0 size request is invalid is a matter of interpretation. Note that ANSI C specifically allows it; if you disallow it, then getsp/remsp aren't really equivalent to malloc/free. There are often times when a 0-byte request is legitimate. Usually this comes up in logic that looks like this: Count the number of (some thing) Allocate memory for that many struct's to describe those things (where it's legitimate for there to be 0 or more things). As long as you only look at entries which you've counted and know are there, the code is quite valid since it won't look at the pointer when the count is 0. We in fact have a wrapper around malloc/free that does much the same things as yours, and it too disallows 0 size requests. However, in just about every case I can recall where it complained of a 0-byte request, the code was actually not broken, it just hadn't considered 0 to be a special case. So, this check isn't really a "good thing" IMHO. -- Jim Patterson Cognos Incorporated UUCP:uunet!mitel!cunews!cognos!jimp P.O. BOX 9707 PHONE:(613)738-1440 3755 Riverside Drive NOT a Jays fan (not even a fan) Ottawa, Ont K1G 3Z4