Skip to content

sort -h misorders negative sizes: the sign is dropped from the comparison (-500M < -2G < -1G instead of -2G < -1G < -500M) #1371

Closed

Description

@caomengxuan666

Probe-verified (same-source mingw+Wine harness, two runs, GNU coreutils 9.4):

Fixture file with lines -500M, -1G, -2G. Command: sort -h.

  • WinuxCmd output: -500M, -2G, -1G
  • GNU output: -2G, -1G, -500M (ascending numeric order: -2048M < -1024M < -500M)

WinuxCmd appears to compare unit first and magnitude ignoring the sign (within a unit, the larger absolute value sorts first), so any set of negative human-readable sizes comes out wrong.

Expected (GNU)

-h compares the full signed quantity: sign, then scaled magnitude.

Source

src/commands/sort.cpp: the human-numeric comparator (human_size_compare-style path) drops the sign before comparing scaled values.

Regression seed

In-repo test named with this issue number: the fixture above plus a mixed-sign set (-1K, 0, 2K, -3) asserted in GNU order.

Activity

  1. added
    bug
    compat-gap
    on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugcompat-gap

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions