summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor van den Elzen <victor.vde@gmail.com>2008-09-11 15:07:05 +0200
committerVictor van den Elzen <victor.vde@gmail.com>2008-09-11 15:07:05 +0200
commit4252823e95bb365e704cdd8ae526d2daf01a6533 (patch)
tree4b3f9348360bdca0150375c0a8efaf53aace9eee
parent28f463463442010dff5dce13d07962f241faf1f5 (diff)
downloadnasm-4252823e95bb365e704cdd8ae526d2daf01a6533.tar.gz
Limit number of passes to 1000
Now NASM won't take unreasonable an amount of time to generate wrong code when it encounters equ's that don't converge, ex: FOO equ FOO + 1
-rw-r--r--nasm.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/nasm.c b/nasm.c
index 8a689e45..3e4b78e6 100644
--- a/nasm.c
+++ b/nasm.c
@@ -1166,7 +1166,9 @@ static void assemble_file(char *fname, StrList **depend_ptr)
report_error(ERR_FATAL, "command line: "
"32-bit segment size requires a higher cpu");
- pass_max = (INT_MAX >> 1) + 2; /* Almost unlimited */
+ pass_max = 1000; /* Always terminate in a reasonable time */
+ /* No real program should need this many passes */
+
for (passn = 1; pass0 <= 2; passn++) {
int pass1, pass2;
ldfunc def_label;
@@ -1730,9 +1732,17 @@ static void assemble_file(char *fname, StrList **depend_ptr)
usage();
exit(1);
}
- if (passn >= pass_max - 2 ||
- (passn > 1 && !global_offset_changed))
+ if (passn > 1 && !global_offset_changed)
pass0++;
+
+ if(passn >= pass_max)
+ /* We get here if the labels don't converge
+ * Example: FOO equ FOO + 1
+ */
+ report_error(ERR_NONFATAL,
+ "Can't find valid values for all labels "
+ "after %d passes, giving up. "
+ "Possible cause: recursive equ's.", passn);
}
preproc->cleanup(0);