mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-27 07:56:14 +01:00
gvariant-parser: Add explicit unsigned-to-signed casts
Rather than prefixing unsigned numbers with unary minus operators and expecting the implicit cast to carry the correct value through, add an explicit cast to a signed type before the unary minus is applied. In all four cases, an overflow check has already been done. Signed-off-by: Philip Withnall <withnall@endlessm.com> https://gitlab.gnome.org/GNOME/glib/issues/1655
This commit is contained in:
parent
3fe6f2a44f
commit
e3e4a09716
@ -1921,7 +1921,7 @@ number_get_value (AST *ast,
|
|||||||
case 'n':
|
case 'n':
|
||||||
if (abs_val - negative > G_MAXINT16)
|
if (abs_val - negative > G_MAXINT16)
|
||||||
return number_overflow (ast, type, error);
|
return number_overflow (ast, type, error);
|
||||||
return g_variant_new_int16 (negative ? -abs_val : abs_val);
|
return g_variant_new_int16 (negative ? -((gint16) abs_val) : abs_val);
|
||||||
|
|
||||||
case 'q':
|
case 'q':
|
||||||
if (negative || abs_val > G_MAXUINT16)
|
if (negative || abs_val > G_MAXUINT16)
|
||||||
@ -1931,7 +1931,7 @@ number_get_value (AST *ast,
|
|||||||
case 'i':
|
case 'i':
|
||||||
if (abs_val - negative > G_MAXINT32)
|
if (abs_val - negative > G_MAXINT32)
|
||||||
return number_overflow (ast, type, error);
|
return number_overflow (ast, type, error);
|
||||||
return g_variant_new_int32 (negative ? -abs_val : abs_val);
|
return g_variant_new_int32 (negative ? -((gint32) abs_val) : abs_val);
|
||||||
|
|
||||||
case 'u':
|
case 'u':
|
||||||
if (negative || abs_val > G_MAXUINT32)
|
if (negative || abs_val > G_MAXUINT32)
|
||||||
@ -1941,7 +1941,7 @@ number_get_value (AST *ast,
|
|||||||
case 'x':
|
case 'x':
|
||||||
if (abs_val - negative > G_MAXINT64)
|
if (abs_val - negative > G_MAXINT64)
|
||||||
return number_overflow (ast, type, error);
|
return number_overflow (ast, type, error);
|
||||||
return g_variant_new_int64 (negative ? -abs_val : abs_val);
|
return g_variant_new_int64 (negative ? -((gint64) abs_val) : abs_val);
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
if (negative)
|
if (negative)
|
||||||
@ -1951,7 +1951,7 @@ number_get_value (AST *ast,
|
|||||||
case 'h':
|
case 'h':
|
||||||
if (abs_val - negative > G_MAXINT32)
|
if (abs_val - negative > G_MAXINT32)
|
||||||
return number_overflow (ast, type, error);
|
return number_overflow (ast, type, error);
|
||||||
return g_variant_new_handle (negative ? -abs_val : abs_val);
|
return g_variant_new_handle (negative ? -((gint32) abs_val) : abs_val);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return ast_type_error (ast, type, error);
|
return ast_type_error (ast, type, error);
|
||||||
|
Loading…
Reference in New Issue
Block a user