]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Fix some minor code issues all over the place
authorsfan5 <sfan5@live.de>
Wed, 23 Dec 2020 21:03:49 +0000 (22:03 +0100)
committersfan5 <sfan5@live.de>
Thu, 24 Dec 2020 12:44:54 +0000 (13:44 +0100)
19 files changed:
CMakeLists.txt
lib/lua/CMakeLists.txt
src/CMakeLists.txt
src/client/content_cao.cpp
src/client/game.cpp
src/client/hud.cpp
src/client/mapblock_mesh.cpp
src/client/tile.cpp
src/filesys.cpp
src/gui/touchscreengui.cpp
src/irrlicht_changes/CGUITTFont.h
src/irrlicht_changes/irrUString.h
src/mapgen/mapgen_v7.cpp
src/mapgen/treegen.cpp
src/network/serverpackethandler.cpp
src/nodedef.cpp
src/script/cpp_api/s_security.cpp
src/util/srp.cpp
src/util/string.cpp

index 78d551168e3047b4eefc3aab7dac7a4a43f343a1..1d53fcffd20071b3dbb13df43780460ed763c552 100644 (file)
@@ -1,15 +1,9 @@
-cmake_minimum_required(VERSION 2.6)
-
-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()
+cmake_minimum_required(VERSION 3.5)
 
 # This can be read from ${PROJECT_NAME} after project() is called
 project(minetest)
 set(PROJECT_NAME_CAPITALIZED "Minetest")
 
-# Works only for cmake 3.1 and greater
 set(CMAKE_CXX_STANDARD 11)
 set(GCC_MINIMUM_VERSION "4.8")
 set(CLANG_MINIMUM_VERSION "3.4")
index 119dd6302d3e9730a36c514a3af0fb7d985a8830..5d0dc0f708d711704b6322bd5009b9043d0bf793 100644 (file)
@@ -1,5 +1,3 @@
-cmake_minimum_required(VERSION 2.4 FATAL_ERROR)
-
 project(lua C)
 
 set(LUA_VERSION_MAJOR 5)
@@ -15,9 +13,8 @@ set(LIBS)
 
 if(APPLE)
        set(DEFAULT_POSIX TRUE)
-       set(DEFAULT_DLOPEN ON)
-       # use this on Mac OS X 10.3-
-       option(LUA_USE_MACOSX "Mac OS X 10.3-" OFF)
+       set(DEFAULT_DLOPEN OFF)
+       set(COMMON_CFLAGS "${COMMON_CFLAGS} -DLUA_USE_MACOSX")
 elseif(UNIX OR CYGWIN)
        set(DEFAULT_POSIX TRUE)
 elseif(WIN32)
@@ -32,12 +29,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
        set(DEFAULT_DLOPEN ON)
 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})
 mark_as_advanced(LUA_USE_DLOPEN)
 
index b8ce69f1d71880fc1d74fccd426afd861093d070..b6bba6e8db0ac36fd8bdbf87b19b839bccf18520 100644 (file)
@@ -1,5 +1,3 @@
-cmake_minimum_required(VERSION 2.6)
-
 project(minetest)
 
 INCLUDE(CheckIncludeFiles)
@@ -124,27 +122,6 @@ option(ENABLE_FREETYPE "Enable FreeType2 (TrueType fonts and basic unicode suppo
 set(USE_FREETYPE FALSE)
 
 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)
        if(FREETYPE_FOUND)
                message(STATUS "Freetype enabled.")
index c645900aa258c3c903359bd65f8dfd18fcbb8c4e..c65977b449846442cf8829e6e633c1fca1bc7f5e 100644 (file)
@@ -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.
                v3f local_rot = node->getRotation();
                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 &&
-                       (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
                                + m_prop.automatic_face_movement_dir_offset;
                float max_rotation_per_sec =
index 6151d2aa686fb3c2531b81a7abd2719483546443..9e942f47a33c558450443842080b4cd4acd45b4e 100644 (file)
@@ -186,7 +186,7 @@ struct LocalFormspecHandler : public TextDest
                        return;
                }
 
-               if (m_client && m_client->modsLoaded())
+               if (m_client->modsLoaded())
                        m_client->getScript()->on_formspec_input(m_formname, fields);
        }
 
@@ -583,7 +583,7 @@ class GameGlobalShaderConstantSetterFactory : public IShaderConstantSetterFactor
 
        virtual IShaderConstantSetter* create()
        {
-               GameGlobalShaderConstantSetter *scs = new GameGlobalShaderConstantSetter(
+               auto *scs = new GameGlobalShaderConstantSetter(
                                m_sky, m_force_fog_off, m_fog_range, m_client);
                if (!m_sky)
                        created_nosky.push_back(scs);
@@ -1338,7 +1338,7 @@ bool Game::createClient(const GameStartData &start_data)
                return false;
        }
 
-       GameGlobalShaderConstantSetterFactory *scsf = new GameGlobalShaderConstantSetterFactory(
+       auto *scsf = new GameGlobalShaderConstantSetterFactory(
                        &m_flags.force_fog_off, &runData.fog_range, client);
        shader_src->addShaderConstantSetterFactory(scsf);
 
@@ -1348,20 +1348,14 @@ bool Game::createClient(const GameStartData &start_data)
        /* Camera
         */
        camera = new Camera(*draw_control, client);
-       if (!camera || !camera->successfullyCreated(*error_message))
+       if (!camera->successfullyCreated(*error_message))
                return false;
        client->setCamera(camera);
 
        /* Clouds
         */
-       if (m_cache_enable_clouds) {
+       if (m_cache_enable_clouds)
                clouds = new Clouds(smgr, -1, time(0));
-               if (!clouds) {
-                       *error_message = "Memory allocation error (clouds)";
-                       errorstream << *error_message << std::endl;
-                       return false;
-               }
-       }
 
        /* Skybox
         */
@@ -1369,12 +1363,6 @@ bool Game::createClient(const GameStartData &start_data)
        scsf->setSky(sky);
        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
         */
        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);
 
-       if (!hud) {
-               *error_message = "Memory error: could not create HUD";
-               errorstream << *error_message << std::endl;
-               return false;
-       }
-
        mapper = client->getMinimap();
 
        if (mapper && client->modsLoaded())
@@ -1431,11 +1413,6 @@ bool Game::initGui()
        // Chat backend and console
        gui_chat_console = new GUIChatConsole(guienv, guienv->getRootGUIElement(),
                        -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
 
@@ -1492,9 +1469,6 @@ bool Game::connectToServer(const GameStartData &start_data,
                        itemdef_manager, nodedef_manager, sound, eventmgr,
                        connect_address.isIPv6(), m_game_ui.get());
 
-       if (!client)
-               return false;
-
        client->m_simple_singleplayer_mode = simple_singleplayer_mode;
 
        infostream << "Connecting to server at ";
index 8d8411ca1f34323614f365948e6652c04f4cdb79..e956c2738d012a341a28985b52737540f52f8a26 100644 (file)
@@ -1055,9 +1055,9 @@ void drawItemStack(
 
        if (def.type == ITEM_TOOL && item.wear != 0) {
                // Draw a progressbar
-               float barheight = rect.getHeight() / 16;
-               float barpad_x = rect.getWidth() / 16;
-               float barpad_y = rect.getHeight() / 16;
+               float barheight = static_cast<float>(rect.getHeight()) / 16;
+               float barpad_x = static_cast<float>(rect.getWidth()) / 16;
+               float barpad_y = static_cast<float>(rect.getHeight()) / 16;
 
                core::rect<s32> progressrect(
                        rect.UpperLeftCorner.X + barpad_x,
index dac25a0663abb88cb432502935f9690ea5e96212..4c43fcb6175460b15a6cd1b2590c2067c4fcdfd3 100644 (file)
@@ -1201,13 +1201,13 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
 MapBlockMesh::~MapBlockMesh()
 {
        for (scene::IMesh *m : m_mesh) {
-               if (m_enable_vbo && m)
+               if (m_enable_vbo) {
                        for (u32 i = 0; i < m->getMeshBufferCount(); i++) {
                                scene::IMeshBuffer *buf = m->getMeshBuffer(i);
                                RenderingEngine::get_video_driver()->removeHardwareBuffer(buf);
                        }
+               }
                m->drop();
-               m = NULL;
        }
        delete m_minimap_mapblock;
 }
index d03588b2b727f765143b42ded8755433c20077e4..37836d0df5c9dec7ea071de1dd6ac685a900e8f6 100644 (file)
@@ -1633,6 +1633,13 @@ bool TextureSource::generateImagePart(std::string part_of_name,
                        /* IMPORTANT: When changing this, getTextureForMesh() needs to be
                         * 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.
                        if (g_settings->getBool("texture_clean_transparent"))
                                imageCleanTransparent(baseimg, 127);
index 2470b1b647316e925c8570ebd363f14f01e47d79..28a33f4d0168ccfaaf54e1e5ef25720bcb88779f 100644 (file)
@@ -295,31 +295,26 @@ bool RecursiveDelete(const std::string &path)
 
        infostream<<"Removing \""<<path<<"\""<<std::endl;
 
-       //return false;
-
        pid_t child_pid = fork();
 
        if(child_pid == 0)
        {
                // Child
-               char argv_data[3][10000];
+               const char *argv[4] = {
 #ifdef __ANDROID__
-               strcpy(argv_data[0], "/system/bin/rm");
+                       "/system/bin/rm",
 #else
-               strcpy(argv_data[0], "/bin/rm");
+                       "/bin/rm",
 #endif
-               strcpy(argv_data[1], "-rf");
-               strncpy(argv_data[2], path.c_str(), sizeof(argv_data[2]) - 1);
-               char *argv[4];
-               argv[0] = argv_data[0];
-               argv[1] = argv_data[1];
-               argv[2] = argv_data[2];
-               argv[3] = NULL;
+                       "-rf",
+                       path.c_str(),
+                       NULL
+               };
 
                verbosestream<<"Executing '"<<argv[0]<<"' '"<<argv[1]<<"' '"
                                <<argv[2]<<"'"<<std::endl;
 
-               execv(argv[0], argv);
+               execv(argv[0], const_cast<char**>(argv));
 
                // Execv shouldn't return. Failed.
                _exit(1);
@@ -331,7 +326,6 @@ bool RecursiveDelete(const std::string &path)
                pid_t tpid;
                do{
                        tpid = wait(&child_status);
-                       //if(tpid != child_pid) process_terminated(tpid);
                }while(tpid != child_pid);
                return (child_status == 0);
        }
index 0d64aa61826c400234ca67809a19bbe4c394822d..e1a971462369d228ac44ab7fb98cf4152e64adfb 100644 (file)
@@ -881,8 +881,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
                        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);
 
-                       if (m_joystick_has_really_moved ||
-                                       (!m_joystick_has_really_moved && inside_joystick) ||
+                       if (m_joystick_has_really_moved || inside_joystick ||
                                        (!m_fixed_joystick &&
                                        distance_sq > m_touchscreen_threshold * m_touchscreen_threshold)) {
                                m_joystick_has_really_moved = true;
index cf64934a2562c480a41d621348eba517347385c0..310f74f67b55e8f36e12c8d6248d1d27167ccd5e 100644 (file)
@@ -356,7 +356,7 @@ namespace gui
                                load_flags = FT_LOAD_DEFAULT | FT_LOAD_RENDER;
                                if (!useHinting()) load_flags |= FT_LOAD_NO_HINTING;
                                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;
                        }
                        u32 getWidthFromCharacter(wchar_t c) const;
index b628c092c28b5a2371d65910ec81f126a498626a..09172ee6dc384a28fdb3fd1cda262e365b0dfa51 100644 (file)
@@ -1331,7 +1331,7 @@ class ustring16
        {
                u32 i;
                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])
                                return false;
 
@@ -1350,7 +1350,7 @@ class ustring16
                if (!str)
                        return false;
                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])
                                return false;
 
index cc5f5726dd8f6763d294c313ddccdf5bec974cb5..91f004518aefd53dd385e12efc74d857ed8e5254 100644 (file)
@@ -297,7 +297,7 @@ int MapgenV7::getSpawnLevelAtPoint(v2s16 p)
        int iters = 256;
        while (iters > 0 && y <= max_spawn_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
 
                        // y + 1 due to biome 'dust'
index e633d800a3713001d68289fd7d487574abd0b2ba..ec7771439fc04f0269b8352608c28bdf02f03272 100644 (file)
@@ -406,7 +406,8 @@ treegen::error make_ltree(MMVManip &vmanip, v3s16 p0,
                                        v3f(position.X, position.Y, position.Z - 1),
                                        tree_definition
                                );
-                       } if (!stack_orientation.empty()) {
+                       }
+                       if (!stack_orientation.empty()) {
                                s16 size = 1;
                                for (x = -size; x <= size; x++)
                                for (y = -size; y <= size; y++)
index 3db4eb2861718cf92c177d0a68dee2e64be50080..c636d01e1c6f045eb493b416d4be14dedba5f4d0 100644 (file)
@@ -316,7 +316,7 @@ void Server::handleCommand_Init2(NetworkPacket* pkt)
        // Send active objects
        {
                PlayerSAO *sao = getPlayerSAO(peer_id);
-               if (client && sao)
+               if (sao)
                        SendActiveObjectRemoveAdd(client, sao);
        }
 
index 80013192d291f6f96994f7caa9d562a0331cb592..f9d15a9f67af84ea4a14cca1f58fdf81ed88cc2c 100644 (file)
@@ -617,7 +617,7 @@ static void fillTileAttribs(ITextureSource *tsrc, TileLayer *layer,
        bool has_scale = tiledef.scale > 0;
        bool use_autoscale = tsettings.autoscale_mode == AUTOSCALE_FORCE ||
                (tsettings.autoscale_mode == AUTOSCALE_ENABLE && !has_scale);
-       if (use_autoscale && layer->texture) {
+       if (use_autoscale) {
                auto texture_size = layer->texture->getOriginalSize();
                float base_size = tsettings.node_texture_size;
                float size = std::fmin(texture_size.Width, texture_size.Height);
index 01333b941505369345cef6e80bcfc41f6ee5b0aa..63058d7c3f6325dec57cf87943416e14b7764579 100644 (file)
@@ -398,10 +398,9 @@ bool ScriptApiSecurity::safeLoadFile(lua_State *L, const char *path, const char
                        lua_pushfstring(L, "%s: %s", path, strerror(errno));
                        return false;
                }
-               chunk_name = new char[strlen(display_name) + 2];
-               chunk_name[0] = '@';
-               chunk_name[1] = '\0';
-               strcat(chunk_name, display_name);
+               size_t len = strlen(display_name) + 2;
+               chunk_name = new char[len];
+               snprintf(chunk_name, len, "@%s", display_name);
        }
 
        size_t start = 0;
index f4d369d687ce68a80cefb395c46df495a12fb64d..ceb2fef9e011933269fc7abf4b053b48a41d8011 100644 (file)
@@ -1015,10 +1015,10 @@ void  srp_user_process_challenge(struct SRPUser *usr,
                        goto cleanup_and_exit;
 
                *bytes_M = usr->M;
-               if (len_M) *len_M = hash_length(usr->hash_alg);
+               *len_M = hash_length(usr->hash_alg);
        } else {
                *bytes_M = NULL;
-               if (len_M) *len_M = 0;
+               *len_M = 0;
        }
 
 cleanup_and_exit:
index 8381a29c5acce46f2184dfc0dee6f26f3e125ffa..3ac3b8cf0cbb989e6553b81161cd27c7ac32854e 100644 (file)
@@ -633,7 +633,7 @@ static bool parseNamedColorString(const std::string &value, video::SColor &color
                color_name = value;
        }
 
-       color_name = lowercase(value);
+       color_name = lowercase(color_name);
 
        std::map<const std::string, unsigned>::const_iterator it;
        it = named_colors.colors.find(color_name);