From 662b83769a7862a649315803468f16108c62dfdd Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sat, 15 Nov 2014 19:40:29 +0100 Subject: [PATCH] WUtil: changed order for null pointer check in array functions (Coverity #72806, #72807, #72819) As pointed by Coverity, there were some null pointer checks that had been misplaced, due to a pointer dereference present in a preceding check. This had been fixed by adding another null check in the check, making a duplicate check. This patch moves the null pointer check in first place, and remove the pointer check from the range check to separate the pointer check on one side and the range check on the other side. Signed-off-by: Christophe CURIS Signed-off-by: Carlos R. Mafra --- WINGs/array.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/WINGs/array.c b/WINGs/array.c index 0b5be944..df52358d 100644 --- a/WINGs/array.c +++ b/WINGs/array.c @@ -126,11 +126,11 @@ void WMAddToArray(WMArray * array, void *item) void WMInsertInArray(WMArray * array, int index, void *item) { - wassertr(array && index >= 0 && index <= array->itemCount); - if (array == NULL) return; + wassertr(index >= 0 && index <= array->itemCount); + if (array->itemCount >= array->allocSize) { array->allocSize += RESIZE_INCREMENT; array->items = wrealloc(array->items, sizeof(void *) * array->allocSize); @@ -148,11 +148,11 @@ void *WMReplaceInArray(WMArray * array, int index, void *item) { void *old; - wassertrv(array && index >= 0 && index <= array->itemCount, NULL); - if (array == NULL) return NULL; + wassertrv(index >= 0 && index <= array->itemCount, NULL); + /* is it really useful to perform append if index == array->itemCount ? -Dan */ if (index == array->itemCount) { WMAddToArray(array, item); @@ -167,11 +167,11 @@ void *WMReplaceInArray(WMArray * array, int index, void *item) int WMDeleteFromArray(WMArray * array, int index) { - wassertrv(array && index >= 0 && index < array->itemCount, 0); - if (array == NULL) return 0; + wassertrv(index >= 0 && index < array->itemCount, 0); + if (array->destructor) { array->destructor(array->items[index]); }