-
-
Notifications
You must be signed in to change notification settings - Fork 393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gcc warning: potential null pointer dereference [-Wnull-dereference] using etl::map::insert #830
Comments
When exceptions are not used GCC is expecting that the error handler could return, thereby propagating a |
Ok, I understood. So you suggest that if the error_handler returns, instead of producing undefined behaviour by accessing nullpointer, map::insert to return a nulliterator and false for inserted? That sounds promising. The Standard function std::map::insert returns inserted = false for the case that the key is already present in the map. So the combination of nulliterator and inserted = false for a insert on a full map would still distinguish from the case that the key is already prensent. |
I tested your suggestion. Although it eliminates the undefined behavior the warnings sill arise. I am still not certain which "pointer" the compiler thinks of dereferencing. I am even a bit suspicious that the warning considers some internal magic of the new-statement. /usr/include/etl/map.h:1520:7: warning: potential null pointer dereference [-Wnull-dereference] => Line 1500 in unmodified code /usr/include/etl/map.h:1545:7: warning: potential null pointer dereference [-Wnull-dereference] => Line 1525 in unmodified code |
The warning is there because I need to look again at the library and rethink how errors are handled. The containers especially should be left in a known state if, say, an |
The STL containers will just throw a |
I have raised my own issue #831 where I want to change over to using the error handler in the unit tests, as apposed to exceptions. |
Thank you very much. I think this improved my understanding of the problem. |
Here is a simple example to replicate the issue: https://godbolt.org/z/roYMb7GEb . It also occurs in I think with optimizations turned on the compiler has trouble connecting the logic for ensuring the container is not full and that the allocated pointer won't be null. Changing |
I've so far been unable to replicate the error in the unit tests with 20.38.10, using the test below, but if I paste the body of the test into Godbolt (with the same compiler and options) I do get the error!
|
One possible solution: #873 |
Fixed 20.38.11 |
Hi,
I have a question regaring an occuring compiler warning.
Compiling with -O2 the gcc warns about potential null pointer dereference [-Wnull-dereference] using the function etl::map::insert.
As far is I understand the warning is raised from Line 1500 of map.h:
::new (&node.value) value_type(value);
Disabeling the warning arount the insert statement has no effect since the warning arises from an instantiated template.
Similar behaviour occures using flat_map but in lien 1032 of flat_map.h:
::new (pvalue) value_type(etl::forward(value));
I just wanted to ask if sombody faced the same effect and maybe has some tips for coming around.
Finally I am just not sure if its really a problem of if gccs warning is just a false positive.
We are using gcc 12.2.0 and etl v20.38.10 with ETL_THROW_EXCEPTIONS disabled.
Kind Regards,
Tobias
The text was updated successfully, but these errors were encountered: