Fix bug where pop would return the wrong value.
authorDavid Given <dg@cowlark.com>
Sat, 21 Jan 2017 22:21:55 +0000 (23:21 +0100)
committerDavid Given <dg@cowlark.com>
Sat, 21 Jan 2017 22:21:55 +0000 (23:21 +0100)
modules/src/data/array.c

index 363e603..2168c7d 100644 (file)
@@ -21,8 +21,7 @@ void array_append(void* arrayp, void* value)
     struct array* array = arrayp;
 
     extend(array);
-    array->item[array->count] = value;
-    array->count++;
+    array->item[array->count++] = value;
 }
 
 int array_indexof(void* arrayp, void* value)
@@ -99,7 +98,7 @@ void* array_pop(void* arrayp)
     struct array* array = arrayp;
 
     assert(array->count > 0);
-    return array->item[array->count--];
+    return array->item[--array->count];
 }
 
 void array_appendall(void* arrayp, void* srcp)