From: Peter Johnson Date: Sun, 30 Oct 2005 06:15:15 +0000 (-0000) Subject: Make negative times value an error case. X-Git-Tag: v0.5.0rc1~82 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7f72306ed51e985557dbca59e7b6d03a11040a67;p=yasm Make negative times value an error case. * bytecode.c (yasm_bc_resolve, yasm_bc_tobytes): Look for negative multiple. * timesover-err.asm: New testcase for this. Reported by: Stefan svn path=/trunk/yasm/; revision=1296 --- diff --git a/libyasm/bytecode.c b/libyasm/bytecode.c index 1abf415c..0b120f1c 100644 --- a/libyasm/bytecode.c +++ b/libyasm/bytecode.c @@ -1344,8 +1344,12 @@ yasm_bc_resolve(yasm_bytecode *bc, int save, N_("expression must not contain floating point value")); retval |= YASM_BC_RESOLVE_ERROR; } - } else - bc->len *= yasm_intnum_get_uint(num); + } else { + if (yasm_intnum_sign(num) >= 0) + bc->len *= yasm_intnum_get_uint(num); + else + retval |= YASM_BC_RESOLVE_ERROR; + } yasm_expr_destroy(temp); } @@ -1374,6 +1378,11 @@ yasm_bc_tobytes(yasm_bytecode *bc, unsigned char *buf, unsigned long *bufsize, if (!num) yasm_internal_error( N_("could not determine multiple in bc_tobytes")); + if (yasm_intnum_sign(num) < 0) { + yasm__error(bc->line, N_("multiple is negative")); + *bufsize = 0; + return NULL; + } *multiple = yasm_intnum_get_uint(num); if (*multiple == 0) { *bufsize = 0; diff --git a/libyasm/tests/Makefile.inc b/libyasm/tests/Makefile.inc index 634bbbb5..0594c1cf 100644 --- a/libyasm/tests/Makefile.inc +++ b/libyasm/tests/Makefile.inc @@ -14,6 +14,8 @@ EXTRA_DIST += libyasm/tests/duplabel-err.errwarn EXTRA_DIST += libyasm/tests/incbin.asm EXTRA_DIST += libyasm/tests/incbin.errwarn EXTRA_DIST += libyasm/tests/incbin.hex +EXTRA_DIST += libyasm/tests/timesover-err.asm +EXTRA_DIST += libyasm/tests/timesover-err.errwarn EXTRA_DIST += libyasm/tests/unary.asm EXTRA_DIST += libyasm/tests/unary.errwarn EXTRA_DIST += libyasm/tests/unary.hex diff --git a/libyasm/tests/timesover-err.asm b/libyasm/tests/timesover-err.asm new file mode 100644 index 00000000..6b3b7f95 --- /dev/null +++ b/libyasm/tests/timesover-err.asm @@ -0,0 +1,2 @@ +times 512 db 0 +times 01FEh-($-$$) db 0 diff --git a/libyasm/tests/timesover-err.errwarn b/libyasm/tests/timesover-err.errwarn new file mode 100644 index 00000000..c972a1d9 --- /dev/null +++ b/libyasm/tests/timesover-err.errwarn @@ -0,0 +1 @@ +-:2: multiple is negative