diff --git a/mongoose.c b/mongoose.c index fa650bac15..d94ce7ef76 100644 --- a/mongoose.c +++ b/mongoose.c @@ -2563,10 +2563,13 @@ int mg_json_get(struct mg_str json, const char *path, int *toklen) { case S_KEY: if (c == '"') { int n = mg_pass_string(&s[i + 1], len - i - 1); - printf("K %s %d %d %d [%.*s]\n", path, pos, n, i, n + 2, s + i); + // printf("K %s %d %d %d [%.*s]\n", path, pos, n, i, n + 2, s + i); if (n < 0) return n; if (i + 1 + n >= len) return MG_JSON_NOT_FOUND; - printf("K %s [%.*s] %d %d %d\n", path, n, &s[i + 1], n, depth, ed); + // printf("K %s [%.*s] %d %d %d\n", path, n, &s[i + 1], n, depth, ed); + // NOTE(cpq): in the check sequence below is important. + // strncmp() must go first: it fails fast if the remaining length of + // the path is smaller than `n`. if (depth == ed && path[pos - 1] == '.' && strncmp(&s[i + 1], &path[pos], (size_t) n) == 0 && (path[pos + n] == '\0' || path[pos + n] == '.' || diff --git a/src/json.c b/src/json.c index 79ade13216..1565e02f4b 100644 --- a/src/json.c +++ b/src/json.c @@ -167,10 +167,13 @@ int mg_json_get(struct mg_str json, const char *path, int *toklen) { case S_KEY: if (c == '"') { int n = mg_pass_string(&s[i + 1], len - i - 1); - printf("K %s %d %d %d [%.*s]\n", path, pos, n, i, n + 2, s + i); + // printf("K %s %d %d %d [%.*s]\n", path, pos, n, i, n + 2, s + i); if (n < 0) return n; if (i + 1 + n >= len) return MG_JSON_NOT_FOUND; - printf("K %s [%.*s] %d %d %d\n", path, n, &s[i + 1], n, depth, ed); + // printf("K %s [%.*s] %d %d %d\n", path, n, &s[i + 1], n, depth, ed); + // NOTE(cpq): in the check sequence below is important. + // strncmp() must go first: it fails fast if the remaining length of + // the path is smaller than `n`. if (depth == ed && path[pos - 1] == '.' && strncmp(&s[i + 1], &path[pos], (size_t) n) == 0 && (path[pos + n] == '\0' || path[pos + n] == '.' ||