[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/6] coverity-model: clean up the models for array allocation fun
From: |
Paolo Bonzini |
Subject: |
[PATCH 4/6] coverity-model: clean up the models for array allocation functions |
Date: |
Sat, 31 Jul 2021 08:27:39 +0200 |
sz is only used in one place, so replace it with nmemb * size in
that one place.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
scripts/coverity-scan/model.c | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/scripts/coverity-scan/model.c b/scripts/coverity-scan/model.c
index 1a5f39d2ae..2d384bdd79 100644
--- a/scripts/coverity-scan/model.c
+++ b/scripts/coverity-scan/model.c
@@ -178,13 +178,11 @@ uint8_t replay_get_byte(void)
void *g_malloc_n(size_t nmemb, size_t size)
{
- size_t sz;
void *ptr;
__coverity_negative_sink__(nmemb);
__coverity_negative_sink__(size);
- sz = nmemb * size;
- ptr = __coverity_alloc__(sz);
+ ptr = __coverity_alloc__(nmemb * size);
__coverity_mark_as_uninitialized_buffer__(ptr);
__coverity_mark_as_afm_allocated__(ptr, AFM_free);
return ptr;
@@ -192,13 +190,11 @@ void *g_malloc_n(size_t nmemb, size_t size)
void *g_malloc0_n(size_t nmemb, size_t size)
{
- size_t sz;
void *ptr;
__coverity_negative_sink__(nmemb);
__coverity_negative_sink__(size);
- sz = nmemb * size;
- ptr = __coverity_alloc__(sz);
+ ptr = __coverity_alloc__(nmemb * size);
__coverity_writeall0__(ptr);
__coverity_mark_as_afm_allocated__(ptr, AFM_free);
return ptr;
@@ -206,13 +202,10 @@ void *g_malloc0_n(size_t nmemb, size_t size)
void *g_realloc_n(void *ptr, size_t nmemb, size_t size)
{
- size_t sz;
-
__coverity_negative_sink__(nmemb);
__coverity_negative_sink__(size);
- sz = nmemb * size;
__coverity_escape__(ptr);
- ptr = __coverity_alloc__(sz);
+ ptr = __coverity_alloc__(nmemb * size);
/*
* Memory beyond the old size isn't actually initialized. Can't
* model that. See Coverity's realloc() model
--
2.31.1
- [PATCH 0/6] Updates for Coverity modeling file, Paolo Bonzini, 2021/07/31
- [PATCH 1/6] coverity-model: update address_space_read/write models, Paolo Bonzini, 2021/07/31
- [PATCH 2/6] coverity-model: make g_free a synonym of free, Paolo Bonzini, 2021/07/31
- [PATCH 3/6] coverity-model: remove model for more allocation functions, Paolo Bonzini, 2021/07/31
- [PATCH 4/6] coverity-model: clean up the models for array allocation functions,
Paolo Bonzini <=
- [PATCH 6/6] coverity-model: write models fully for non-array allocation functions, Paolo Bonzini, 2021/07/31
- [PATCH 5/6] coverity-model: constrain g_malloc/g_malloc0/g_realloc as never returning NULL, Paolo Bonzini, 2021/07/31