2 ms·
> Ubsan should adopt a couple of other safety improvements from C++, ... Ubsan is not a bucket for putting a bunch of "safety improvements", it's a tool for de
by dietrichepp 12y ago
> Ubsan should adopt a couple of other safety improvements from C++, ...
Ubsan is not a bucket for putting a bunch of "safety improvements", it's a tool for detecting undefined behavior at runtime. GCC has many tools for detecting problems in your code, and there are some options which enable several such diagnostics at the same time. Note that ubsan doesn't include asan, which (in my mind) is way more useful than ubsan.
However, an implicit conversion from void * is very common in C. As an observation, most C programmers do not cast the result of malloc(). If you use an explicit cast on your malloc() on Stack Overflow, C programmers will come out of the woodwork to explain not only why it's unnecessary, but why the cast can hide undefined behavior[1], and so you shouldn't do it! So this is a no-go. Maybe you can ask for it as an optional warning if you really want it.
The other one you asked for is already available: -Wwrite-strings. If you want an error, -Werror=write-strings.
I suggest browsing the docs, if you are interested in getting more warnings:
https://gcc.gnu.org/onlinedocs/gcc-4.9.1/gcc/Warning-Options.html#Warning-Options https://gcc.gnu.org/onlinedocs/gcc-4.9.1/gcc/Warning-Options...
[1] If you forget to include <stdlib.h>, then you will get an implicit declaration for malloc() which returns int. An explicit cast from int to e.g. char* is NOT what you want. You can, of course, turn on -Werror=implicit-function-declaration. However, if you just omit the cast, you will always get an error because the int can't be implicitly converted to a pointer type.