Don't dereference pointer from _array_get
This commit is contained in:
@@ -70,7 +70,7 @@ BEGIN_C_LINKAGE
|
||||
#define wapp_array_item_size(TYPE, ARRAY_PTR) \
|
||||
_array_item_size((u8 *)ARRAY_PTR, sizeof(TYPE))
|
||||
#define wapp_array_get(TYPE, ARRAY_PTR, INDEX) \
|
||||
(*((TYPE *)_array_get((u8 *)ARRAY_PTR, INDEX, sizeof(TYPE))))
|
||||
((TYPE *)_array_get((u8 *)ARRAY_PTR, INDEX, sizeof(TYPE)))
|
||||
#define wapp_array_set(TYPE, ARRAY_PTR, INDEX, VALUE_PTR) \
|
||||
_array_set((u8 *)ARRAY_PTR, INDEX, (u8 *)VALUE_PTR, sizeof(TYPE))
|
||||
#define wapp_array_append_capped(TYPE, ARRAY_PTR, VALUE_PTR) \
|
||||
|
||||
@@ -7,13 +7,13 @@ TestFuncResult test_i32_array(void) {
|
||||
i32 *array = wapp_array(i32, 1, 2, 3, 4, 5, 6, 7);
|
||||
result = wapp_array_count(i32, array) == 7 && wapp_array_capacity(i32, array) == 16;
|
||||
|
||||
i32 item;
|
||||
i32 *item;
|
||||
u64 count = wapp_array_count(i32, array);
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
item = wapp_array_get(i32, array, index);
|
||||
result = result && item && item == (i32)(index + 1);
|
||||
result = result && item && *item == (i32)(index + 1);
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
@@ -36,13 +36,13 @@ TestFuncResult test_i32_array_get(void) {
|
||||
|
||||
i32 *array = wapp_array(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
|
||||
i32 item;
|
||||
i32 *item;
|
||||
u64 count = wapp_array_count(i32, array);
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
item = wapp_array_get(i32, array, index);
|
||||
result = result && item == (i32)index;
|
||||
result = result && item && *item == (i32)index;
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
@@ -56,7 +56,7 @@ TestFuncResult test_i32_array_set(void) {
|
||||
|
||||
i32 *array = wapp_array(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
|
||||
i32 item;
|
||||
i32 *item;
|
||||
u64 count = wapp_array_count(i32, array);
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
@@ -64,7 +64,7 @@ TestFuncResult test_i32_array_set(void) {
|
||||
i32 num = (i32)(index * 2);
|
||||
wapp_array_set(i32, array, index, &num);
|
||||
item = wapp_array_get(i32, array, index);
|
||||
result = result && item == (i32)(index * 2);
|
||||
result = result && item && *item == (i32)(index * 2);
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
@@ -80,8 +80,8 @@ TestFuncResult test_i32_array_append_capped(void) {
|
||||
wapp_array_append_capped(i32, array, &((i32){10}));
|
||||
|
||||
result = wapp_array_count(i32, array) == 1;
|
||||
i32 item = wapp_array_get(i32, array, 0);
|
||||
result = result && item == 10;
|
||||
i32 *item = wapp_array_get(i32, array, 0);
|
||||
result = result && item && *item == 10;
|
||||
|
||||
array = wapp_array(i32, 1);
|
||||
wapp_array_append_capped(i32, array, &((i32){10}));
|
||||
@@ -120,7 +120,7 @@ TestFuncResult test_i32_array_copy_capped(void) {
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
result = result && wapp_array_get(i32, src, index) == wapp_array_get(i32, dst1, index);
|
||||
result = result && *wapp_array_get(i32, src, index) == *wapp_array_get(i32, dst1, index);
|
||||
|
||||
++index;
|
||||
running = index < expected_count;
|
||||
@@ -133,7 +133,7 @@ TestFuncResult test_i32_array_copy_capped(void) {
|
||||
index = 0;
|
||||
running = true;
|
||||
while (running) {
|
||||
result = result && wapp_array_get(i32, src, index) == wapp_array_get(i32, dst2, index);
|
||||
result = result && *wapp_array_get(i32, src, index) == *wapp_array_get(i32, dst2, index);
|
||||
|
||||
++index;
|
||||
running = index < expected_count;
|
||||
@@ -218,7 +218,7 @@ TestFuncResult test_i32_array_copy_alloc(void) {
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
result = result && wapp_array_get(i32, src, index) == wapp_array_get(i32, array_ptr, index);
|
||||
result = result && *wapp_array_get(i32, src, index) == *wapp_array_get(i32, array_ptr, index);
|
||||
|
||||
++index;
|
||||
running = index < expected_count;
|
||||
@@ -231,7 +231,7 @@ TestFuncResult test_i32_array_copy_alloc(void) {
|
||||
index = 0;
|
||||
running = true;
|
||||
while (running) {
|
||||
result = result && wapp_array_get(i32, src, index) == wapp_array_get(i32, array_ptr, index);
|
||||
result = result && *wapp_array_get(i32, src, index) == *wapp_array_get(i32, array_ptr, index);
|
||||
|
||||
++index;
|
||||
running = index < expected_count;
|
||||
|
||||
@@ -9,13 +9,13 @@ TestFuncResult test_str8_array(void) {
|
||||
Str8 *array = wapp_array(Str8, wapp_str8_lit("Hello"), wapp_str8_lit("Hi"), wapp_str8_lit("Bye"));
|
||||
result = wapp_array_count(Str8, array) == 3 && wapp_array_capacity(Str8, array) == 8;
|
||||
|
||||
Str8 item;
|
||||
Str8 *item;
|
||||
u64 count = wapp_array_count(Str8, array);
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
item = wapp_array_get(Str8, array, index);
|
||||
result = result && (wapp_str8_equal(&item, &expected[index]));
|
||||
result = result && item && (wapp_str8_equal(item, &expected[index]));
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
|
||||
Reference in New Issue
Block a user