From 9d811e1267e725d5c4f63cb10061edaa863b3408 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Sun, 9 Feb 2020 22:13:16 +0100 Subject: [PATCH] Warn when truncating values in `charmap` --- src/asm/asmy.y | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/asm/asmy.y b/src/asm/asmy.y index 52de18cf..d5c5ea96 100644 --- a/src/asm/asmy.y +++ b/src/asm/asmy.y @@ -999,7 +999,12 @@ incbin : T_POP_INCBIN string charmap : T_POP_CHARMAP string comma const { - if (charmap_Add($2, constexpr_GetConstantValue(&$4) & 0xFF) == -1) { + int32_t value = constexpr_GetConstantValue(&$4); + + if ((value & 0xFF) != value) + warning(WARNING_TRUNCATION, "Expression must be 8-bit"); + + if (charmap_Add($2, value & 0xFF) == -1) { fprintf(stderr, "Error parsing charmap. Either you've added too many (%i), or the input character length is too long (%i)' : %s\n", MAXCHARMAPS, CHARMAPLENGTH, strerror(errno)); yyerror("Error parsing charmap."); }