Browse Source

Merge pull request #556 from Jehan/wip/Jehan/fix-broken-mingw-w64

Fixes various Wreturn-type and Wimplicit-fallthrough errors on Mingw-w64
tags/json-c-0.14-20200419
Eric Haszlakiewicz GitHub 5 years ago
parent
commit
a06339215e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 5 deletions
  1. +5
    -5
      json_object.c
  2. +7
    -0
      json_util.c
  3. +17
    -0
      json_util.h

+ 5
- 5
json_object.c View File

@@ -597,7 +597,7 @@ json_bool json_object_get_boolean(const struct json_object *jso)
case json_object_int_type_uint64:
return (jso->o.c_int.cint.c_uint64 != 0);
default:
assert(!"invalid cint_type");
json_abort("invalid cint_type");
}
case json_type_double:
return (jso->o.c_double != 0);
@@ -734,7 +734,7 @@ int64_t json_object_get_int64(const struct json_object *jso)
return INT64_MAX;
return (int64_t)jso->o.c_int.cint.c_uint64;
default:
assert(!"invalid cint_type");
json_abort("invalid cint_type");
}
case json_type_double:
// INT64_MAX can't be exactly represented as a double
@@ -772,7 +772,7 @@ uint64_t json_object_get_uint64(const struct json_object *jso)
case json_object_int_type_uint64:
return jso->o.c_int.cint.c_uint64;
default:
assert(!"invalid cint_type");
json_abort("invalid cint_type");
}
case json_type_double:
// UINT64_MAX can't be exactly represented as a double
@@ -836,7 +836,7 @@ int json_object_int_inc(struct json_object *jso, int64_t val) {
}
return 1;
default:
assert(!"invalid cint_type");
json_abort("invalid cint_type");
}
}

@@ -1067,7 +1067,7 @@ double json_object_get_double(const struct json_object *jso)
case json_object_int_type_uint64:
return jso->o.c_int.cint.c_uint64;
default:
assert(!"invalid cint_type");
json_abort("invalid cint_type");
}
case json_type_boolean:
return jso->o.c_boolean;


+ 7
- 0
json_util.c View File

@@ -282,3 +282,10 @@ const char *json_type_to_name(enum json_type o_type)
return json_type_name[o_type];
}

void json_abort(const char *message)
{
if (message != NULL)
fprintf (stderr, "json-c aborts with error: %s\n", message);
abort();
}


+ 17
- 0
json_util.h View File

@@ -112,6 +112,23 @@ JSON_EXPORT int json_parse_double(const char *buf, double *retval);
*/
JSON_EXPORT const char *json_type_to_name(enum json_type o_type);

#ifndef JSON_NORETURN
#if defined(_MSC_VER)
#define JSON_NORETURN __declspec(noreturn)
#else
/* 'cold' attribute is for optimization, telling the computer this code
* path is unlikely.
*/
#define JSON_NORETURN __attribute__ ((noreturn, cold))
#endif
#endif
/**
* Abort and optionally print a message on standard error.
* This should be used rather than assert() for unconditional abortion
* (in particular for code paths which are never supposed to be run).
* */
JSON_NORETURN JSON_EXPORT void json_abort(const char *message);

#ifdef __cplusplus
}
#endif


Loading…
Cancel
Save