Skip to content

numfmt: --format width accounting diverges from GNU for multi-byte --suffix #11937

@sylvestre

Description

@sylvestre

Summary

When --suffix contains non-ASCII characters and --format=%Nf requests padding, uutils and GNU produce different padding. ASCII suffixes agree exactly.

Found by fuzz_numfmt.

Reproduction

$ LC_ALL=C /usr/bin/numfmt --suffix=🔗 --format=%17.2f 692
692.00🔗
(no leading spaces)

$ LC_ALL=C target/debug/numfmt --suffix=🔗 --format=%17.2f 692
       692.00🔗
(7 leading spaces)

Same with other multi-byte suffixes (`中`, `Ã`, …). Single-byte ASCII suffixes behave identically on both:

$ numfmt --suffix=AB --format=%17.2f 692   # both:  '         692.00AB'

GNU's width calculation seems to deduct the suffix length in a way that makes the full output (including suffix bytes) come out at something ≤ 17, while uutils pads the number portion to width - ascii_byte_len(suffix) regardless of suffix encoding.

Not yet clear which behavior is correct (GNU's is locale-aware; in LC_ALL=C it's arguably ambiguous), but the two should agree.

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