Conversation

C PSA/periodic reminder: YOU CANNOT CALL A VARIADIC FUNCTION VIA AN EXPRESSION OF NON-VARIADIC FUNCTION TYPE MATCHING THE ARGS YOU WANT TO USE, OR VICE VERSA!
2
7
Replying to
By casting a function pointer? I'd never even thought to try it, but now that you mention it, I certainly wouldn't expect it to work, though it might by accident on ancient systems that always pass args on stack.
1
Replying to and
No, because C type information is lost compiling to bytecode. There's no error even with a more egregious violation. Needs a compile-time sanitizer. % cat a.c int foo(void) { return 1; } % cat b.c void foo(int x); void bar() { foo(5); } % clang a.c b.c -flto -shared
2
You’d need each callee to know it’s own type, and each caller to check that what it’s calling is indeed what it thinks. Doesn’t seem in line with what UBSan does (i.e. needs storage, needs to work for the entire process). Unless you had something else in mind?
1
1
It could diagnose all the issues at link-time when using LTO. It might not make sense to call that a sanitizer. It wouldn't work across dynamic library boundaries without adding actual metadata in the binary and linker support but that's not required for it to be useful.
2
1
Show replies