]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix assertion in malloc.c:tcache_get.
authorJoseph Myers <joseph@codesourcery.com>
Mon, 4 Feb 2019 23:46:58 +0000 (23:46 +0000)
committerArjun Shankar <ashankar@redhat.com>
Wed, 30 Oct 2019 10:56:49 +0000 (11:56 +0100)
One of the warnings that appears with -Wextra is "ordered comparison
of pointer with integer zero" in malloc.c:tcache_get, for the
assertion:

  assert (tcache->entries[tc_idx] > 0);

Indeed, a "> 0" comparison does not make sense for
tcache->entries[tc_idx], which is a pointer.  My guess is that
tcache->counts[tc_idx] is what's intended here, and this patch changes
the assertion accordingly.

Tested for x86_64.

* malloc/malloc.c (tcache_get): Compare tcache->counts[tc_idx]
with 0, not tcache->entries[tc_idx].

(cherry picked from commit 77dc0d8643aa99c92bf671352b0a8adde705896f)

ChangeLog
malloc/malloc.c

index 416c61a94c059797d9f2bcaf6f2ac914e8dad94c..668ae78ae723ceb61755b5e1a09aa371ae8a79b1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2019-02-04  Joseph Myers  <joseph@codesourcery.com>
+
+       * malloc/malloc.c (tcache_get): Compare tcache->counts[tc_idx]
+       with 0, not tcache->entries[tc_idx].
+
 2019-09-13  Wilco Dijkstra  <wdijkstr@arm.com>
 
        * string/memmem.c (__memmem): Rewrite to improve performance.
index 0e7970001aca268cc90079706a66d87afb1d95b3..78edbfc8dba0b6ec6059e8926d5e08ae673bd41b 100644 (file)
@@ -2941,7 +2941,7 @@ tcache_get (size_t tc_idx)
 {
   tcache_entry *e = tcache->entries[tc_idx];
   assert (tc_idx < TCACHE_MAX_BINS);
-  assert (tcache->entries[tc_idx] > 0);
+  assert (tcache->counts[tc_idx] > 0);
   tcache->entries[tc_idx] = e->next;
   --(tcache->counts[tc_idx]);
   e->key = NULL;