diff options
author | Kevin Svetlitski <svetlitski@meta.com> | 2023-04-26 14:10:41 -0700 |
---|---|---|
committer | Qi Wang <interwq@gmail.com> | 2023-05-11 20:27:49 -0700 |
commit | 3e2ba7a6510be583edb316372f8cfff35f2f25d5 (patch) | |
tree | 1b122673f81ec709d692e8999c85fd66054d79d5 | |
parent | 0288126d9cc0d061766e37cbbaabaa78aff3aff5 (diff) | |
download | jemalloc-3e2ba7a6510be583edb316372f8cfff35f2f25d5.tar.gz |
Remove dead stores detected by static analysis
None of these are harmful, and they are almost certainly optimized
away by the compiler. The motivation for fixing them anyway is that
we'd like to enable static analysis as part of CI, and the first step
towards that is resolving the warnings it produces at present.
-rw-r--r-- | include/jemalloc/internal/log.h | 3 | ||||
-rw-r--r-- | src/ctl.c | 2 | ||||
-rw-r--r-- | src/jemalloc.c | 3 | ||||
-rw-r--r-- | src/malloc_io.c | 6 | ||||
-rw-r--r-- | src/pages.c | 2 | ||||
-rw-r--r-- | src/stats.c | 4 |
6 files changed, 7 insertions, 13 deletions
diff --git a/include/jemalloc/internal/log.h b/include/jemalloc/internal/log.h index 64208586..f39c598a 100644 --- a/include/jemalloc/internal/log.h +++ b/include/jemalloc/internal/log.h @@ -96,8 +96,7 @@ log_impl_varargs(const char *name, ...) { dst_offset += malloc_snprintf(buf, JEMALLOC_LOG_BUFSIZE, "%s: ", name); dst_offset += malloc_vsnprintf(buf + dst_offset, JEMALLOC_LOG_BUFSIZE - dst_offset, format, ap); - dst_offset += malloc_snprintf(buf + dst_offset, - JEMALLOC_LOG_BUFSIZE - dst_offset, "\n"); + malloc_snprintf(buf + dst_offset, JEMALLOC_LOG_BUFSIZE - dst_offset, "\n"); va_end(ap); malloc_write(buf); @@ -2745,7 +2745,6 @@ arena_i_dss_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, int ret; const char *dss = NULL; unsigned arena_ind; - dss_prec_t dss_prec_old = dss_prec_limit; dss_prec_t dss_prec = dss_prec_limit; malloc_mutex_lock(tsd_tsdn(tsd), &ctl_mtx); @@ -2773,6 +2772,7 @@ arena_i_dss_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, * Access via index narenas is deprecated, and scheduled for removal in * 6.0.0. */ + dss_prec_t dss_prec_old; if (arena_ind == MALLCTL_ARENAS_ALL || arena_ind == ctl_arenas->narenas) { if (dss_prec != dss_prec_limit && diff --git a/src/jemalloc.c b/src/jemalloc.c index 7407022f..37cd159c 100644 --- a/src/jemalloc.c +++ b/src/jemalloc.c @@ -2389,7 +2389,6 @@ imalloc_sample(static_opts_t *sopts, dynamic_opts_t *dopts, tsd_t *tsd, * from the ind_large bucket. */ szind_t ind_large; - size_t bumped_usize = usize; dopts->alignment = prof_sample_align(dopts->alignment); if (usize <= SC_SMALL_MAXCLASS) { @@ -2398,7 +2397,7 @@ imalloc_sample(static_opts_t *sopts, dynamic_opts_t *dopts, tsd_t *tsd, sz_sa2u(SC_LARGE_MINCLASS, dopts->alignment)) == SC_LARGE_MINCLASS); ind_large = sz_size2index(SC_LARGE_MINCLASS); - bumped_usize = sz_s2u(SC_LARGE_MINCLASS); + size_t bumped_usize = sz_s2u(SC_LARGE_MINCLASS); ret = imalloc_no_sample(sopts, dopts, tsd, bumped_usize, bumped_usize, ind_large); if (unlikely(ret == NULL)) { diff --git a/src/malloc_io.c b/src/malloc_io.c index b76885cb..6de409b3 100644 --- a/src/malloc_io.c +++ b/src/malloc_io.c @@ -423,7 +423,6 @@ malloc_vsnprintf(char *str, size_t size, const char *format, va_list ap) { unsigned char len = '?'; char *s; size_t slen; - bool first_width_digit = true; bool pad_zero = false; f++; @@ -462,9 +461,7 @@ malloc_vsnprintf(char *str, size_t size, const char *format, va_list ap) { } break; case '0': - if (first_width_digit) { - pad_zero = true; - } + pad_zero = true; JEMALLOC_FALLTHROUGH; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { @@ -474,7 +471,6 @@ malloc_vsnprintf(char *str, size_t size, const char *format, va_list ap) { assert(uwidth != UINTMAX_MAX || get_errno() != ERANGE); width = (int)uwidth; - first_width_digit = false; break; } default: break; diff --git a/src/pages.c b/src/pages.c index b672e4de..09b51b88 100644 --- a/src/pages.c +++ b/src/pages.c @@ -68,7 +68,6 @@ static int madvise_dont_need_zeros_is_faulty = -1; */ static int madvise_MADV_DONTNEED_zeroes_pages() { - int works = -1; size_t size = PAGE; void * addr = mmap(NULL, size, PROT_READ|PROT_WRITE, @@ -83,6 +82,7 @@ static int madvise_MADV_DONTNEED_zeroes_pages() } memset(addr, 'A', size); + int works; if (madvise(addr, size, MADV_DONTNEED) == 0) { works = memchr(addr, 'A', size) == NULL; } else { diff --git a/src/stats.c b/src/stats.c index 43360a2d..59db4f8e 100644 --- a/src/stats.c +++ b/src/stats.c @@ -1803,7 +1803,7 @@ stats_print_helper(emitter_t *emitter, bool merged, bool destroyed, size_t sz; VARIABLE_ARRAY(bool, initialized, narenas); bool destroyed_initialized; - unsigned i, j, ninitialized; + unsigned i, ninitialized; xmallctlnametomib("arena.0.initialized", mib, &miblen); for (i = ninitialized = 0; i < narenas; i++) { @@ -1843,7 +1843,7 @@ stats_print_helper(emitter_t *emitter, bool merged, bool destroyed, /* Unmerged stats. */ if (unmerged) { - for (i = j = 0; i < narenas; i++) { + for (i = 0; i < narenas; i++) { if (initialized[i]) { char arena_ind_str[20]; malloc_snprintf(arena_ind_str, |