diff options
author | Khem Raj <raj.khem@gmail.com> | 2022-08-14 00:46:28 -0700 |
---|---|---|
committer | Khem Raj <raj.khem@gmail.com> | 2022-08-14 00:46:28 -0700 |
commit | 257b29c9910938b54df379e7e14c4a653e06449d (patch) | |
tree | e96777d7b11ac5bf760a17876758a5366ae852eb | |
parent | d1deed499f2c94c1ba39326fe1742c6f78bf455d (diff) | |
download | json-c-257b29c9910938b54df379e7e14c4a653e06449d.tar.gz |
json_pointer.c: Move idx_val declaration to top of function
This helps compiling with MS compiler, error seems to be
due to defining a variable within the body of the function
its allowed in c99 but not in c89. This should fix build with
MSVC 16.0.40219.1 compiler from Visual Studio 14 2015
Signed-off-by: Khem Raj <raj.khem@gmail.com>
-rw-r--r-- | json_pointer.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/json_pointer.c b/json_pointer.c index 2e8d30c..5abccdb 100644 --- a/json_pointer.c +++ b/json_pointer.c @@ -44,6 +44,7 @@ static void string_replace_all_occurrences_with_char(char *s, const char *occur, static int is_valid_index(struct json_object *jo, const char *path, size_t *idx) { size_t i, len = strlen(path); + long int idx_val = -1; /* this code-path optimizes a bit, for when we reference the 0-9 index range * in a JSON array and because leading zeros not allowed */ @@ -73,7 +74,7 @@ static int is_valid_index(struct json_object *jo, const char *path, size_t *idx) } } - long int idx_val = strtol(path, NULL, 10); + idx_val = strtol(path, NULL, 10); if (idx_val < 0) { errno = EINVAL; |