signed integer overflow in cache.c

123 <[email protected]>
Newsgroups gmane.comp.web.dillo.devel
Message-ID <[email protected]>
In function Cache_client_enqueue variable ClientKey is incremented and
checked for negative values after that (in case of overflow).

Even though overflow is unlikely, signed integer overflow results in
wraparound on most systems and gcc don't seem to optimize away
overflow check even with -O3 (it only inlines Cache_client_enqueue in
my case) it is better to avoid overflow completely as there are other
compilers and compiler versions.

_______________________________________________
Dillo-dev mailing list
[email protected]
http://lists.auriga.wearlab.de/cgi-bin/mailman/listinfo/dillo-dev
intoverflow.patch (text/plain, 343 B)
diff -r c3f8d2d9831a src/cache.c
--- a/src/cache.c
+++ b/src/cache.c
@@ -142,7 +142,9 @@
    static int ClientKey = 0; /* Provide a primary key for each client */
    CacheClient_t *NewClient;
 
-   if (++ClientKey <= 0)
+   if (ClientKey < INT_MAX)
+      ClientKey++;
+   else
       ClientKey = 1;
 
    NewClient = dNew(CacheClient_t, 1);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.