boostorg / container

STL-like containers from Boost
http://www.boost.org/libs/container/
Boost Software License 1.0
96 stars 116 forks source link

variable set but not used in dlmalloc_ext_2_8_6.c #225

Closed jefftrull closed 1 year ago

jefftrull commented 1 year ago

The function boost_cont_allocated_memory() initializes and periodically updates a local variable sum, but never uses it for anything. This triggers warnings in some compilers and static analysis tools:

      size_t sum = mfree;          // ===> initialization
      msegmentptr s = &m->seg;
      while (s != 0) {
         mchunkptr q = align_as_chunk(s->base);
         while (segment_holds(s, q) &&
               q != m->top && q->head != FENCEPOST_HEAD) {
            size_t sz = chunksize(q);
            sum += sz;             // ===> update
igaztanaga commented 1 year ago

Thanks for the report, but I can't see how it's not used, "sum" is then assigned to nm.arena, which is returned nm.arena = sum;

jefftrull commented 1 year ago

The code you reference is in dlmalloc_2_8_6.c, not dlmalloc_ext_2_8_6.c

hdu-sdlzx commented 1 year ago

@igaztanaga clang-15 complains about the following unused variables: libs/container/src/dlmalloc_2_8_6.c:3991:7: warning: variable 'nfences' set but not used [-Wunused-but-set-variable] int nfences = 0; ^ In file included from libs/container/src/alloc_lib.c:24: libs/container/src/dlmalloc_ext_2_8_6.c:1227:14: warning: variable 'sum' set but not used [-Wunused-but-set-variable] size_t sum = mfree; ^ 2 warnings generated.