Skip to content

Commit

Permalink
stb_ds: Fix addn when n=0
Browse files Browse the repository at this point in the history
In this case, the array pointer may still be 0 even after the
maybegrow.

Fixes issue #1015.
  • Loading branch information
rygorous committed Jul 7, 2021
1 parent b14a807 commit 2af2e69
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions stb_ds.h
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,8 @@ extern void * stbds_shmode_func(size_t elemsize, int mode);
#define stbds_arrpush stbds_arrput // synonym
#define stbds_arrpop(a) (stbds_header(a)->length--, (a)[stbds_header(a)->length])
#define stbds_arraddn(a,n) ((void)(stbds_arraddnindex(a, n))) // deprecated, use one of the following instead:
#define stbds_arraddnptr(a,n) (stbds_arrmaybegrow(a,n), stbds_header(a)->length += (n), &(a)[stbds_header(a)->length-(n)])
#define stbds_arraddnindex(a,n)(stbds_arrmaybegrow(a,n), stbds_header(a)->length += (n), stbds_header(a)->length-(n))
#define stbds_arraddnptr(a,n) (stbds_arrmaybegrow(a,n), (n) ? (stbds_header(a)->length += (n), &(a)[stbds_header(a)->length-(n)]) : (a))
#define stbds_arraddnindex(a,n)(stbds_arrmaybegrow(a,n), (n) ? (stbds_header(a)->length += (n), stbds_header(a)->length-(n)) : stbds_arrlen(a))
#define stbds_arraddnoff stbds_arraddnindex
#define stbds_arrlast(a) ((a)[stbds_header(a)->length-1])
#define stbds_arrfree(a) ((void) ((a) ? STBDS_FREE(NULL,stbds_header(a)) : (void)0), (a)=NULL)
Expand Down

0 comments on commit 2af2e69

Please sign in to comment.