]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Fix various code & correctness issues (#11815)
authorsfan5 <sfan5@live.de>
Sun, 5 Dec 2021 13:40:30 +0000 (14:40 +0100)
committerGitHub <noreply@github.com>
Sun, 5 Dec 2021 13:40:30 +0000 (14:40 +0100)
CMakeLists.txt
src/client/content_cao.cpp
src/client/game.cpp
src/gettext.h
src/server.cpp
src/settings.cpp
src/unittest/test_gettext.cpp
src/unittest/test_utilities.cpp

index 3ba99bc21331a90965c17868a26d842fe97e69cb..ea212bede0aea89dda943c4c724d771b441a487d 100644 (file)
@@ -26,7 +26,7 @@ set(DEVELOPMENT_BUILD TRUE)
 
 set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
 if(VERSION_EXTRA)
-       set(VERSION_STRING ${VERSION_STRING}-${VERSION_EXTRA})
+       set(VERSION_STRING "${VERSION_STRING}-${VERSION_EXTRA}")
 elseif(DEVELOPMENT_BUILD)
        set(VERSION_STRING "${VERSION_STRING}-dev")
 endif()
index 24a9e7921683bbcc955d4b7b5ca56b2e825389b1..a80a3ce4ee15f2d6e15b1fe855855e203f7efc4b 100644 (file)
@@ -850,7 +850,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr)
                        logOnce(oss, warningstream);
 
                        video::ITexture *last = m_animated_meshnode->getMaterial(0).TextureLayer[0].Texture;
-                       for (s32 i = 1; i < mat_count; i++) {
+                       for (u32 i = 1; i < mat_count; i++) {
                                auto &layer = m_animated_meshnode->getMaterial(i).TextureLayer[0];
                                if (!layer.Texture)
                                        layer.Texture = last;
index fb993d92ff7e8169d6093b69a4b402c9c64088bf..54028fd1d17aadbf709d4408ea823df02433d1e0 100644 (file)
@@ -1383,7 +1383,7 @@ bool Game::createClient(const GameStartData &start_data)
                str += L" [";
                str += text;
                str += L"]";
-               delete text;
+               delete[] text;
        }
        str += L" [";
        str += driver->getName();
index 67fd9244fc1e63f8084a032c4007830a011e6430..6225fef93e359a12b5e037c9d5f0c66e4b1a33e8 100644 (file)
@@ -48,8 +48,7 @@ void init_gettext(const char *path, const std::string &configured_language,
 
 extern wchar_t *utf8_to_wide_c(const char *str);
 
-// You must free the returned string!
-// The returned string is allocated using new
+// The returned string must be freed using delete[]
 inline const wchar_t *wgettext(const char *str)
 {
        // We must check here that is not an empty string to avoid trying to translate it
index 5022221ee62a4c5c7269ce8b342e4f0b591cc70e..c175cbcd29f3cbf9eec7e6b411c0a9e64b5943dc 100644 (file)
@@ -517,9 +517,7 @@ void Server::stop()
 
        // Stop threads (set run=false first so both start stopping)
        m_thread->stop();
-       //m_emergethread.setRun(false);
        m_thread->wait();
-       //m_emergethread.stop();
 
        infostream<<"Server: Threads stopped"<<std::endl;
 }
@@ -954,14 +952,14 @@ void Server::AsyncRunStep(bool initial_step)
        }
 
        /*
-               Trigger emergethread (it somehow gets to a non-triggered but
-               bysy state sometimes)
+               Trigger emerge thread
+               Doing this every 2s is left over from old code, unclear if this is still needed.
        */
        {
                float &counter = m_emergethread_trigger_timer;
-               counter += dtime;
-               if (counter >= 2.0) {
-                       counter = 0.0;
+               counter -= dtime;
+               if (counter <= 0.0f) {
+                       counter = 2.0f;
 
                        m_emerge->startThreads();
                }
index 818d2bc41460e8422d949ac34f27d9eb24c1c023..cf7ec1b721d0f351647e7778295db52400d677a9 100644 (file)
@@ -88,7 +88,7 @@ void SettingsHierarchy::onLayerCreated(int layer, Settings *obj)
 
 void SettingsHierarchy::onLayerRemoved(int layer)
 {
-       assert(layer >= 0 && layer < layers.size());
+       assert(layer >= 0 && layer < (int)layers.size());
        layers[layer] = nullptr;
        if (this == &g_hierarchy && layer == (int)SL_GLOBAL)
                g_settings = nullptr;
index 98f73ec627f559ea44176cf3fd98967d2ab1ae07..338a416d7ffcbcee83024e536d3cad585871acd6 100644 (file)
@@ -7,13 +7,12 @@ class TestGettext : public TestBase
 public:
        TestGettext() {
                TestManager::registerTestModule(this);
-  }
+       }
 
        const char *getName() { return "TestGettext"; }
 
        void runTests(IGameDef *gamedef);
 
-       void testSnfmtgettext();
        void testFmtgettext();
 };
 
@@ -24,24 +23,21 @@ void TestGettext::runTests(IGameDef *gamedef)
        TEST(testFmtgettext);
 }
 
+// Make sure updatepo.sh does not pick up the strings
+#define dummyname fmtgettext
+
 void TestGettext::testFmtgettext()
 {
-  std::string buf = fmtgettext("Viewing range changed to %d",  12);
-  UASSERTEQ(std::string, buf, "Viewing range changed to 12");
-  buf = fmtgettext(
-    "You are about to join this server with the name \"%s\" for the "
-    "first time.\n"
-    "If you proceed, a new account using your credentials will be "
-    "created on this server.\n"
-    "Please retype your password and click 'Register and Join' to "
-    "confirm account creation, or click 'Cancel' to abort."
-    ,  "A");
-  UASSERTEQ(std::string, buf,
-    "You are about to join this server with the name \"A\" for the "
-    "first time.\n"
-    "If you proceed, a new account using your credentials will be "
-    "created on this server.\n"
-    "Please retype your password and click 'Register and Join' to "
-    "confirm account creation, or click 'Cancel' to abort."
-  );
+       std::string buf = dummyname("sample text %d", 12);
+       UASSERTEQ(std::string, buf, "sample text 12");
+
+       std::string src, expect;
+       src    = "You are about to join this server with the name \"%s\".\n";
+       expect = "You are about to join this server with the name \"foo\".\n";
+       for (int i = 0; i < 20; i++) {
+               src.append("loooong text");
+               expect.append("loooong text");
+       }
+       buf = dummyname(src.c_str(), "foo");
+       UASSERTEQ(const std::string &, buf, expect);
 }
index 039110d547b5bf53182ffc75eae878b694f22b4e..743fe446216d64253add77bc3655108520601fd9 100644 (file)
@@ -392,9 +392,9 @@ void TestUtilities::testIsPowerOfTwo()
        UASSERT(is_power_of_two(2) == true);
        UASSERT(is_power_of_two(3) == false);
        for (int exponent = 2; exponent <= 31; ++exponent) {
-               UASSERT(is_power_of_two((1 << exponent) - 1) == false);
-               UASSERT(is_power_of_two((1 << exponent)) == true);
-               UASSERT(is_power_of_two((1 << exponent) + 1) == false);
+               UASSERT(is_power_of_two((1U << exponent) - 1) == false);
+               UASSERT(is_power_of_two((1U << exponent)) == true);
+               UASSERT(is_power_of_two((1U << exponent) + 1) == false);
        }
        UASSERT(is_power_of_two(U32_MAX) == false);
 }
@@ -629,4 +629,4 @@ void TestUtilities::testBase64()
        UASSERT(base64_is_valid("AAA=A") == false);
        UASSERT(base64_is_valid("AAAA=A") == false);
        UASSERT(base64_is_valid("AAAAA=A") == false);
-}
\ No newline at end of file
+}