Skip to content

fix: cast char to unsigned char before passing to isspace to prevent undefined behavior - #2716

Merged
CarterLi merged 1 commit into
fastfetch-cli:devfrom
pro-laxmi:fix/strutil-ctype-cast
Nov 14, 2026
Merged

CarterLi merged 1 commit into
fastfetch-cli:devfrom
pro-laxmi:fix/strutil-ctype-cast

Conversation

@pro-laxmi

@pro-laxmi pro-laxmi commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Cast signed char to unsigned char before passing to <ctype.h> functions (isspace()) to prevent undefined behavior with non-ASCII or UTF-8 byte sequences.

Changes

  • Cast strbuf->chars[...] to (unsigned char) in ffStrbufEndsWithFn (src/common/FFstrbuf.h).
  • Cast strbuf->chars[index] to (unsigned char) in ffStrbufTrimLeftSpace (src/common/impl/FFstrbuf.c).
  • Cast *str to (unsigned char) in ffStrSet (src/common/strutil.h).
  • Added regression tests in tests/strutil.c testing non-ASCII bytes \x80 and \xff.

Checklist

  • I have tested my changes locally.
    • Ran ctest --test-dir build --output-on-failure: 20/20 tests passed cleanly.

@CarterLi
CarterLi merged commit c6c8bff into fastfetch-cli:dev Nov 14, 2026
25 of 26 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