From 0a8f45876802ce036b11f287ed3d693ff128c196 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Sat, 25 Aug 2012 13:05:53 +0200 Subject: 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 --- src/cache.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') 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 +#include #include #include @@ -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); -- cgit v1.2.3