commit 32be30224703df053be11d1c953763e7d7f2a5f6 from: Stefan Sperling date: Tue Sep 22 22:11:55 2020 UTC do not clobber the arraylist head if recallocarray fails commit - dabc100859385b31dcfbe62d04187d6947a12795 commit + 32be30224703df053be11d1c953763e7d7f2a5f6 blob - bb6e626bf9c86e3fa8598f4710496f81737f2c17 blob + badedfc28278523e489b303c0c470e925bbbabfa --- include/diff/arraylist.h +++ include/diff/arraylist.h @@ -40,6 +40,7 @@ #define ARRAYLIST(MEMBER_TYPE) \ struct { \ MEMBER_TYPE *head; \ + MEMBER_TYPE *p; \ unsigned int len; \ unsigned int allocated; \ unsigned int alloc_blocksize; \ @@ -61,12 +62,18 @@ || (ARRAY_LIST).allocated < (ARRAY_LIST).len + 1) { \ (ARRAY_LIST).allocated += \ (ARRAY_LIST).alloc_blocksize ? : 8; \ - (ARRAY_LIST).head = recallocarray((ARRAY_LIST).head, \ + (ARRAY_LIST).p = recallocarray((ARRAY_LIST).head, \ (ARRAY_LIST).len, \ (ARRAY_LIST).allocated, \ sizeof(*(ARRAY_LIST).head)); \ + if ((ARRAY_LIST).p == NULL) { \ + NEW_ITEM_P = NULL; \ + break; \ + } \ + (ARRAY_LIST).head = (ARRAY_LIST).p; \ + (ARRAY_LIST).p = NULL; \ }; \ - if (!(ARRAY_LIST).head \ + if ((ARRAY_LIST).head == NULL \ || (ARRAY_LIST).allocated < (ARRAY_LIST).len + 1) { \ NEW_ITEM_P = NULL; \ break; \