[master] d571dc7 rewrite 0U - VSL_SEGMENTS in way which should make Flexelint happy
Nils Goroll
nils.goroll at uplex.de
Mon Jun 29 14:03:58 CEST 2015
commit d571dc72548ce4defa00fe69e9d09b0216930a89
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Mon Jun 29 13:59:52 2015 +0200
rewrite 0U - VSL_SEGMENTS in way which should make Flexelint happy
We intentionally provoke an early wrap of our segment_n unsigned int.
The previous code is fine according to
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
"A computation involving unsigned operands can never overflow...",
but nevertheless we don't want to trigger Flexelint warnings.
Thanks to Dag Haavi Finstad for digging the ISO standards url.
diff --git a/bin/varnishd/cache/cache_shmlog.c b/bin/varnishd/cache/cache_shmlog.c
index 06b0f49..9bb7d1e 100644
--- a/bin/varnishd/cache/cache_shmlog.c
+++ b/bin/varnishd/cache/cache_shmlog.c
@@ -461,7 +461,7 @@ VSM_Init(void)
vsl_end = vsl_head->log + vsl_segsize * VSL_SEGMENTS;
/* Make segment_n always overflow on first log wrap to make any
problems with regard to readers on that event visible */
- vsl_segment_n = 0U - VSL_SEGMENTS;
+ vsl_segment_n = UINT_MAX - VSL_SEGMENTS + 1;
AZ(vsl_segment_n % VSL_SEGMENTS);
vsl_head->segment_n = vsl_segment_n;
vsl_ptr = vsl_head->log;
More information about the varnish-commit
mailing list