Skip to content

awk's empty for(;;) condition evaluates as false, so the loop body never runs #76

Description

@davydog187

awk's empty for(;;) condition evaluates as false, so the loop body never runs.

$ awk 'BEGIN{n=0; for(;;){n++; if(n>3) break}; print n}'
0                 # gawk on the same machine prints 4

$ awk 'BEGIN{for(;;){x=x+1}}'
                  # exit 0, empty stderr, 0 ms

In awk, an omitted for condition means truefor(;;) is the idiomatic infinite loop, exited with
break. JustBash treats the missing condition as false and skips the body entirely, so any loop written
that way is silently a no-op and whatever it was meant to compute never happens.

Note the failure mode: exit 0, no diagnostic, wrong answer. for(;;) is common enough in awk one-liners
that an agent writing one gets a confidently wrong result.

The bounded variant is fine — for(i=0;i>=0;i++) runs and is correctly stopped by the wall clock at
~1002 ms — so this is specific to the empty-condition form, not to for generally. Check while() and
do-while for the same treatment of an absent or empty condition.

Likely in lib/just_bash/commands/awk/evaluator.ex around the for clause at :590.


Pre-existing. Verified byte-identical at 16c85b3 and afe0aa8. It terminates, so it is a correctness
bug rather than a sandbox-termination hole, which is why it was left out of #69.

Found by an independent verification pass while working #69 (PR #73).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions