Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 12, 2023

Conversation

sjanel
Copy link
Contributor

@sjanel sjanel commented Aug 11, 2023

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.

@Thalhammer Thalhammer merged commit ce1f9df into Thalhammer:master Aug 12, 2023
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants