glib-aux: workaround coverty warning about comparing nm_json_int_t with int64

Error: CONSTANT_EXPRESSION_RESULT (CWE-569): [#def240]
  NetworkManager-1.31.3/src/libnm-glib-aux/nm-json-aux.h:260: result_independent_of_operands: "v < -9223372036854775808LL /* (gint64)(-9223372036854775807L - 1L) */" is always false regardless of the values of its operands. This occurs as the logical first operand of "||".
  #  258|
  #  259|       v = vt->nm_json_integer_value(elem);
  #  260|->     if (v < G_MININT64 || v > G_MAXINT64)
  #  261|           return -ERANGE;
  #  262|

  Error: CONSTANT_EXPRESSION_RESULT (CWE-569): [#def241]
  NetworkManager-1.31.3/src/libnm-glib-aux/nm-json-aux.h:279: result_independent_of_operands: "v > 18446744073709551615UL" is always false regardless of the values of its operands. This occurs as the logical second operand of "||".
  #  277|
  #  278|       v = vt->nm_json_integer_value(elem);
  #  279|->     if (v < 0 || v > G_MAXUINT64)
  #  280|           return -ERANGE;
  #  281|
This commit is contained in:
Thomas Haller 2021-05-06 21:24:56 +02:00
parent 463db1c7a6
commit d527d3874c
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -256,9 +256,15 @@ nm_jansson_json_as_int64(const NMJsonVt *vt, const nm_json_t *elem, gint64 *out_
if (!nm_json_is_integer(elem))
return -EINVAL;
/* assert that this integer is signed. */
G_STATIC_ASSERT_EXPR(((nm_json_int_t) -1) < 0);
v = vt->nm_json_integer_value(elem);
if (v < G_MININT64 || v > G_MAXINT64)
return -ERANGE;
if (sizeof(v) > sizeof(gint64)) {
if (v < G_MININT64 || v > G_MAXINT64)
return -ERANGE;
}
NM_SET_OUT(out_val, v);
return 1;
@ -275,10 +281,18 @@ nm_jansson_json_as_uint64(const NMJsonVt *vt, const nm_json_t *elem, guint64 *ou
if (!nm_json_is_integer(elem))
return -EINVAL;
/* assert that this integer is signed. */
G_STATIC_ASSERT_EXPR(((nm_json_int_t) -1) < 0);
v = vt->nm_json_integer_value(elem);
if (v < 0 || v > G_MAXUINT64)
if (v < 0)
return -ERANGE;
if (sizeof(v) > sizeof(gint64)) {
if (v > G_MAXUINT64)
return -ERANGE;
}
NM_SET_OUT(out_val, v);
return 1;
}