fix warnings (#648)

* fix unknown command line argument

* fix warnings settings for gcc

* fix -Wzero-as-null-pointer-constant

* revert CMakeLists.txt
This commit is contained in:
MihailRis 2025-10-10 23:12:01 +03:00 committed by GitHub
parent 8f3e5e880c
commit 24931770d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
50 changed files with 69 additions and 61 deletions

View File

@ -101,13 +101,8 @@ target_compile_options(
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:
-Wall
-Wextra
-Wpedantic
# additional warnings
-Wformat-nonliteral
-Wctor-dtor-privacy
-Wduplicated-branches
-Wduplicated-cond
-Wzero-as-null-pointer-constant
#-Wsign-conversion
-Wcast-align
-Wpointer-arith
@ -116,7 +111,10 @@ target_compile_options(
-Wno-unused-parameter
-Wno-sign-compare
-Wno-unknown-pragmas
-Wno-gnu-anonymous-struct
>
$<$<CXX_COMPILER_ID:MSVC>:
-Wduplicated-branches
-Wduplicated-cond
>)
target_link_options(

View File

@ -25,7 +25,7 @@ Cubemap::Cubemap(uint width, uint height, ImageFormat imageFormat)
0,
format,
GL_UNSIGNED_BYTE,
NULL
nullptr
);
}
}

View File

@ -23,7 +23,7 @@ public:
glGenTextures(1, &depthMap);
glBindTexture(GL_TEXTURE_2D, depthMap);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
resolution, resolution, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
resolution, resolution, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);

View File

@ -17,7 +17,7 @@ namespace guiutil {
/// @brief Create element from XML
/// @param source XML
std::shared_ptr<gui::UINode> create(
gui::GUI& gui, const std::string& source, scriptenv env = 0
gui::GUI& gui, const std::string& source, scriptenv env = nullptr
);
void alert(

View File

@ -169,4 +169,5 @@ const luaL_Reg rigidbodylib[] = {
{"set_crouching", lua::wrap<l_set_crouching>},
{"get_body_type", lua::wrap<l_get_body_type>},
{"set_body_type", lua::wrap<l_set_body_type>},
{NULL, NULL}};
{nullptr, nullptr}
};

View File

@ -169,5 +169,5 @@ const luaL_Reg skeletonlib[] = {
{"is_interpolated", lua::wrap<l_is_interpolated>},
{"set_interpolated", lua::wrap<l_set_interpolated>},
{"exists", lua::wrap<l_exists>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -51,4 +51,5 @@ const luaL_Reg transformlib[] = {
{"set_size", lua::wrap<l_set_size>},
{"get_rot", lua::wrap<l_get_rot>},
{"set_rot", lua::wrap<l_set_rot>},
{NULL, NULL}};
{nullptr, nullptr}
};

View File

@ -2,5 +2,5 @@
const luaL_Reg applib[] = {
// see libcore.cpp an stdlib.lua
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -65,5 +65,5 @@ static int l_parse_model(lua::State* L) {
const luaL_Reg assetslib[] = {
{"load_texture", lua::wrap<l_load_texture>},
{"parse_model", lua::wrap<l_parse_model>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -394,4 +394,5 @@ const luaL_Reg audiolib[] = {
{"get_velocity", lua::wrap<l_audio_get_velocity>},
{"count_speakers", lua::wrap<l_audio_count_speakers>},
{"count_streams", lua::wrap<l_audio_count_streams>},
{NULL, NULL}};
{nullptr, nullptr}
};

View File

@ -49,5 +49,5 @@ const luaL_Reg base64lib[] = {
{"decode", lua::wrap<l_decode<util::base64_decode>>},
{"encode_urlsafe", lua::wrap<l_encode<util::base64_urlsafe_encode>>},
{"decode_urlsafe", lua::wrap<l_decode<util::base64_urlsafe_decode>>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -35,5 +35,5 @@ static int l_frombytes(lua::State* L) {
const luaL_Reg bjsonlib[] = {
{"tobytes", lua::wrap<l_tobytes>},
{"frombytes", lua::wrap<l_frombytes>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -783,5 +783,5 @@ const luaL_Reg blocklib[] = {
{"has_tag", lua::wrap<l_has_tag>},
{"__get_tags", lua::wrap<l_get_tags>},
{"__pull_register_events", lua::wrap<l_pull_register_events>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -39,5 +39,5 @@ const luaL_Reg blockwrapslib[] = {
{"unwrap", lua::wrap<l_unwrap>},
{"set_pos", lua::wrap<l_set_pos>},
{"set_texture", lua::wrap<l_set_texture>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -208,5 +208,5 @@ const luaL_Reg byteutillib[] = {
{"tpack", lua::wrap<l_tpack>},
{"unpack", lua::wrap<l_unpack>},
{"get_size", lua::wrap<l_get_size>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -125,4 +125,5 @@ const luaL_Reg cameralib[] = {
{"get_right", lua::wrap<l_camera_getter<getter_right>>},
{"get_up", lua::wrap<l_camera_getter<getter_up>>},
{"look_at", lua::wrap<l_look_at>},
{NULL, NULL}};
{nullptr, nullptr}
};

View File

@ -79,6 +79,6 @@ static int l_decode(lua::State* L) {
const luaL_Reg compressionlib[] = {
{"encode", lua::wrap<l_encode>},
{"decode", lua::wrap<l_decode>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -126,4 +126,5 @@ const luaL_Reg consolelib[] = {
{"set", lua::wrap<l_set>},
{"get_commands_list", lua::wrap<l_get_commands_list>},
{"get_command_info", lua::wrap<l_get_command_info>},
{NULL, NULL}};
{nullptr, nullptr}
};

View File

@ -310,5 +310,5 @@ const luaL_Reg corelib[] = {
{"open_url", lua::wrap<l_open_url>},
{"quit", lua::wrap<l_quit>},
{"capture_output", lua::wrap<l_capture_output>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -255,5 +255,5 @@ const luaL_Reg entitylib[] = {
{"get_all_in_radius", lua::wrap<l_get_all_in_radius>},
{"raycast", lua::wrap<l_raycast>},
{"reload_component", lua::wrap<l_reload_component>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -404,6 +404,6 @@ const luaL_Reg filelib[] = {
{"__flush_descriptor", lua::wrap<l_flush_descriptor>},
{"__close_descriptor", lua::wrap<l_close_descriptor>},
{"__close_all_descriptors", lua::wrap<l_close_all_descriptors>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -104,5 +104,5 @@ const luaL_Reg generationlib[] = {
{"load_fragment", lua::wrap<l_load_fragment>},
{"get_generators", lua::wrap<l_get_generators>},
{"get_default_generator", lua::wrap<l_get_default_generator>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -1053,5 +1053,5 @@ const luaL_Reg guilib[] = {
{"alert", lua::wrap<l_gui_alert>},
{"load_document", lua::wrap<l_gui_load_document>},
{"__reindex", lua::wrap<l_gui_reindex>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -208,5 +208,5 @@ const luaL_Reg hudlib[] = {
{"_set_debug_cheats", wrap_hud<l_set_debug_cheats>},
{"set_allow_pause", wrap_hud<l_set_allow_pause>},
{"reload_script", wrap_hud<l_reload_script>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -177,5 +177,5 @@ const luaL_Reg inputlib[] = {
{"is_pressed", lua::wrap<l_is_pressed>},
{"reset_bindings", lua::wrap<l_reset_bindings>},
{"set_enabled", lua::wrap<l_set_enabled>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -256,5 +256,5 @@ const luaL_Reg inventorylib[] = {
{"create", lua::wrap<l_create>},
{"remove", lua::wrap<l_remove>},
{"clone", lua::wrap<l_clone>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -147,5 +147,5 @@ const luaL_Reg itemlib[] = {
{"reload_script", lua::wrap<l_reload_script>},
{"has_tag", lua::wrap<l_has_tag>},
{"__get_tags", lua::wrap<l_get_tags>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -19,5 +19,5 @@ static int l_json_parse(lua::State* L) {
const luaL_Reg jsonlib[] = {
{"tostring", lua::wrap<l_json_stringify>},
{"parse", lua::wrap<l_json_parse>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -282,4 +282,5 @@ const luaL_Reg mat4lib[] = {
{"look_at", lua::wrap<l_look_at>},
{"from_quat", lua::wrap<l_from_quat>},
{"tostring", lua::wrap<l_tostring>},
{NULL, NULL}};
{nullptr, nullptr}
};

View File

@ -541,5 +541,5 @@ const luaL_Reg networklib[] = {
{"__get_serverport", wrap<l_get_serverport>},
{"__set_nodelay", wrap<l_set_nodelay>},
{"__is_nodelay", wrap<l_is_nodelay>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -268,5 +268,5 @@ const luaL_Reg packlib[] = {
{"get_base_packs", lua::wrap<l_pack_get_base_packs>},
{"assemble", lua::wrap<l_pack_assemble>},
{"request_writeable", lua::wrap<l_pack_request_writeable>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -82,5 +82,5 @@ const luaL_Reg particleslib[] = {
{"is_alive", wrap_hud<l_is_alive>},
{"get_origin", wrap_hud<l_get_origin>},
{"set_origin", wrap_hud<l_set_origin>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -126,5 +126,5 @@ const luaL_Reg pathfindinglib[] = {
{"set_max_visited", lua::wrap<l_set_max_visited_blocks>},
{"set_jump_height", lua::wrap<l_set_jump_height>},
{"avoid_tag", lua::wrap<l_avoid_tag>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -358,5 +358,5 @@ const luaL_Reg playerlib[] = {
{"set_name", lua::wrap<l_set_name>},
{"create", lua::wrap<l_create>},
{"delete", lua::wrap<l_delete>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -84,5 +84,5 @@ const luaL_Reg posteffectslib[] = {
{"is_active", lua::wrap<l_is_active>},
{"set_params", lua::wrap<l_set_params>},
{"set_array", lua::wrap<l_set_array>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -48,4 +48,5 @@ const luaL_Reg quatlib[] = {
{"from_mat4", lua::wrap<l_from_mat4>},
{"slerp", lua::wrap<l_slerp>},
{"tostring", lua::wrap<l_tostring>},
{NULL, NULL}};
{nullptr, nullptr}
};

View File

@ -42,5 +42,5 @@ const luaL_Reg randomlib[] = {
{"random", lua::wrap<l_random>},
{"bytes", lua::wrap<l_bytes>},
{"uuid", lua::wrap<l_uuid>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -108,5 +108,5 @@ const luaL_Reg text3dlib[] = {
{"set_axis_y", wrap_hud<l_set_axis_y>},
{"set_rotation", wrap_hud<l_set_rotation>},
{"update_settings", wrap_hud<l_update_settings>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -68,5 +68,5 @@ const luaL_Reg timelib[] = {
{"utc_time", lua::wrap<l_utc_time>},
{"utc_offset", lua::wrap<l_utc_offset>},
{"local_time", lua::wrap<l_local_time>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -23,5 +23,5 @@ static int l_toml_parse(lua::State* L) {
const luaL_Reg tomllib[] = {
{"tostring", lua::wrap<l_toml_stringify>},
{"parse", lua::wrap<l_toml_parse>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -99,5 +99,5 @@ const luaL_Reg utf8lib[] = {
{"lower", lua::wrap<l_lower>},
{"encode", lua::wrap<l_encode>},
{"escape", lua::wrap<l_escape>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -228,7 +228,8 @@ const luaL_Reg vec2lib[] = {
{"angle", lua::wrap<l_vec2_angle>},
{"mix", lua::wrap<l_mix<2>>},
{"rotate", lua::wrap<l_vec2_rotate>},
{NULL, NULL}};
{nullptr, nullptr}
};
const luaL_Reg vec3lib[] = {
{"add", lua::wrap<l_binop<3, std::plus>>},
@ -246,7 +247,8 @@ const luaL_Reg vec3lib[] = {
{"dot", lua::wrap<l_dot<3>>},
{"spherical_rand", lua::wrap<l_spherical_rand>},
{"mix", lua::wrap<l_mix<3>>},
{NULL, NULL}};
{nullptr, nullptr}
};
const luaL_Reg vec4lib[] = {
{"add", lua::wrap<l_binop<4, std::plus>>},
@ -263,4 +265,5 @@ const luaL_Reg vec4lib[] = {
{"pow", lua::wrap<l_pow<4>>},
{"dot", lua::wrap<l_dot<4>>},
{"mix", lua::wrap<l_mix<4>>},
{NULL, NULL}};
{nullptr, nullptr}
};

View File

@ -64,5 +64,5 @@ const luaL_Reg weatherlib[] = {
{"get_current_data", lua::wrap<l_get_current_data>},
{"get_fall_intensity", lua::wrap<l_get_fall_intensity>},
{"is_transition", lua::wrap<l_is_transition>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -251,5 +251,5 @@ const luaL_Reg worldlib[] = {
{"save_chunk_data", lua::wrap<l_save_chunk_data>},
{"count_chunks", lua::wrap<l_count_chunks>},
{"reload_script", lua::wrap<l_reload_script>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -16,5 +16,5 @@ static int l_parse(lua::State* L) {
const luaL_Reg yamllib[] = {
{"tostring", lua::wrap<l_stringify>},
{"parse", lua::wrap<l_parse>},
{NULL, NULL}
{nullptr, nullptr}
};

View File

@ -14,7 +14,7 @@ int l_print(lua::State* L) {
lua::pushvalue(L, i); /* value to print */
lua::call(L, 1, 1);
const char* s = lua::tostring(L, -1); /* get result */
if (s == NULL)
if (s == nullptr)
return luaL_error(
L,
LUA_QL("tostring") " must return a string to " LUA_QL("print")

View File

@ -23,7 +23,7 @@ namespace util {
PseudoRandom(unsigned short seed) : seed(seed) {}
PseudoRandom() {
seed = static_cast<unsigned short>(time(0));
seed = static_cast<unsigned short>(time(nullptr));
}
int rand() {

View File

@ -115,7 +115,7 @@ public:
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_POST, request.type == RequestType::POST);
curl_slist* hs = NULL;
curl_slist* hs = nullptr;
for (const auto& header : request.headers) {
hs = curl_slist_append(hs, header.c_str());
@ -172,7 +172,7 @@ public:
url = "";
return;
}
if ((msg = curl_multi_info_read(multiHandle, &messagesLeft)) != NULL) {
if ((msg = curl_multi_info_read(multiHandle, &messagesLeft)) != nullptr) {
if(msg->msg == CURLMSG_DONE) {
curl_multi_remove_handle(multiHandle, curl);
}

View File

@ -126,7 +126,7 @@ bool platform::open_url(const std::string& url) {
return false;
}
#elif defined(_WIN32)
auto res = ShellExecuteW(NULL, L"open", util::quote(url).c_str(), NULL, NULL, SW_SHOWDEFAULT);
auto res = ShellExecuteW(nullptr, L"open", util::quote(url).c_str(), nullptr, nullptr, SW_SHOWDEFAULT);
if (res <= 32) {
logger.warning() << "'open' returned code " << res;
} else {
@ -155,7 +155,7 @@ void platform::open_folder(const std::filesystem::path& folder) {
logger.warning() << "'" << cmd << "' returned code " << res;
}
#elif defined(_WIN32)
ShellExecuteW(NULL, L"open", folder.wstring().c_str(), NULL, NULL, SW_SHOWDEFAULT);
ShellExecuteW(nullptr, L"open", folder.wstring().c_str(), nullptr, nullptr, SW_SHOWDEFAULT);
#else
auto cmd = "xdg-open " + util::quote(folder.u8string());
if (int res = system(cmd.c_str())) {
@ -168,7 +168,7 @@ void platform::open_folder(const std::filesystem::path& folder) {
std::filesystem::path platform::get_executable_path() {
#ifdef _WIN32
wchar_t buffer[MAX_PATH];
DWORD result = GetModuleFileNameW(NULL, buffer, MAX_PATH);
DWORD result = GetModuleFileNameW(nullptr, buffer, MAX_PATH);
if (result == 0) {
DWORD error = GetLastError();
throw std::runtime_error("GetModuleFileName failed with code: " + std::to_string(error));

View File

@ -99,7 +99,7 @@ static bool initialize_gl(int width, int height) {
#ifndef __APPLE__
glEnable(GL_DEBUG_OUTPUT);
glDebugMessageCallback(gl_message_callback, 0);
glDebugMessageCallback(gl_message_callback, nullptr);
#endif
glViewport(0, 0, width, height);
@ -402,7 +402,7 @@ public:
return;
}
cursor = shape;
// NULL cursor is valid for GLFW
// nullptr cursor is valid for GLFW
glfwSetCursor(window, standard_cursors[static_cast<int>(shape)]);
}