warzone2100 icon indicating copy to clipboard operation
warzone2100 copied to clipboard

Building wz2100 4.4.2 fails with chatoptions.cpp:1103: potential null pointer dereference

Open Selorax opened this issue 1 year ago • 1 comments

System is armbian focal on aarch64. Previous version of warzone 2100, namely 4.3.2 worked fine on the same computer. GCC version is 9.4.0

However when building 4.4.2 I run into multiple problems.

It could be due to missing new dependencies or something, but this warning is very suspicious and looks like a bug, so it could be a serious bug.

# cmake --build . --target install
[0/2] Re-checking globbed directories...
[3/17] Generating __shouldnotexist.h, autorevision.h, autorevision.cache
-- Skipping copy; output file already exists at: "/root/warzone2100/build/build_tools/autorevision.cache"
-- Found Git: /usr/bin/git (found version "2.25.1") 
-- Imported revision data from cache file
[4/10] Running utility command for wz2100_doc
-- Finished generating JS docs
[8/10] Building CXX object src/CMakeFiles/warzone2100.dir/hci/chatoptions.cpp.o
FAILED: src/CMakeFiles/warzone2100.dir/hci/chatoptions.cpp.o 
/usr/bin/c++  -DCURL_GNUTLS_DOES_NOT_REQUIRE_LOCKS_INIT -DJSON_USE_IMPLICIT_CONVERSIONS=0 -DNLOHMANN_JSON_NAMESPACE=nlohmann -DNLOHMANN_JSON_NAMESPACE_BEGIN="namespace nlohmann {" -DNLOHMANN_JSON_NAMESPACE_END=} -DSQLITE_ENABLE_COLUMN_METADATA -DWZ_DEBUG_GFX_API_LEAKS -DYY_NO_UNISTD_H -I. -I../. -I../3rdparty -I../lib/wzmaplib/include -I../3rdparty/optional-lite/include -I../3rdparty/glad/include -I../3rdparty/launchinfo/include -I../3rdparty/EmbeddedJSONSignature/include -I../3rdparty/fmt/include -I../3rdparty/quickjs-wz -I../3rdparty/re2 -I../3rdparty/SQLiteCpp/include -isystem ../3rdparty/glm -isystem ../3rdparty/date/include -isystem ../3rdparty/json/include -fstack-protector-strong -fstack-clash-protection -O2 -g -DNDEBUG -fPIE   -Wpedantic -Wall -Wextra -fno-common -fno-math-errno -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Winit-self -Woverloaded-virtual -Wstrict-null-sentinel -Wwrite-strings -Wpointer-arith -Wmissing-noreturn -Wnon-virtual-dtor -Wnull-dereference -Wduplicated-cond -Walloc-zero -Walloca-larger-than=1024 -Wrestrict -Wfloat-conversion -Wformat-security -Wstringop-truncation -Wlogical-op -Wuninitialized -Werror -Wno-float-conversion -Wno-unused-but-set-variable -Wno-sign-compare -Wno-unused-parameter -Wno-format-truncation -pthread -std=c++14 -MD -MT src/CMakeFiles/warzone2100.dir/hci/chatoptions.cpp.o -MF src/CMakeFiles/warzone2100.dir/hci/chatoptions.cpp.o.d -o src/CMakeFiles/warzone2100.dir/hci/chatoptions.cpp.o -c ../src/hci/chatoptions.cpp
../src/hci/chatoptions.cpp: In member function ‘std::shared_ptr<TableRow> WzChatOptionsForm::newPlayerMuteRow(uint32_t, bool)’:
../src/hci/chatoptions.cpp:1103:65: error: potential null pointer dereference [-Werror=null-dereference]
 1103 |  playerNameLabel->setGeometry(0, 0, playerNameLabel->idealWidth(), playerNameLabel->requiredHeight());
      |                                                                 ^
cc1plus: all warnings being treated as errors
ninja: build stopped: subcommand failed.

P.S. I have tried to edit the code near the line specified by the compiler to get rid of the warning and it worked, the system was able to compile and install:

	// Player Name widget
	auto playerNameLabel = WzPlayerMuteStatusLabel::make(playerIdx);
	// Attempted fix
	if (playerNameLabel == NULL)
	{
		fputs("ERROR: Null pointer dereference in playerNameLabel.\n", stderr);
		exit(1);
	}
	playerNameLabel->setGeometry(0, 0, playerNameLabel->idealWidth(), playerNameLabel->requiredHeight());
	playerNameLabel->setTransparentToMouse(true);

But I have very limited knowledge of C++ so I don't know if it's good enough for anything.

Selorax avatar Dec 03 '23 19:12 Selorax

This is GCC being overzealous with that warning (which is known for generating false-positives). We'll silence it for a future release.

past-due avatar Dec 08 '23 18:12 past-due