Thalhammer / jwt-cpp

A header only library for creating and validating json web tokens in c++
https://thalhammer.github.io/jwt-cpp/
MIT License
855 stars 233 forks source link

Fix warning vla-extension by changing MB_CUR_MAX into MB_LEN_MAX which is a compile time constant #302

Closed sjanel closed 1 year ago

sjanel commented 1 year ago

Latest jwt-cpp code produces following warning with -Wvla-extension:

jwt-cpp-src/include/jwt-cpp/jwt.h:3045:14: warning: variable length arrays are a C99 feature [-Wvla-extension]
                                        char mb[MB_CUR_MAX];
                                                ^~~~~~~~~~
/usr/include/stdlib.h:97:20: note: expanded from macro 'MB_CUR_MAX'
#define MB_CUR_MAX      (__ctype_get_mb_cur_max ())
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
jwt-cpp-src/include/jwt-cpp/jwt.h:3045:14: note: non-constexpr function '__ctype_get_mb_cur_max' cannot be used in a constant expression
/usr/include/stdlib.h:97:21: note: expanded from macro 'MB_CUR_MAX'
#define MB_CUR_MAX      (__ctype_get_mb_cur_max ())
                         ^
/usr/include/stdlib.h:98:15: note: declared here
extern size_t __ctype_get_mb_cur_max (void) __THROW __wur;
              ^
1 warning generated.

The easiest way to fix it is to use MB_LEN_MAX instead of MB_CUR_MAX which is a rather low value anyway (16), and a compile time constant.

According to the documentation, MB_CUR_MAX maximum value (for all locales) is MB_LEN_MAX.