]> granicus.if.org Git - graphviz/commitdiff
cgraph: fix overflow check in 'gv_recalloc'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 1 May 2022 01:16:34 +0000 (18:16 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 11 May 2022 05:24:16 +0000 (22:24 -0700)
lib/cgraph/alloc.h

index 7efbd7ea0c226a6072629f1339b0d1c6100e0cdd..2b25a1b376c4dceb4e66879c1c80a6180d8cef91 100644 (file)
@@ -58,7 +58,7 @@ static inline void *gv_recalloc(void *ptr, size_t old_nmemb, size_t new_nmemb,
   assert(old_nmemb < SIZE_MAX / size && "claimed previous extent is too large");
 
   // will multiplication overflow?
-  if (UNLIKELY(SIZE_MAX / size > new_nmemb)) {
+  if (UNLIKELY(new_nmemb > SIZE_MAX / size)) {
     fprintf(stderr, "integer overflow in dynamic memory reallocation\n");
     graphviz_exit(EXIT_FAILURE);
   }