From 4252823e95bb365e704cdd8ae526d2daf01a6533 Mon Sep 17 00:00:00 2001 From: Victor van den Elzen Date: Thu, 11 Sep 2008 15:07:05 +0200 Subject: [PATCH] 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 --- nasm.c | 16 +++++++++++++--- 1 file 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); -- 2.11.4.GIT