Skip to content

selftest 070 cannot see a process-substituted sort, so a file using comm three times reads as compliant #1111

Description

@OffgridwithJD

test/selftest/070-and-comm-s-two-inputs-must.sh requires every | sort in a file that uses comm to carry LC_ALL=C. Its pattern is a pipe:

grep -E '\|[[:space:]]*sort' "$_f"

A process-substituted sort — comm -23 <(sort "$1") <(sort "$2") — is not a pipeline, so the guard never sees it.

Measured on test/run_all_versions.sh

matches for '| sort'        : 0
occurrences of '<(sort ...)': 3
selftest 070 verdict        : run_all_versions.sh passes the guard

A file that uses comm three times reads as compliant because it never pipes into sort. The three:

pgc_own_mechanism_suites()   { comm -13 <(sort "$1") <(sort "$2"); }
pgc_ran_without_accounting() { comm -23 <(sort "$1") <(sort "$2"); }   # added by #1110
pgc_accounted_among()        { comm -12 <(sort "$1") <(sort "$2"); }   # added by #1110

The same file already applies the convention correctly 500 lines away, which is what makes the gap worth closing rather than arguing about:

LC_ALL=C sort -u "$_reg" >"$_rf"
LC_ALL=C comm -23 "$_rf" "$_af" >"$_t1"

The inputs are not collation-insensitive

Ten real suite names, two collations:

LC_ALL=C      ... pg_dump_roundtrip  pgc_setup  ... projection_update  projections
LC_ALL=en_US  ... pgc_setup  pg_dump_roundtrip  ... projections  projection_update

Two pairs swap, and comm says so when fed en_US-sorted input:

comm: file 1 is not in sorted order
comm: input is not in sorted order

Severity: latent on every environment the gate runs in

Checked rather than assumed. The workflows set no locale, the audit container is C.UTF-8, and C.UTF-8 orders these identically to C. It bites a developer whose box is en_US.UTF-8, which is a common default.

The guard's own comment already notices the distinction it does not cover:

The first reads a FILE and is not a pipeline at all.

What would fix it

Widen the pattern to reach <(sort, $(sort and a bare sort FILE fed to comm, rather than only | sort. The false-positive budget should be measured over the tree first — sort appears in plenty of files that never touch comm, and the guard is already correctly scoped to files that do.

Worth a removal proof in both directions: a <(sort without LC_ALL=C must redden, and the existing piped-sort case must keep reddening.

Provenance

Found while reviewing #1110, whose two new helpers join a pre-existing one. Not a defect #1110 introduced — raised there and approved, with the fix left to whoever takes this.

The other half of the same guard works: adding a comm to docs_style.sh in #1108 correctly flagged five pre-existing piped sorts, which is how I came to look at the pattern at all.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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