Skip to content

Usage of non-portable strndup in cstest #2517

@thestr4ng3r

Description

@thestr4ng3r

Work environment

Questions Answers
OS/arch/bits Mac OS X 10.5
Architecture powerpc
Source of Capstone Source with -DCAPSTONE_BUILD_CSTEST=ON
Version/git commit next, 5bd05e3

Expected behavior

cstest (-DCAPSTONE_BUILD_CSTEST=ON) compiles

Actual behavior

[98/175] Building C object suite/cstest/CMakeFiles/libcstest.dir/src/helper.c.o
FAILED: suite/cstest/CMakeFiles/libcstest.dir/src/helper.c.o
/opt/local/bin/gcc-mp-7 -DCAPSTONE_AARCH64_SUPPORT -DCAPSTONE_ALPHA_SUPPORT -DCAPSTONE_ARM_SUPPORT -DCAPSTONE_BPF_SUPPORT -DCAPSTONE_DEBUG -DCAPSTONE_EVM_SUPPORT -DCAPSTONE_HAS_AARCH64 -DCAPSTONE_HAS_ALPHA -DCAPSTONE_HAS_ARM -DCAPSTONE_HAS_BPF -DCAPSTONE_HAS_EVM -DCAPSTONE_HAS_HPPA -DCAPSTONE_HAS_LOONGARCH -DCAPSTONE_HAS_M680X -DCAPSTONE_HAS_M68K -DCAPSTONE_HAS_MIPS -DCAPSTONE_HAS_MOS65XX -DCAPSTONE_HAS_POWERPC -DCAPSTONE_HAS_RISCV -DCAPSTONE_HAS_SH -DCAPSTONE_HAS_SPARC -DCAPSTONE_HAS_SYSTEMZ -DCAPSTONE_HAS_TMS320C64X -DCAPSTONE_HAS_TRICORE -DCAPSTONE_HAS_WASM -DCAPSTONE_HAS_X86 -DCAPSTONE_HAS_XCORE -DCAPSTONE_HAS_XTENSA -DCAPSTONE_HPPA_SUPPORT -DCAPSTONE_LOONGARCH_SUPPORT -DCAPSTONE_M680X_SUPPORT -DCAPSTONE_M68K_SUPPORT -DCAPSTONE_MIPS_SUPPORT -DCAPSTONE_MOS65XX_SUPPORT -DCAPSTONE_PPC_SUPPORT -DCAPSTONE_RISCV_SUPPORT -DCAPSTONE_SH_SUPPORT -DCAPSTONE_SPARC_SUPPORT -DCAPSTONE_SYSTEMZ_SUPPORT -DCAPSTONE_TMS320C64X_SUPPORT -DCAPSTONE_TRICORE_SUPPORT -DCAPSTONE_USE_SYS_DYN_MEM -DCAPSTONE_WASM_SUPPORT -DCAPSTONE_X86_SUPPORT -DCAPSTONE_XCORE_SUPPORT -DCAPSTONE_XTENSA_SUPPORT -I"/Users/florian/dev/capstone/include>" -I/Users/florian/dev/capstone/suite/cstest/include -I/Users/florian/dev/capstone/build/suite/cstest/extern/src/cmocka_ext/include -I/Users/florian/dev/capstone/build/suite/cstest/extern/src/libcyaml_ext/include -I/Users/florian/dev/capstone/include -g -Werror -Wall -Warray-bounds -Wshift-negative-value -Wreturn-type -Wformat -Wmissing-braces -Wunused-function -Wunused-variable -Wparentheses -Wint-in-bool-context -Wmisleading-indentation -Wno-maybe-uninitialized -Wshadow=local -MD -MT suite/cstest/CMakeFiles/libcstest.dir/src/helper.c.o -MF suite/cstest/CMakeFiles/libcstest.dir/src/helper.c.o.d -o suite/cstest/CMakeFiles/libcstest.dir/src/helper.c.o -c /Users/florian/dev/capstone/suite/cstest/src/helper.c
/Users/florian/dev/capstone/suite/cstest/src/helper.c: In function 'replace_hex':
/Users/florian/dev/capstone/suite/cstest/src/helper.c:55:13: error: implicit declaration of function 'strndup' [-Werror=implicit-function-declaration]
   tmp_tmp = strndup(tmp, orig_found - tmp);
             ^~~~~~~
/Users/florian/dev/capstone/suite/cstest/src/helper.c:55:13: error: incompatible implicit declaration of built-in function 'strndup' [-Werror]
/Users/florian/dev/capstone/suite/cstest/src/helper.c: In function 'replace_negative':
/Users/florian/dev/capstone/suite/cstest/src/helper.c:120:13: error: incompatible implicit declaration of built-in function 'strndup' [-Werror]
   tmp_tmp = strndup(tmp, orig_found - tmp);
             ^~~~~~~
cc1: all warnings being treated as errors
[100/175] Linking C static library libcapstone.a
ninja: build stopped: subcommand failed.

Steps to reproduce the behavior

Compile with cmake and cstest enabled (-DCAPSTONE_BUILD_CSTEST=ON) on a platform that does not have strndup.

Additional Logs, screenshots, source code, configuration dump, ...

There are two usages of strndup which is specified by POSIX, but not C standard, and thus not widely available, e.g. on Mac OS X 10.5 with gcc 7. On this platform, #2508 is also necessary for cstest.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions