Skip to content

fix: avoid strnlen() in cs_strndup for Mac OS X 10.5 portability#2889

Open
Scottcjn wants to merge 1 commit intocapstone-engine:nextfrom
Scottcjn:fix/strndup-portability-leopard
Open

fix: avoid strnlen() in cs_strndup for Mac OS X 10.5 portability#2889
Scottcjn wants to merge 1 commit intocapstone-engine:nextfrom
Scottcjn:fix/strndup-portability-leopard

Conversation

@Scottcjn
Copy link
Copy Markdown

Fixes #2517

The cs_strndup() function in cstest uses strnlen(), which is a POSIX.1-2008 addition and is not available on older platforms -- in our case Mac OS X 10.5 Leopard on PowerPC (we build on a Power Mac G4).

This just replaces the strnlen() call with a plain loop that does the same bounded-length scan. No functional change, just makes it compile on systems that lack strnlen.

Tested building cstest with -DCAPSTONE_BUILD_CSTEST=ON on Leopard.

Replace strnlen() call with a simple loop to find the bounded string
length. strnlen() is POSIX.1-2008 and not available on older platforms
like Mac OS X Leopard (10.5).

Fixes capstone-engine#2517

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Rot127
Copy link
Copy Markdown
Collaborator

Rot127 commented Mar 28, 2026

Thanks. Can you please implement it as cs_strnlen in util.c though?
Good chance we need it again in the future.

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.

Usage of non-portable strndup in cstest

2 participants