False condition in IF force loop exit (TCC/LE 14 64bits)

Oct 8, 2019
1
0
In a loop parsing arguments, when the condition of a IF is false, make it exit.
Here is a very simplified example that show the bug (bug.bat) :
Bash:
set args=spam and eggs

:loop
for /F "tokens=1,* delims= " %%a in ("%args%") do (

    echo -------------------  "%%a" / "%%b"

    if "%1" == "1"         echo within if
   
    echo after if
    set  args=%%b
    goto :loop
)
Here is the console output, with the condition evaluated to TRUE :
Code:
TCC>bug.bat 1
-------------------  "spam" / "and eggs"
within if
after if
-------------------  "and" / "eggs"
within if
after if
-------------------  "eggs" / ""
within if
after if
And now, with the condition evaluated to FALSE :
Code:
TCC>bug.bat 2
-------------------  "spam" / "and eggs"
If looks like the IF FALSE acts like an exit from the loop...

By the way, the same batch executed by MS cmd runs as expected :
Code:
CMD>bug.bat 2
-------------------  "spam" / "and eggs"
after if
-------------------  "and" / "eggs"
after if
-------------------  "eggs" / ""
after if
 

rconn

Administrator
Staff member
May 14, 2008
11,377
107
This is actually a bug in CMD (or at least nonsensical and undocumented behavior). The full version of TCC does emulate this CMD behavior.

TCC/LE is unsupported and deprecated; it's been replaced (for the purpose of executing batch files, not interactive command line usage) with TCC/RT. We will not be updating TCC/LE.
 

rconn

Administrator
Staff member
May 14, 2008
11,377
107
Would DuplicateBugs affect this?
Yes and no. DuplicateBugs will change the IF behavior to work like CMD's, and abort the remainder of the command line regardless of command separators or conditional commands. However, there's actually *two* CMD bugs here -it behaves differently when IF is in a command group vs by itself. The later versions of TCC support both bugs; TCC/LE only supports the non-command group bug.

Somewhat counter-intuitively, TCC/LE will run the batch file like CMD if you set DuplicateBugs=No. Of course, it will then fail on the non-command group IF usage.