diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2012-08-25 13:05:53 +0200 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2012-08-25 13:05:53 +0200 |
commit | 0a8f45876802ce036b11f287ed3d693ff128c196 (patch) | |
tree | 9d62805ad0aa196cb0756b32d85813e39ed4fabf /src | |
parent | 20ca21ecde239794eae7752a9cf9935e69d495e6 (diff) |
improve check for integer overflow
As the behaviour of int overflow is not defined we
rather check for it before incrementing the variable.
Submitted-by: p37sitdu@lavabit.com
Diffstat (limited to 'src')
-rw-r--r-- | src/cache.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/cache.c b/src/cache.c index 11c7faf3..ea9d9a1f 100644 --- a/src/cache.c +++ b/src/cache.c @@ -15,6 +15,7 @@ #include <sys/types.h> +#include <limits.h> #include <stdlib.h> #include <string.h> @@ -142,7 +143,9 @@ static int Cache_client_enqueue(const DilloUrl *Url, DilloWeb *Web, static int ClientKey = 0; /* Provide a primary key for each client */ CacheClient_t *NewClient; - if (++ClientKey <= 0) + if (ClientKey < INT_MAX) /* check for integer overflow */ + ClientKey++; + else ClientKey = 1; NewClient = dNew(CacheClient_t, 1); |