r/cprogramming • • Oct 07 '26

Using -fsanitize=address feels illegal.

Just saying. The -fsanitize=address compiler flag is absolute cheating and should be prohibited by governments of all countries.

Plus there are also other useful runtime sanitizers, such as integer overflow, but... Integer overflow is much easier to notice, usually.

Of course, this is by no means assuming that -fsanitize=address guarantees that the code it inspects is completely safe and correct and won't ever fail on any input data. You still have to test tricky edge cases. But this sanitizer has improved and sped up the bug discovery process disgustingly much for me.

I'm wondering, how often, if ever, do you need tools such as -fsanitize=address or valgrind? Or are you a real man who stores everything in static memory only?

P.S. Forgive my terrible English.

80 Upvotes

31 comments sorted by

View all comments

13

u/andynzor Oct 07 '26

Not available on embedded. Sad to say this but frontier LLMs are excellent at catching memory errors.

3

u/Nothing_from_void Oct 07 '26

I usually write multiple backends so it can compile on a workstation, this catches a lot of classes of bugs but if you get too much into simulating hardware it does add a lot of lines of code

3

u/anto2554 Oct 07 '26

Don't kernel sanitizers work for this? Haven't really looked into it

2

u/New_Enthusiasm9053 Oct 07 '26

Honestly seems to be a skill issue. Don't write UB and abstract your shit properly and you can test the vast majority of your code on a full OS. Admittedly I don't work with really small devices, we have 2MB of flash so maybe I'm spoiled.

1

u/flatfinger Oct 09 '26

The Standard uses the term "undefined behavior" as a catch-all that includes many situations where it would be impossible to predict how a program would behave without information which the C language does not supply, but which a programmer might receive via means outside the language, such as the documentation supplied with the execution environment. All non-trivial freestanding programs are to some measure reliant upon compilers processing some such corner cases in a manner that is agnostic with regard to whether the environment would be required to specify the behavior.

Both clang and gcc have for years been prone to make illegitimate assumptions about comparisons between a one-past pointer and an object which might have been deliberately placed using the linker to immediately follow it in address space. Such placements can be extremely useful in embedded systems where one wants to allow every byte of RAM that isn't used for any other purpose to be used as a heap. The C language doesn't provide any means of indicating that one symbol is supposed to immediately follow another without any symbols being defined in between, but it also doesn't preclude the possibility that a programmer might know things about symbols brought in via the extern storage class that the compiler can't.