commit - 5ff759965efbabc96fecd514e208a9a1b7be72df
commit + 1c2d4cc9a3b08873d8a8dd63731b68eab87b6b03
blob - 7aaab19f0a58317289881be832a03ec59f67a0ff
blob + 73fc7617ad6907c5ba7138f41853f8e9e447a48e
--- include/arraylist.h
+++ include/arraylist.h
} while (0)
#define ARRAYLIST_INSERT(NEW_ITEM_P, ARRAY_LIST, AT_IDX) do { \
+ int _at_idx = (AT_IDX); \
ARRAYLIST_ADD(NEW_ITEM_P, ARRAY_LIST); \
- if ((NEW_ITEM_P) && (AT_IDX) < (ARRAY_LIST).len) \
- memmove(&(ARRAY_LIST).head[(AT_IDX) + 1], \
- &(ARRAY_LIST).head[AT_IDX], \
- ((ARRAY_LIST).len - (AT_IDX)) \
+ if ((NEW_ITEM_P) \
+ && _at_idx >= 0 \
+ && _at_idx < (ARRAY_LIST).len) { \
+ memmove(&(ARRAY_LIST).head[_at_idx + 1], \
+ &(ARRAY_LIST).head[_at_idx], \
+ ((ARRAY_LIST).len - 1 - _at_idx) \
* sizeof(*(ARRAY_LIST).head)); \
+ (NEW_ITEM_P) = &(ARRAY_LIST).head[_at_idx]; \
+ }; \
} while (0)
#define ARRAYLIST_CLEAR(ARRAY_LIST) \