#Tool for statically analysing my C code?

38 messages · Page 1 of 1 (latest)

agile river
#

Could anyone tell me where I can find something better than cppcheck for statically analyze my C code?
I keep seeing errors in valgrind about "Invalid read of size #" meaning I'm probably using freed memory, exceeding the size of my strings or allocating too big ones when I'm using jansson.

So, I'd be specifically looking for something that could help me about that and that could also tell me where are the missing free function calls.

icy plinthBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

simple linden
#

address sanitizers may be more convenient to use than valgrind, I think, also clang sports some static analyzer

torn crest
agile river
torn crest
agile river
#

I'd prefer not using CMake cause I find it very unconvenient ...

torn crest
#

A) Why do you find it inconvenient?
B) Why does that matter rn?

agile river
#

A) Syntax, condition statements, ... mostly everything. Unability to set several sources directories easily and unability to browse them recursively (e.g. aux_source_directory).
B) Cause I'm stuck using this: set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -ggdb -Wall -Wextra")

past trellis
#

You could try gcc -fanalyzer. They’ve been improving it but idk how it’s false positive/negative rate is

#

I agree with sbdswr that asan would be good to try

agile river
agile river
#

There's no way len could be anything else than INET_ADDSTRLEN or INET6_ADDRSTRLEN

simple linden
#

well, you have that path

agile river
#

I have that path?

simple linden
#

the path of code which is clearly shown to you

#

if you go to default len is uninitialized

#

change break there to return NULL e.g.

agile river
#

k good point

simple linden
#

btw sizeof(char) is just 1, always

#

by definition

#

doing anything else there than malloc(len) just feels weird

agile river
#

yeah

#

currently laughing at me

#

wow is -fanalyze is very helpful, won't have headache anymore while trying to find where I fucked up my code

simple linden
#

also, again, the address sanitizer

agile river
#

already detected a leak

simple linden
#

it is memcheck built-in to your code, so faster than valgrind

icy plinthBOT
#
Address Sanitizer

Memory errors are common in C and C++ and can be hard to debug because they often manifest far from their source.

Address sanitizer is a runtime tool that identifies memory errors at their source and makes debugging much simpler. This is an essential tool for C and C++ software development.

Address sanitizer is available for gcc/clang on linux and msvc on windows. To use it, simply pass the flag -fsanitize=address to the compiler.

For a detailed walkthrough, see tccpp Address Sanitizer

agile river
#

k

ruby oar
# agile river A) Syntax, condition statements, ... mostly everything. Unability to set several...

just a sidenote:

condition statements
kinda agree, though the syntax is fine
Unability to set several sources directories easily
wdym? any directroy with a CMakeLists.txt become a a source dir or a dir CMake will be aware of if you include_directory add_subdirectory it (sorry got them both confused)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -ggdb -Wall -Wextra")
isn't the way things should be done anymore. either use presets or at the very least
target_compile_options

agile river
# ruby oar just a sidenote: > condition statements kinda agree, though the syntax is fine >...

wdym? any directroy with a CMakeLists.txt become a a source dir or a dir CMake will be aware of if you include_directory it
yeah, that's unconvenient too, having to add CMakeLists.txt to every single source dir ...
imagine having doing that for a lot of files per directory, and a lot of directories too:
It's not currently the case for me, but could be if I decide to split my source code into several files.

#

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -ggdb -Wall -Wextra")
isn't the way things should be done anymore. either use presets or at the very list
target_compile_options
presets?

icy plinthBOT
#

This question is being automatically marked as stale.
If your question has been answered, type !solved.
If your question is not answered feel free to bump the post or re-ask.
Take a look at !howto ask for tips on improving your question.

agile river
#

!solved