]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Fix a potentially useless integer overflow check.
authorMansour Moufid <mansourmoufid@gmail.com>
Tue, 20 Sep 2011 01:25:23 +0000 (21:25 -0400)
committerNick Mathewson <nickm@torproject.org>
Tue, 20 Sep 2011 13:52:44 +0000 (09:52 -0400)
GCC 4.2 and maybe other compilers optimize away unsigned integer
overflow checks of the form (foo + bar < foo), for all bar.

Fix one such check in `src/common/OpenBSD_malloc_Linux.c'.

src/common/OpenBSD_malloc_Linux.c

index 19dac776578e8a6719fd1ce9ddf8407cc3a45c63..445135c6bba09dbc504bf300ae28917339ac7693 100644 (file)
@@ -1236,7 +1236,7 @@ imalloc(size_t size)
                ptralloc = 1;
                size = malloc_pagesize;
        }
-       if ((size + malloc_pagesize) < size) {  /* Check for overflow */
+       if (size > SIZE_MAX - malloc_pagesize) { /* Check for overflow */
                result = NULL;
                errno = ENOMEM;
        } else if (size <= malloc_maxsize)