blob: 2979552a34064e446915c39ec22c4833bd642137 [file] [log] [blame]
Andrew Geissler69721092021-07-23 12:57:00 -04001From d6294e9166e4875a0572349aabcc5e51acbd2e3c Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Fri, 4 Jun 2021 11:33:12 -0700
4Subject: [PATCH] stats_prefix.c: Check for NDEBUG before using total_written
5 variable
6
7When using NDEBUG assert macro is ineffective which is caught by latest
8clang and reports that total_written is set but unused. Therefore check
9for NDEBUG to make sure assert is used only when its effective
10
11Fixes
12error: variable 'total_written' set but not used [-Werror,-Wunused-but-set-variable]
13 size_t size = 0, written = 0, total_written = 0;
14 ^
15Upstream-Status: Submitted [https://github.com/memcached/memcached/pull/792]
16Signed-off-by: Khem Raj <raj.khem@gmail.com>
17---
18 stats_prefix.c | 8 ++++++--
19 1 file changed, 6 insertions(+), 2 deletions(-)
20
21diff --git a/stats_prefix.c b/stats_prefix.c
22index 62f0d04..d72e514 100644
23--- a/stats_prefix.c
24+++ b/stats_prefix.c
25@@ -127,8 +127,10 @@ char *stats_prefix_dump(int *length) {
26 PREFIX_STATS *pfs;
27 char *buf;
28 int i, pos;
29- size_t size = 0, written = 0, total_written = 0;
30-
31+ size_t size = 0, written = 0;
32+#ifndef NDEBUG
33+ size_t total_written = 0;
34+#endif
35 /*
36 * Figure out how big the buffer needs to be. This is the sum of the
37 * lengths of the prefixes themselves, plus the size of one copy of
38@@ -154,8 +156,10 @@ char *stats_prefix_dump(int *length) {
39 pfs->prefix, pfs->num_gets, pfs->num_hits,
40 pfs->num_sets, pfs->num_deletes);
41 pos += written;
42+#ifndef NDEBUG
43 total_written += written;
44 assert(total_written < size);
45+#endif
46 }
47 }
48