Skip to content

src/mjson.c: unused variable suspected by clang #51

Description

@git001

Clang creates a warning about unused variables which was discovered by HAPoxy community haproxy/haproxy#1868

One suggestion is to create a pragma for clang haproxy/haproxy#1868 (comment)
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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions