bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] malloc((1 << 31) - 1) must return 0


From: Ognyan Kulev
Subject: [PATCH] malloc((1 << 31) - 1) must return 0
Date: Mon, 25 Mar 2002 19:28:11 +0200
User-agent: Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:0.9.9) Gecko/20020311

Hi,

In `libc/hurd/hurdmalloc.c:281' there is an assertion that is triggered when SIZE has value ((1 << 31) - 1). Instead of assertion failure the function must return 0. Here is a patch that checks SIZE in different way.

BTW I didn't compile neither the previous patched `hurdchdir.c' nor this patched `hurdmalloc.c'. I'm not sure if the second test in the `if' statement is completely correct (you know, c-casting, int < unsigned).

Regards
--
Ognyan Kulev <ogi@fmi.uni-sofia.bg>, "\"Programmer\""
2002-03-25  Ognyan Kulev <ogi@fmi.uni-sofia.bg>

         * hurdmalloc.c (malloc): The sanity check for SIZE is rewritten.
--- hurdmalloc.c.orig   Mon Mar 25 16:30:17 2002
+++ hurdmalloc.c        Mon Mar 25 19:16:56 2002
@@ -265,9 +265,10 @@ malloc(size)
        register free_list_t fl;
        register header_t h;
 
-       if ((int) size < 0)             /* sanity check */
-               return 0;
        size += HEADER_SIZE;
+       if (size < HEADER_SIZE
+           || (1 << (NBUCKETS - 1 + LOG2_MIN_SIZE)) < size)
+         return 0;
        /*
         * Find smallest power-of-two block size
         * big enough to hold requested size plus header.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]