adamgreen / CppUTest

Custom fork of CppUTest unit testing code that I use from multiple projects.
4 stars 13 forks source link

'this' pointer is null in defaultCrashMethod() #2

Open patrickkeys opened 1 year ago

patrickkeys commented 1 year ago

When attempting to compile, the following error is raised:

mri/CppUTest/src/CppUTest/Utest.cpp: In function ‘void defaultCrashMethod()’:
mri/CppUTest/src/CppUTest/Utest.cpp:94:61: error: ‘this’ pointer is null [-Werror=nonnull]
   94 |         UtestShell* ptr = (UtestShell*) 0x0; ptr->countTests();
      |                                              ~~~~~~~~~~~~~~~^~
At global scope:
cc1plus: note: unrecognized command-line option ‘-Wno-unknown-warning-option’ may have been intended to silence earlier diagnostics
cc1plus: all warnings being treated as errors
make: *** [makefile:268: obj/mri/CppUTest/src/CppUTest/Utest.o] Error 1
adamgreen commented 1 year ago

You don't indicate how you are trying to build this code? I don't use any of the makefiles in this project folder itself. They were just copied over from the original CppUTest as it existed years ago when I first grabbed a copy of it. I just pull it in as a submodule of other projects and it is those other project's Makefiles which compile this code.

If you are starting a new project then I recommend getting the latest from https://github.com/cpputest

The warning can be ignored. That code wants to dereference a NULL pointer to generate a crash.

patrickkeys commented 1 year ago

Hi Adam

Thanks so much for taking a look at this! Apologies for not including more information... I was building as part of CrashDebug, so using the makefiles there. Incidentally, there may be a few more similar issues when trying to build - I'll see if I can resolve in a similar fashion...

adamgreen commented 1 year ago

You could always get rid of the -Werror flag just to get things building and then try to figure out how to fix or silence the other warnings later. If you have a PR that gets it to work in your environment then I would love to see it. By the way, you didn't mention which OS and more importantly which compiler (GCC/Clang/etc) version you are using.

patrickkeys commented 1 year ago

I should have some time (hopefully!) this week to have a look at this - quite happy to work out the necessary changes and send a PR. I'm compiling on Linux, specifically openSUSE Tumbleweed (rolling release), specifically using GCC 13.1.1. Tumbleweed is a rolling (development) release, which means that toolchain changes are more likely to break things - but also a good indicator of changes in the pipeline for other distributions.

adamgreen commented 1 year ago

Thanks for the info.

I should have some time (hopefully!) this week to have a look at this - quite happy to work out the necessary changes and send a PR.

Sounds good.