mjson
mjson copied to clipboard
src/mjson.c: unused variable suspected by clang
Clang creates a warning about unused variables which was discovered by HAPoxy community https://github.com/haproxy/haproxy/issues/1868
One suggestion is to create a pragma for clang https://github.com/haproxy/haproxy/issues/1868#issuecomment-1250049715
Another option is to add a new option like -D MJSON_DEBUG=1
and change the code accordingly.
Something like the code below instead of this block https://github.com/cesanta/mjson/blob/master/src/mjson.c#L186-L192.
static int plen1(const char *s) {
int i = 0;
#if MJSON_DEBUG
int n = 0;
#endif
while (s[i] != '\0' && s[i] != '.' && s[i] != '[') {
i += s[i] == '\\' ? 2 : 1;
#if MJSON_DEBUG
n++;
#endif
}
#if MJSON_DEBUG
printf("PLEN1: s: [%s], [%.*s] => %d\n", s, i, s, n);
#endif
return n;
}
As I would like to create a Pull Request to mjson and then add the new version to HAProxy please let me know what's your preferred way is to solve the clang warning.
this has raised just few days ago because is was detected by Fedora Rawhide which has switched to clang-15. I guess it is new rule in clang-15
I stumbled also about this issue:
/myMPD/dist/mjson/mjson.c:195:14: error: variable 'n' set but not used [-Werror,-Wunused-but-set-variable]
int i = 0, n = 0;
^
/myMPD/dist/mjson/mjson.c:743:17: error: variable 'n' set but not used [-Werror,-Wunused-but-set-variable]
int sign = 1, n = 0;