Andrew Geissler | 6972109 | 2021-07-23 12:57:00 -0400 | [diff] [blame] | 1 | From d6294e9166e4875a0572349aabcc5e51acbd2e3c Mon Sep 17 00:00:00 2001 |
| 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Fri, 4 Jun 2021 11:33:12 -0700 |
| 4 | Subject: [PATCH] stats_prefix.c: Check for NDEBUG before using total_written |
| 5 | variable |
| 6 | |
| 7 | When using NDEBUG assert macro is ineffective which is caught by latest |
| 8 | clang and reports that total_written is set but unused. Therefore check |
| 9 | for NDEBUG to make sure assert is used only when its effective |
| 10 | |
| 11 | Fixes |
| 12 | error: variable 'total_written' set but not used [-Werror,-Wunused-but-set-variable] |
| 13 | size_t size = 0, written = 0, total_written = 0; |
| 14 | ^ |
| 15 | Upstream-Status: Submitted [https://github.com/memcached/memcached/pull/792] |
| 16 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 17 | --- |
| 18 | stats_prefix.c | 8 ++++++-- |
| 19 | 1 file changed, 6 insertions(+), 2 deletions(-) |
| 20 | |
| 21 | diff --git a/stats_prefix.c b/stats_prefix.c |
| 22 | index 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 | |