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

[tor-commits] [tor/maint-0.2.2] Fix a potentially useless integer overflow check.



commit 1ba90ab655fab036f00ba0185ca7b456612a12bd
Author: Mansour Moufid <mansourmoufid@xxxxxxxxx>
Date:   Mon Sep 19 21:25:23 2011 -0400

    Fix a potentially useless integer overflow check.
    
    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 |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/common/OpenBSD_malloc_Linux.c b/src/common/OpenBSD_malloc_Linux.c
index 19dac77..445135c 100644
--- a/src/common/OpenBSD_malloc_Linux.c
+++ b/src/common/OpenBSD_malloc_Linux.c
@@ -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)

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits