From 50a2d3be7bf473c7590f77350fadf3471427ce09 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Tue, 29 Oct 2019 09:45:06 +0100 Subject: [PATCH] Fix unsigned type overflow in memory report. 2019-10-29 Martin Liska * ggc-common.c: One can't subtract unsigned types in compare function. From-SVN: r277560 --- gcc/ChangeLog | 5 +++++ gcc/ggc-common.c | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 51097bba544..b6eeeaddc8e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2019-10-29 Martin Liska + + * ggc-common.c: One can't subtract unsigned types + in compare function. + 2019-10-29 Martin Liska * cgraphunit.c (symbol_table::compile): Pass diff --git a/gcc/ggc-common.c b/gcc/ggc-common.c index 37d3c5df9e1..48db4208599 100644 --- a/gcc/ggc-common.c +++ b/gcc/ggc-common.c @@ -928,10 +928,13 @@ public: static int compare (const void *first, const void *second) { - const mem_pair_t f = *(const mem_pair_t *)first; - const mem_pair_t s = *(const mem_pair_t *)second; + const mem_pair_t mem1 = *(const mem_pair_t *) first; + const mem_pair_t mem2 = *(const mem_pair_t *) second; - return s.second->get_balance () - f.second->get_balance (); + size_t balance1 = mem1.second->get_balance (); + size_t balance2 = mem2.second->get_balance (); + + return balance1 == balance2 ? 0 : (balance1 < balance2 ? 1 : -1); } /* Dump header with NAME. */ -- 2.30.2