nothings / stb

stb single-file public domain libraries for C/C++
https://twitter.com/nothings
Other
26.31k stars 7.69k forks source link

stb_ds 0.67: passing 'const char *' to parameter of type 'void *' discards qualifiers #1436

Open rongcuid opened 1 year ago

rongcuid commented 1 year ago

Describe the bug When using stb_ds, incompatible pointer type warning appear (and becomes error because of Werror):

error: passing 'const char *' to parameter of type 'void *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
  arrsetlen(extensions, count);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/local/include/stb/stb_ds.h:407:21: note: expanded from macro 'arrsetlen'
#define arrsetlen   stbds_arrsetlen
                    ^
/opt/local/include/stb/stb_ds.h:539:67: note: expanded from macro 'stbds_arrsetlen'
#define stbds_arrsetlen(a,n)   ((stbds_arrcap(a) < (size_t) (n) ? stbds_arrsetcap((a),(size_t)(n)),0 : 0), (a) ? stbds_header(a)->length = (size_t) (n) : 0)
                                                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/local/include/stb/stb_ds.h:538:33: note: expanded from macro 'stbds_arrsetcap'
#define stbds_arrsetcap(a,n)   (stbds_arrgrow(a,0,n))
                                ^~~~~~~~~~~~~~~~~~~~
/opt/local/include/stb/stb_ds.h:561:62: note: expanded from macro 'stbds_arrgrow'
#define stbds_arrgrow(a,b,c)   ((a) = stbds_arrgrowf_wrapper((a), sizeof *(a), (b), (c)))
                                                             ^~~
/opt/local/include/stb/stb_ds.h:494:36: note: passing argument to parameter 'a' here
extern void * stbds_arrgrowf(void *a, size_t elemsize, size_t addlen, size_t min_cap);

I believe that the stbds_arrgrow macro should explicitly cast a into a void pointer, like this: (void *) (a).

To Reproduce Steps to reproduce the behavior:

const char *test = NULL;
arrsetlen(test, 10);

Expected behavior Compiles without warning or error