From: Christophe CURIS <christophe.cu...@free.fr>

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 <christophe.cu...@free.fr>
---
 WINGs/array.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/WINGs/array.c b/WINGs/array.c
index 0b5be94..df52358 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]);
        }
-- 
2.1.1


-- 
To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.

Reply via email to