strfunc: better error messages if a string transform fails

Let the user know what string transform actually failed on them.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin 2019-06-06 17:17:16 -07:00
parent d4b20355d2
commit 236f4a832b
3 changed files with 9 additions and 9 deletions

View File

@ -746,7 +746,7 @@ static expr *eval_floatize(enum floatize type)
return finishtemp();
}
static expr *eval_strfunc(enum strfunc type)
static expr *eval_strfunc(enum strfunc type, const char *name)
{
char *string;
size_t string_len;
@ -760,13 +760,13 @@ static expr *eval_strfunc(enum strfunc type)
scan();
}
if (tt != TOKEN_STR) {
nasm_nonfatal("expecting string");
nasm_nonfatal("expecting string as argument to %s", name);
return NULL;
}
string_len = string_transform(tokval->t_charptr, tokval->t_inttwo,
&string, type);
if (string_len == (size_t)-1) {
nasm_nonfatal("invalid string for transform");
nasm_nonfatal("invalid input string to %s", name);
return NULL;
}
@ -908,7 +908,7 @@ static expr *expr6(void)
return eval_floatize(tokval->t_integer);
case TOKEN_STRFUNC:
return eval_strfunc(tokval->t_integer);
return eval_strfunc(tokval->t_integer, tokval->t_charptr);
case '(':
scan();

View File

@ -612,14 +612,14 @@ restart_parse:
if (i != TOKEN_STR) {
nasm_nonfatal("%s must be followed by a string constant",
funcname);
eop->type = EOT_NOTHING;
eop->type = EOT_NOTHING;
} else {
eop->type = EOT_DB_STRING_FREE;
eop->stringlen =
string_transform(tokval.t_charptr, tokval.t_inttwo,
&eop->stringval, func);
if (eop->stringlen == (size_t)-1) {
nasm_nonfatal("invalid string for transform");
nasm_nonfatal("invalid input string to %s", funcname);
eop->type = EOT_NOTHING;
}
}

View File

@ -3,16 +3,16 @@
./travis/test/utf.asm:65: error: unterminated __utf16__ function
./travis/test/utf.asm:65: error: comma expected after operand 2
./travis/test/utf.asm:66: error: unterminated __utf16__ function
./travis/test/utf.asm:67: error: invalid string for transform
./travis/test/utf.asm:67: error: invalid input string to __utf16__
./travis/test/utf.asm:69: error: __utf16le__ must be followed by a string constant
./travis/test/utf.asm:70: error: __utf16le__ must be followed by a string constant
./travis/test/utf.asm:71: error: unterminated __utf16le__ function
./travis/test/utf.asm:71: error: comma expected after operand 2
./travis/test/utf.asm:72: error: unterminated __utf16le__ function
./travis/test/utf.asm:73: error: invalid string for transform
./travis/test/utf.asm:73: error: invalid input string to __utf16le__
./travis/test/utf.asm:75: error: __utf16be__ must be followed by a string constant
./travis/test/utf.asm:76: error: __utf16be__ must be followed by a string constant
./travis/test/utf.asm:77: error: unterminated __utf16be__ function
./travis/test/utf.asm:77: error: comma expected after operand 2
./travis/test/utf.asm:78: error: unterminated __utf16be__ function
./travis/test/utf.asm:79: error: invalid string for transform
./travis/test/utf.asm:79: error: invalid input string to __utf16be__