Fix some minor code issues all over the place

This commit is contained in:
sfan5 2020-12-23 22:03:49 +01:00
parent 289425f6bd
commit 74762470b2
19 changed files with 45 additions and 109 deletions

@ -1,15 +1,9 @@
cmake_minimum_required(VERSION 2.6) cmake_minimum_required(VERSION 3.5)
if(${CMAKE_VERSION} STREQUAL "2.8.2")
# Bug http://vtk.org/Bug/view.php?id=11020
message(WARNING "CMake/CPack version 2.8.2 will not create working .deb packages!")
endif()
# This can be read from ${PROJECT_NAME} after project() is called # This can be read from ${PROJECT_NAME} after project() is called
project(minetest) project(minetest)
set(PROJECT_NAME_CAPITALIZED "Minetest") set(PROJECT_NAME_CAPITALIZED "Minetest")
# Works only for cmake 3.1 and greater
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 11)
set(GCC_MINIMUM_VERSION "4.8") set(GCC_MINIMUM_VERSION "4.8")
set(CLANG_MINIMUM_VERSION "3.4") set(CLANG_MINIMUM_VERSION "3.4")

@ -1,5 +1,3 @@
cmake_minimum_required(VERSION 2.4 FATAL_ERROR)
project(lua C) project(lua C)
set(LUA_VERSION_MAJOR 5) set(LUA_VERSION_MAJOR 5)
@ -15,9 +13,8 @@ set(LIBS)
if(APPLE) if(APPLE)
set(DEFAULT_POSIX TRUE) set(DEFAULT_POSIX TRUE)
set(DEFAULT_DLOPEN ON) set(DEFAULT_DLOPEN OFF)
# use this on Mac OS X 10.3- set(COMMON_CFLAGS "${COMMON_CFLAGS} -DLUA_USE_MACOSX")
option(LUA_USE_MACOSX "Mac OS X 10.3-" OFF)
elseif(UNIX OR CYGWIN) elseif(UNIX OR CYGWIN)
set(DEFAULT_POSIX TRUE) set(DEFAULT_POSIX TRUE)
elseif(WIN32) elseif(WIN32)
@ -32,12 +29,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(DEFAULT_DLOPEN ON) set(DEFAULT_DLOPEN ON)
endif() endif()
# For "Mac OS X 10.3-"
if(LUA_USE_MACOSX)
set(COMMON_CFLAGS "${COMMON_CFLAGS} -DLUA_USE_MACOSX")
set(LUA_USE_DLOPEN FALSE)
endif(LUA_USE_MACOSX)
option(LUA_USE_DLOPEN "Enable dlopen support." ${DEFAULT_DLOPEN}) option(LUA_USE_DLOPEN "Enable dlopen support." ${DEFAULT_DLOPEN})
mark_as_advanced(LUA_USE_DLOPEN) mark_as_advanced(LUA_USE_DLOPEN)

@ -1,5 +1,3 @@
cmake_minimum_required(VERSION 2.6)
project(minetest) project(minetest)
INCLUDE(CheckIncludeFiles) INCLUDE(CheckIncludeFiles)
@ -124,27 +122,6 @@ option(ENABLE_FREETYPE "Enable FreeType2 (TrueType fonts and basic unicode suppo
set(USE_FREETYPE FALSE) set(USE_FREETYPE FALSE)
if(ENABLE_FREETYPE) if(ENABLE_FREETYPE)
##
## Note: FindFreetype.cmake seems to have been fixed in recent versions of
## CMake. If issues persist, re-enable this workaround specificially for the
## failing platforms.
##
# if(UNIX)
# include(FindPkgConfig)
# if(PKG_CONFIG_FOUND)
# pkg_check_modules(FREETYPE QUIET freetype2)
# if(FREETYPE_FOUND)
# SET(FREETYPE_PKGCONFIG_FOUND TRUE)
# SET(FREETYPE_LIBRARY ${FREETYPE_LIBRARIES})
# # Because CMake is idiotic
# string(REPLACE ";" " " FREETYPE_CFLAGS_STR ${FREETYPE_CFLAGS})
# string(REPLACE ";" " " FREETYPE_LDFLAGS_STR ${FREETYPE_LDFLAGS})
# endif(FREETYPE_FOUND)
# endif(PKG_CONFIG_FOUND)
# endif(UNIX)
# if(NOT FREETYPE_FOUND)
# find_package(Freetype)
# endif()
find_package(Freetype) find_package(Freetype)
if(FREETYPE_FOUND) if(FREETYPE_FOUND)
message(STATUS "Freetype enabled.") message(STATUS "Freetype enabled.")

@ -1165,7 +1165,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
} }
} }
if (!getParent() && std::fabs(m_prop.automatic_rotate) > 0.001) { if (!getParent() && node && fabs(m_prop.automatic_rotate) > 0.001f) {
// This is the child node's rotation. It is only used for automatic_rotate. // This is the child node's rotation. It is only used for automatic_rotate.
v3f local_rot = node->getRotation(); v3f local_rot = node->getRotation();
local_rot.Y = modulo360f(local_rot.Y - dtime * core::RADTODEG * local_rot.Y = modulo360f(local_rot.Y - dtime * core::RADTODEG *
@ -1174,7 +1174,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
} }
if (!getParent() && m_prop.automatic_face_movement_dir && if (!getParent() && m_prop.automatic_face_movement_dir &&
(fabs(m_velocity.Z) > 0.001 || fabs(m_velocity.X) > 0.001)) { (fabs(m_velocity.Z) > 0.001f || fabs(m_velocity.X) > 0.001f)) {
float target_yaw = atan2(m_velocity.Z, m_velocity.X) * 180 / M_PI float target_yaw = atan2(m_velocity.Z, m_velocity.X) * 180 / M_PI
+ m_prop.automatic_face_movement_dir_offset; + m_prop.automatic_face_movement_dir_offset;
float max_rotation_per_sec = float max_rotation_per_sec =

@ -186,7 +186,7 @@ struct LocalFormspecHandler : public TextDest
return; return;
} }
if (m_client && m_client->modsLoaded()) if (m_client->modsLoaded())
m_client->getScript()->on_formspec_input(m_formname, fields); m_client->getScript()->on_formspec_input(m_formname, fields);
} }
@ -583,7 +583,7 @@ public:
virtual IShaderConstantSetter* create() virtual IShaderConstantSetter* create()
{ {
GameGlobalShaderConstantSetter *scs = new GameGlobalShaderConstantSetter( auto *scs = new GameGlobalShaderConstantSetter(
m_sky, m_force_fog_off, m_fog_range, m_client); m_sky, m_force_fog_off, m_fog_range, m_client);
if (!m_sky) if (!m_sky)
created_nosky.push_back(scs); created_nosky.push_back(scs);
@ -1338,7 +1338,7 @@ bool Game::createClient(const GameStartData &start_data)
return false; return false;
} }
GameGlobalShaderConstantSetterFactory *scsf = new GameGlobalShaderConstantSetterFactory( auto *scsf = new GameGlobalShaderConstantSetterFactory(
&m_flags.force_fog_off, &runData.fog_range, client); &m_flags.force_fog_off, &runData.fog_range, client);
shader_src->addShaderConstantSetterFactory(scsf); shader_src->addShaderConstantSetterFactory(scsf);
@ -1348,20 +1348,14 @@ bool Game::createClient(const GameStartData &start_data)
/* Camera /* Camera
*/ */
camera = new Camera(*draw_control, client); camera = new Camera(*draw_control, client);
if (!camera || !camera->successfullyCreated(*error_message)) if (!camera->successfullyCreated(*error_message))
return false; return false;
client->setCamera(camera); client->setCamera(camera);
/* Clouds /* Clouds
*/ */
if (m_cache_enable_clouds) { if (m_cache_enable_clouds)
clouds = new Clouds(smgr, -1, time(0)); clouds = new Clouds(smgr, -1, time(0));
if (!clouds) {
*error_message = "Memory allocation error (clouds)";
errorstream << *error_message << std::endl;
return false;
}
}
/* Skybox /* Skybox
*/ */
@ -1369,12 +1363,6 @@ bool Game::createClient(const GameStartData &start_data)
scsf->setSky(sky); scsf->setSky(sky);
skybox = NULL; // This is used/set later on in the main run loop skybox = NULL; // This is used/set later on in the main run loop
if (!sky) {
*error_message = "Memory allocation error sky";
errorstream << *error_message << std::endl;
return false;
}
/* Pre-calculated values /* Pre-calculated values
*/ */
video::ITexture *t = texture_src->getTexture("crack_anylength.png"); video::ITexture *t = texture_src->getTexture("crack_anylength.png");
@ -1404,12 +1392,6 @@ bool Game::createClient(const GameStartData &start_data)
hud = new Hud(guienv, client, player, &player->inventory); hud = new Hud(guienv, client, player, &player->inventory);
if (!hud) {
*error_message = "Memory error: could not create HUD";
errorstream << *error_message << std::endl;
return false;
}
mapper = client->getMinimap(); mapper = client->getMinimap();
if (mapper && client->modsLoaded()) if (mapper && client->modsLoaded())
@ -1431,11 +1413,6 @@ bool Game::initGui()
// Chat backend and console // Chat backend and console
gui_chat_console = new GUIChatConsole(guienv, guienv->getRootGUIElement(), gui_chat_console = new GUIChatConsole(guienv, guienv->getRootGUIElement(),
-1, chat_backend, client, &g_menumgr); -1, chat_backend, client, &g_menumgr);
if (!gui_chat_console) {
*error_message = "Could not allocate memory for chat console";
errorstream << *error_message << std::endl;
return false;
}
#ifdef HAVE_TOUCHSCREENGUI #ifdef HAVE_TOUCHSCREENGUI
@ -1492,9 +1469,6 @@ bool Game::connectToServer(const GameStartData &start_data,
itemdef_manager, nodedef_manager, sound, eventmgr, itemdef_manager, nodedef_manager, sound, eventmgr,
connect_address.isIPv6(), m_game_ui.get()); connect_address.isIPv6(), m_game_ui.get());
if (!client)
return false;
client->m_simple_singleplayer_mode = simple_singleplayer_mode; client->m_simple_singleplayer_mode = simple_singleplayer_mode;
infostream << "Connecting to server at "; infostream << "Connecting to server at ";

@ -1055,9 +1055,9 @@ void drawItemStack(
if (def.type == ITEM_TOOL && item.wear != 0) { if (def.type == ITEM_TOOL && item.wear != 0) {
// Draw a progressbar // Draw a progressbar
float barheight = rect.getHeight() / 16; float barheight = static_cast<float>(rect.getHeight()) / 16;
float barpad_x = rect.getWidth() / 16; float barpad_x = static_cast<float>(rect.getWidth()) / 16;
float barpad_y = rect.getHeight() / 16; float barpad_y = static_cast<float>(rect.getHeight()) / 16;
core::rect<s32> progressrect( core::rect<s32> progressrect(
rect.UpperLeftCorner.X + barpad_x, rect.UpperLeftCorner.X + barpad_x,

@ -1201,13 +1201,13 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
MapBlockMesh::~MapBlockMesh() MapBlockMesh::~MapBlockMesh()
{ {
for (scene::IMesh *m : m_mesh) { for (scene::IMesh *m : m_mesh) {
if (m_enable_vbo && m) if (m_enable_vbo) {
for (u32 i = 0; i < m->getMeshBufferCount(); i++) { for (u32 i = 0; i < m->getMeshBufferCount(); i++) {
scene::IMeshBuffer *buf = m->getMeshBuffer(i); scene::IMeshBuffer *buf = m->getMeshBuffer(i);
RenderingEngine::get_video_driver()->removeHardwareBuffer(buf); RenderingEngine::get_video_driver()->removeHardwareBuffer(buf);
} }
}
m->drop(); m->drop();
m = NULL;
} }
delete m_minimap_mapblock; delete m_minimap_mapblock;
} }

@ -1633,6 +1633,13 @@ bool TextureSource::generateImagePart(std::string part_of_name,
/* IMPORTANT: When changing this, getTextureForMesh() needs to be /* IMPORTANT: When changing this, getTextureForMesh() needs to be
* updated too. */ * updated too. */
if (!baseimg) {
errorstream << "generateImagePart(): baseimg == NULL "
<< "for part_of_name=\"" << part_of_name
<< "\", cancelling." << std::endl;
return false;
}
// Apply the "clean transparent" filter, if configured. // Apply the "clean transparent" filter, if configured.
if (g_settings->getBool("texture_clean_transparent")) if (g_settings->getBool("texture_clean_transparent"))
imageCleanTransparent(baseimg, 127); imageCleanTransparent(baseimg, 127);

@ -295,31 +295,26 @@ bool RecursiveDelete(const std::string &path)
infostream<<"Removing \""<<path<<"\""<<std::endl; infostream<<"Removing \""<<path<<"\""<<std::endl;
//return false;
pid_t child_pid = fork(); pid_t child_pid = fork();
if(child_pid == 0) if(child_pid == 0)
{ {
// Child // Child
char argv_data[3][10000]; const char *argv[4] = {
#ifdef __ANDROID__ #ifdef __ANDROID__
strcpy(argv_data[0], "/system/bin/rm"); "/system/bin/rm",
#else #else
strcpy(argv_data[0], "/bin/rm"); "/bin/rm",
#endif #endif
strcpy(argv_data[1], "-rf"); "-rf",
strncpy(argv_data[2], path.c_str(), sizeof(argv_data[2]) - 1); path.c_str(),
char *argv[4]; NULL
argv[0] = argv_data[0]; };
argv[1] = argv_data[1];
argv[2] = argv_data[2];
argv[3] = NULL;
verbosestream<<"Executing '"<<argv[0]<<"' '"<<argv[1]<<"' '" verbosestream<<"Executing '"<<argv[0]<<"' '"<<argv[1]<<"' '"
<<argv[2]<<"'"<<std::endl; <<argv[2]<<"'"<<std::endl;
execv(argv[0], argv); execv(argv[0], const_cast<char**>(argv));
// Execv shouldn't return. Failed. // Execv shouldn't return. Failed.
_exit(1); _exit(1);
@ -331,7 +326,6 @@ bool RecursiveDelete(const std::string &path)
pid_t tpid; pid_t tpid;
do{ do{
tpid = wait(&child_status); tpid = wait(&child_status);
//if(tpid != child_pid) process_terminated(tpid);
}while(tpid != child_pid); }while(tpid != child_pid);
return (child_status == 0); return (child_status == 0);
} }

@ -881,8 +881,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
s32 dyj = event.TouchInput.Y - m_screensize.Y + button_size * 5.0f / 2.0f; s32 dyj = event.TouchInput.Y - m_screensize.Y + button_size * 5.0f / 2.0f;
bool inside_joystick = (dxj * dxj + dyj * dyj <= button_size * button_size * 1.5 * 1.5); bool inside_joystick = (dxj * dxj + dyj * dyj <= button_size * button_size * 1.5 * 1.5);
if (m_joystick_has_really_moved || if (m_joystick_has_really_moved || inside_joystick ||
(!m_joystick_has_really_moved && inside_joystick) ||
(!m_fixed_joystick && (!m_fixed_joystick &&
distance_sq > m_touchscreen_threshold * m_touchscreen_threshold)) { distance_sq > m_touchscreen_threshold * m_touchscreen_threshold)) {
m_joystick_has_really_moved = true; m_joystick_has_really_moved = true;

@ -356,7 +356,7 @@ namespace gui
load_flags = FT_LOAD_DEFAULT | FT_LOAD_RENDER; load_flags = FT_LOAD_DEFAULT | FT_LOAD_RENDER;
if (!useHinting()) load_flags |= FT_LOAD_NO_HINTING; if (!useHinting()) load_flags |= FT_LOAD_NO_HINTING;
if (!useAutoHinting()) load_flags |= FT_LOAD_NO_AUTOHINT; if (!useAutoHinting()) load_flags |= FT_LOAD_NO_AUTOHINT;
if (useMonochrome()) load_flags |= FT_LOAD_MONOCHROME | FT_LOAD_TARGET_MONO | FT_RENDER_MODE_MONO; if (useMonochrome()) load_flags |= FT_LOAD_MONOCHROME | FT_LOAD_TARGET_MONO;
else load_flags |= FT_LOAD_TARGET_NORMAL; else load_flags |= FT_LOAD_TARGET_NORMAL;
} }
u32 getWidthFromCharacter(wchar_t c) const; u32 getWidthFromCharacter(wchar_t c) const;

@ -1331,7 +1331,7 @@ public:
{ {
u32 i; u32 i;
const uchar16_t* oa = other.c_str(); const uchar16_t* oa = other.c_str();
for(i=0; array[i] && oa[i] && i < n; ++i) for(i=0; i < n && array[i] && oa[i]; ++i)
if (array[i] != oa[i]) if (array[i] != oa[i])
return false; return false;
@ -1350,7 +1350,7 @@ public:
if (!str) if (!str)
return false; return false;
u32 i; u32 i;
for(i=0; array[i] && str[i] && i < n; ++i) for(i=0; i < n && array[i] && str[i]; ++i)
if (array[i] != str[i]) if (array[i] != str[i])
return false; return false;

@ -297,7 +297,7 @@ int MapgenV7::getSpawnLevelAtPoint(v2s16 p)
int iters = 256; int iters = 256;
while (iters > 0 && y <= max_spawn_y) { while (iters > 0 && y <= max_spawn_y) {
if (!getMountainTerrainAtPoint(p.X, y + 1, p.Y)) { if (!getMountainTerrainAtPoint(p.X, y + 1, p.Y)) {
if (y <= water_level || y > max_spawn_y) if (y <= water_level)
return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point
// y + 1 due to biome 'dust' // y + 1 due to biome 'dust'

@ -406,7 +406,8 @@ treegen::error make_ltree(MMVManip &vmanip, v3s16 p0,
v3f(position.X, position.Y, position.Z - 1), v3f(position.X, position.Y, position.Z - 1),
tree_definition tree_definition
); );
} if (!stack_orientation.empty()) { }
if (!stack_orientation.empty()) {
s16 size = 1; s16 size = 1;
for (x = -size; x <= size; x++) for (x = -size; x <= size; x++)
for (y = -size; y <= size; y++) for (y = -size; y <= size; y++)

@ -316,7 +316,7 @@ void Server::handleCommand_Init2(NetworkPacket* pkt)
// Send active objects // Send active objects
{ {
PlayerSAO *sao = getPlayerSAO(peer_id); PlayerSAO *sao = getPlayerSAO(peer_id);
if (client && sao) if (sao)
SendActiveObjectRemoveAdd(client, sao); SendActiveObjectRemoveAdd(client, sao);
} }

@ -617,7 +617,7 @@ static void fillTileAttribs(ITextureSource *tsrc, TileLayer *layer,
bool has_scale = tiledef.scale > 0; bool has_scale = tiledef.scale > 0;
bool use_autoscale = tsettings.autoscale_mode == AUTOSCALE_FORCE || bool use_autoscale = tsettings.autoscale_mode == AUTOSCALE_FORCE ||
(tsettings.autoscale_mode == AUTOSCALE_ENABLE && !has_scale); (tsettings.autoscale_mode == AUTOSCALE_ENABLE && !has_scale);
if (use_autoscale && layer->texture) { if (use_autoscale) {
auto texture_size = layer->texture->getOriginalSize(); auto texture_size = layer->texture->getOriginalSize();
float base_size = tsettings.node_texture_size; float base_size = tsettings.node_texture_size;
float size = std::fmin(texture_size.Width, texture_size.Height); float size = std::fmin(texture_size.Width, texture_size.Height);

@ -398,10 +398,9 @@ bool ScriptApiSecurity::safeLoadFile(lua_State *L, const char *path, const char
lua_pushfstring(L, "%s: %s", path, strerror(errno)); lua_pushfstring(L, "%s: %s", path, strerror(errno));
return false; return false;
} }
chunk_name = new char[strlen(display_name) + 2]; size_t len = strlen(display_name) + 2;
chunk_name[0] = '@'; chunk_name = new char[len];
chunk_name[1] = '\0'; snprintf(chunk_name, len, "@%s", display_name);
strcat(chunk_name, display_name);
} }
size_t start = 0; size_t start = 0;

@ -1015,10 +1015,10 @@ void srp_user_process_challenge(struct SRPUser *usr,
goto cleanup_and_exit; goto cleanup_and_exit;
*bytes_M = usr->M; *bytes_M = usr->M;
if (len_M) *len_M = hash_length(usr->hash_alg); *len_M = hash_length(usr->hash_alg);
} else { } else {
*bytes_M = NULL; *bytes_M = NULL;
if (len_M) *len_M = 0; *len_M = 0;
} }
cleanup_and_exit: cleanup_and_exit:

@ -633,7 +633,7 @@ static bool parseNamedColorString(const std::string &value, video::SColor &color
color_name = value; color_name = value;
} }
color_name = lowercase(value); color_name = lowercase(color_name);
std::map<const std::string, unsigned>::const_iterator it; std::map<const std::string, unsigned>::const_iterator it;
it = named_colors.colors.find(color_name); it = named_colors.colors.find(color_name);