Skip to content

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

Open
pro-laxmi wants to merge 1 commit into
fastfetch-cli:devfrom
pro-laxmi:fix/strutil-ctype-cast
Open

pro-laxmi wants to merge 1 commit into
fastfetch-cli:devfrom
pro-laxmi:fix/strutil-ctype-cast

Conversation

@pro-laxmi

Copy link
Copy Markdown

Summary of Changes

In the C standard library <ctype.h>, character classification functions like isspace() require their argument to be representable as an unsigned char or equal to EOF. Passing a signed char with a negative value (e.g. non-ASCII or UTF-8 code units \x80 through \xFF) causes undefined behavior.

Fix

  • Added explicit (unsigned char) casts in:
    • ffStrSet (src/common/strutil.h)
    • ffStrbufTrimLeftSpace (src/common/impl/FFstrbuf.c)
    • ffStrbufEndsWithFn (src/common/FFstrbuf.h)
  • Added regression tests in tests/strutil.c verifying ffStrSet handles non-ASCII bytes \x80 and \xff.

Verification & Testing

  • Built and ran full test suite via CTest (ctest --test-dir build).
  • 20/20 test targets passed cleanly.

This branch has not been deployed

No deployments
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.

1 participant