Skip to content

Display: validates --*-ndigits CLI options - #2772

Merged
CarterLi merged 1 commit into
fastfetch-cli:devfrom
sagaragas:fix/validate-ndigits-options
Nov 30, 2026
Merged

CarterLi merged 1 commit into
fastfetch-cli:devfrom
sagaragas:fix/validate-ndigits-options

Conversation

@sagaragas

Copy link
Copy Markdown
Contributor

Summary

--size-ndigits rejects values outside 0..9, while --temp-ndigits, --percent-ndigits, --fraction-ndigits, and --freq-ndigits don't check their range at all. They cast the parsed integer straight to uint8_t or int8_t. Passing 16 or higher hits assert(precision <= 15) in ffStrbufAppendDouble() on debug builds or overflows the 4-bit YYJSON_WRITE_FP_TO_FIXED field on release builds. Larger values like 128 or 256 silently wrap around.

This adds the same 0..9 / -1..9 bounds checks to those four CLI flags, exiting 479 like --size-ndigits and matching the JSON config parser. It also updates the --fraction-ndigits remark in doc/help.json from "negative" to -1. Inputs that used to succeed now fail with an error: 10..255 for --temp-ndigits and --percent-ndigits, plus 10..15 and values below -1 for --fraction-ndigits and --freq-ndigits.

Before:

$ fastfetch --freq-ndigits 17 -s cpu -l none
CPU: AMD Ryzen 9 6900HX (16) @ 4.90000000000000000 GHz
$ fastfetch --freq-ndigits 128 -s cpu -l none
CPU: AMD Ryzen 9 6900HX (16) @ 4936 MHz
$ fastfetch --percent-ndigits 256 -s memory -l none
Memory: 500.72 MiB / 20.00 GiB (2%)

After:

$ fastfetch --freq-ndigits 17 -s cpu -l none
Error: --freq-ndigits must be between -1 and 9
$ fastfetch --freq-ndigits 128 -s cpu -l none
Error: --freq-ndigits must be between -1 and 9
$ fastfetch --percent-ndigits 256 -s memory -l none
Error: --percent-ndigits must be between 0 and 9

Checklist

  • I have tested my changes locally.

`--size-ndigits` already rejected values outside 0..9, but
`--temp-ndigits`, `--percent-ndigits`, `--fraction-ndigits`, and
`--freq-ndigits` cast the parsed integer directly to `uint8_t`/`int8_t`.
Values >= 16 hit `assert(precision <= 15)` in `ffStrbufAppendDouble` on
debug builds or overflowed the 4-bit `YYJSON_WRITE_FP_TO_FIXED` field on
release builds, and larger values wrapped modulo 256.

Apply the same 0..9 and -1..9 checks used by `--size-ndigits` and JSON
config parsing, and update the `--fraction-ndigits` remark in
`doc/help.json` to match `-1`.
@CarterLi
CarterLi merged commit 085b262 into fastfetch-cli:dev Nov 30, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants