Skip to contentSkip to conversation

coverity: Fix g_malloc_n-like models

PATCH In review Jan Kiszka 3 participants 4 messages Mar 12, 2015 – Mar 17, 2015

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 coverity: Fix g_malloc_n-like models

Allocate the calculated overall size, not only the size of a single element.

---
 scripts/coverity-model.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
scripts/coverity-model.c +3 -3
index 58356af..cdda259 100644
@@ -123,7 +123,7 @@ void *g_malloc_n(size_t nmemb, size_t size)
     __coverity_negative_sink__(nmemb);
     __coverity_negative_sink__(size);
     sz = nmemb * size;
-    ptr = __coverity_alloc__(size);
+    ptr = __coverity_alloc__(sz);
     __coverity_mark_as_uninitialized_buffer__(ptr);
     __coverity_mark_as_afm_allocated__(ptr, "g_free");
     return ptr;
@@ -137,7 +137,7 @@ void *g_malloc0_n(size_t nmemb, size_t size)
     __coverity_negative_sink__(nmemb);
     __coverity_negative_sink__(size);
     sz = nmemb * size;
-    ptr = __coverity_alloc__(size);
+    ptr = __coverity_alloc__(sz);
     __coverity_writeall0__(ptr);
     __coverity_mark_as_afm_allocated__(ptr, "g_free");
     return ptr;
@@ -151,7 +151,7 @@ void *g_realloc_n(void *ptr, size_t nmemb, size_t size)
     __coverity_negative_sink__(size);
     sz = nmemb * size;
     __coverity_escape__(ptr);
-    ptr = __coverity_alloc__(size);
+    ptr = __coverity_alloc__(sz);
     /*
      * Memory beyond the old size isn't actually initialized.  Can't
      * model that.  See Coverity's realloc() model
Signature · 1 line
2.1.4
#2 lore raw
Quoted 8 lines · Markus Armbruster
Quoted 4 lines · Jan Kiszka

Allocate the calculated overall size, not only the size of a single element.

I'm feeding this to Coverity locally to gauge its impact.

I got no changes.

Paolo

#3 lore raw
Quoted 11 lines · Paolo Bonzini
Quoted 8 lines · Markus Armbruster
Quoted 4 lines · Jan Kiszka

Allocate the calculated overall size, not only the size of a single element.

I'm feeding this to Coverity locally to gauge its impact.

I got no changes.

Yep, same here. Applied, thanks!