diff --git a/CMakeLists.txt b/CMakeLists.txt index bf6929f..3d24caf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,8 @@ set(JSON_C_HEADERS ./linkhash.h ./math_compat.h ./strdup_compat.h + ./strerror_override.h + ./strerror_override_private.h ./vasprintf_compat.h ./printbuf.h ./random_seed.h @@ -66,6 +68,7 @@ set(JSON_C_SOURCES ./json_util.c ./linkhash.c ./printbuf.c + ./strerror_override.c ./random_seed.c ./strerror_override.c ) diff --git a/json_object.c b/json_object.c index ec4e2b6..01ee0a8 100644 --- a/json_object.c +++ b/json_object.c @@ -459,13 +459,15 @@ int json_object_object_add_ex(struct json_object* jso, struct json_object *const val, const unsigned opts) { + struct json_object *existing_value = NULL; + struct lh_entry *existing_entry; + unsigned long hash; + assert(json_object_get_type(jso) == json_type_object); // We lookup the entry and replace the value, rather than just deleting // and re-adding it, so the existing key remains valid. - json_object *existing_value = NULL; - struct lh_entry *existing_entry; - const unsigned long hash = lh_get_hash(jso->o.c_object, (const void *)key); + hash = lh_get_hash(jso->o.c_object, (const void *)key); existing_entry = (opts & JSON_C_OBJECT_ADD_KEY_IS_NEW) ? NULL : lh_table_lookup_entry_w_hash(jso->o.c_object, (const void *)key, hash); @@ -851,11 +853,12 @@ struct json_object* json_object_new_double(double d) struct json_object* json_object_new_double_s(double d, const char *ds) { + char *new_ds; struct json_object *jso = json_object_new_double(d); if (!jso) return NULL; - char *new_ds = strdup(ds); + new_ds = strdup(ds); if (!new_ds) { json_object_generic_delete(jso); @@ -1035,8 +1038,8 @@ int json_object_set_string(json_object* jso, const char* s) { } int json_object_set_string_len(json_object* jso, const char* s, int len){ - if (jso==NULL || jso->o_type!=json_type_string) return 0; char *dstbuf; + if (jso==NULL || jso->o_type!=json_type_string) return 0; if (leno.c_string.str.data; if (jso->o.c_string.len>=LEN_DIRECT_STRING_DATA) free(jso->o.c_string.str.ptr); diff --git a/json_tokener.c b/json_tokener.c index 56b6c07..57d8367 100644 --- a/json_tokener.c +++ b/json_tokener.c @@ -387,10 +387,11 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok, { size_t size_inf; int is_negative = 0; + char *infbuf; printbuf_memappend_fast(tok->pb, &c, 1); size_inf = json_min(tok->st_pos+1, json_inf_str_len); - char *infbuf = tok->pb->buf; + infbuf = tok->pb->buf; if (*infbuf == '-') { infbuf++; diff --git a/linkhash.c b/linkhash.c index 5497061..f68ff6f 100644 --- a/linkhash.c +++ b/linkhash.c @@ -560,6 +560,13 @@ int lh_table_resize(struct lh_table *t, int new_size) return 0; } +#if defined(_MSC_VER) && (_MSC_VER < 1900) +unsigned long lh_get_hash(const struct lh_table *t, const void *k) +{ + return t->hash_fn(k); +} +#endif + void lh_table_free(struct lh_table *t) { struct lh_entry *c; diff --git a/linkhash.h b/linkhash.h index a606345..9080a72 100644 --- a/linkhash.h +++ b/linkhash.h @@ -332,10 +332,14 @@ int lh_table_resize(struct lh_table *t, int new_size); * @param k a pointer to the key to lookup * @return the key's hash */ -static inline unsigned long lh_get_hash(const struct lh_table *t, const void *k) -{ - return t->hash_fn(k); +#if !defined(_MSC_VER) || (_MSC_VER > 1800) +static inline unsigned long lh_get_hash(const struct lh_table *t, const void *k) +{ + return t->hash_fn(k); } +#else +unsigned long lh_get_hash(const struct lh_table *t, const void *k); +#endif /* Don't use this outside of linkhash.h: */ #ifdef __UNCONST diff --git a/random_seed.c b/random_seed.c index cb086d3..3232777 100644 --- a/random_seed.c +++ b/random_seed.c @@ -186,11 +186,11 @@ static int get_dev_random_seed() static int get_cryptgenrandom_seed() { - DEBUG_SEED("get_cryptgenrandom_seed"); - HCRYPTPROV hProvider = 0; int r; + DEBUG_SEED("get_cryptgenrandom_seed"); + if (!CryptAcquireContextW(&hProvider, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) { fprintf(stderr, "error CryptAcquireContextW"); exit(1);