coolxv / cpp-stub

C++ unit test stub(not mock) and awesome.Surpported ISA x86,x86-64,arm64,arm32,arm thumb,mips64,riscv,loongarch64.
MIT License
272 stars 80 forks source link

use `unsigned char*` for the fn pointer type #37

Closed jiridanek closed 8 months ago

jiridanek commented 8 months ago

When the type is just char*, I get a lot of -Woverflow warnings from the compiler

main.cpp:22:
cpp-stub/stub.h: In instantiation of ‘void Stub::set(T, S) [with T = int (*)(int); S = int (*)(int)]’:
main.cpp:42:17:   required from here
cpp-stub/stub.h:209:21: error: overflow in conversion from ‘int’ to ‘char’ changes value from ‘187’ to ‘-69’ [-Werror=overflow]
  209 |         *(fn + 1) = 0xbb;\
      |                     ^~~~
cpp-stub/stub.h:327:13: note: in expansion of macro ‘REPLACE_FAR’
  327 |             REPLACE_FAR(this, fn, fn_stub);
      |             ^~~~~~~~~~~