]> granicus.if.org Git - graphviz/commitdiff
cgraph: fix incorrect 'gv_recalloc' assertion
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 1 May 2022 01:13:17 +0000 (18:13 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 11 May 2022 05:24:16 +0000 (22:24 -0700)
The assertion here was claiming that overflow _did_ occur when computing the
extent of the previous allocation rather than the reverse.

lib/cgraph/alloc.h

index 153b40f8cdb2f0fdd525a3f610d9db2bf7e597b6..7efbd7ea0c226a6072629f1339b0d1c6100e0cdd 100644 (file)
@@ -55,8 +55,7 @@ static inline void *gv_recalloc(void *ptr, size_t old_nmemb, size_t new_nmemb,
                                 size_t size) {
 
   assert(size > 0 && "attempt to allocate array of 0-sized elements");
-  assert(SIZE_MAX / size <= old_nmemb &&
-         "claimed previous extent is too large");
+  assert(old_nmemb < SIZE_MAX / size && "claimed previous extent is too large");
 
   // will multiplication overflow?
   if (UNLIKELY(SIZE_MAX / size > new_nmemb)) {