Skip to content

Commit ff934d5

Browse files
authoredDec 5, 2021
Fix various code & correctness issues (#11815)
1 parent 7a043b3 commit ff934d5

8 files changed

+30
-37
lines changed
 

‎CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ set(DEVELOPMENT_BUILD TRUE)
2626

2727
set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
2828
if(VERSION_EXTRA)
29-
set(VERSION_STRING ${VERSION_STRING}-${VERSION_EXTRA})
29+
set(VERSION_STRING "${VERSION_STRING}-${VERSION_EXTRA}")
3030
elseif(DEVELOPMENT_BUILD)
3131
set(VERSION_STRING "${VERSION_STRING}-dev")
3232
endif()

‎src/client/content_cao.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr)
850850
logOnce(oss, warningstream);
851851

852852
video::ITexture *last = m_animated_meshnode->getMaterial(0).TextureLayer[0].Texture;
853-
for (s32 i = 1; i < mat_count; i++) {
853+
for (u32 i = 1; i < mat_count; i++) {
854854
auto &layer = m_animated_meshnode->getMaterial(i).TextureLayer[0];
855855
if (!layer.Texture)
856856
layer.Texture = last;

‎src/client/game.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ bool Game::createClient(const GameStartData &start_data)
13831383
str += L" [";
13841384
str += text;
13851385
str += L"]";
1386-
delete text;
1386+
delete[] text;
13871387
}
13881388
str += L" [";
13891389
str += driver->getName();

‎src/gettext.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ void init_gettext(const char *path, const std::string &configured_language,
4848

4949
extern wchar_t *utf8_to_wide_c(const char *str);
5050

51-
// You must free the returned string!
52-
// The returned string is allocated using new
51+
// The returned string must be freed using delete[]
5352
inline const wchar_t *wgettext(const char *str)
5453
{
5554
// We must check here that is not an empty string to avoid trying to translate it

‎src/server.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,7 @@ void Server::stop()
517517

518518
// Stop threads (set run=false first so both start stopping)
519519
m_thread->stop();
520-
//m_emergethread.setRun(false);
521520
m_thread->wait();
522-
//m_emergethread.stop();
523521

524522
infostream<<"Server: Threads stopped"<<std::endl;
525523
}
@@ -954,14 +952,14 @@ void Server::AsyncRunStep(bool initial_step)
954952
}
955953

956954
/*
957-
Trigger emergethread (it somehow gets to a non-triggered but
958-
bysy state sometimes)
955+
Trigger emerge thread
956+
Doing this every 2s is left over from old code, unclear if this is still needed.
959957
*/
960958
{
961959
float &counter = m_emergethread_trigger_timer;
962-
counter += dtime;
963-
if (counter >= 2.0) {
964-
counter = 0.0;
960+
counter -= dtime;
961+
if (counter <= 0.0f) {
962+
counter = 2.0f;
965963

966964
m_emerge->startThreads();
967965
}

‎src/settings.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void SettingsHierarchy::onLayerCreated(int layer, Settings *obj)
8888

8989
void SettingsHierarchy::onLayerRemoved(int layer)
9090
{
91-
assert(layer >= 0 && layer < layers.size());
91+
assert(layer >= 0 && layer < (int)layers.size());
9292
layers[layer] = nullptr;
9393
if (this == &g_hierarchy && layer == (int)SL_GLOBAL)
9494
g_settings = nullptr;

‎src/unittest/test_gettext.cpp

+16-20
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ class TestGettext : public TestBase
77
public:
88
TestGettext() {
99
TestManager::registerTestModule(this);
10-
}
10+
}
1111

1212
const char *getName() { return "TestGettext"; }
1313

1414
void runTests(IGameDef *gamedef);
1515

16-
void testSnfmtgettext();
1716
void testFmtgettext();
1817
};
1918

@@ -24,24 +23,21 @@ void TestGettext::runTests(IGameDef *gamedef)
2423
TEST(testFmtgettext);
2524
}
2625

26+
// Make sure updatepo.sh does not pick up the strings
27+
#define dummyname fmtgettext
28+
2729
void TestGettext::testFmtgettext()
2830
{
29-
std::string buf = fmtgettext("Viewing range changed to %d", 12);
30-
UASSERTEQ(std::string, buf, "Viewing range changed to 12");
31-
buf = fmtgettext(
32-
"You are about to join this server with the name \"%s\" for the "
33-
"first time.\n"
34-
"If you proceed, a new account using your credentials will be "
35-
"created on this server.\n"
36-
"Please retype your password and click 'Register and Join' to "
37-
"confirm account creation, or click 'Cancel' to abort."
38-
, "A");
39-
UASSERTEQ(std::string, buf,
40-
"You are about to join this server with the name \"A\" for the "
41-
"first time.\n"
42-
"If you proceed, a new account using your credentials will be "
43-
"created on this server.\n"
44-
"Please retype your password and click 'Register and Join' to "
45-
"confirm account creation, or click 'Cancel' to abort."
46-
);
31+
std::string buf = dummyname("sample text %d", 12);
32+
UASSERTEQ(std::string, buf, "sample text 12");
33+
34+
std::string src, expect;
35+
src = "You are about to join this server with the name \"%s\".\n";
36+
expect = "You are about to join this server with the name \"foo\".\n";
37+
for (int i = 0; i < 20; i++) {
38+
src.append("loooong text");
39+
expect.append("loooong text");
40+
}
41+
buf = dummyname(src.c_str(), "foo");
42+
UASSERTEQ(const std::string &, buf, expect);
4743
}

‎src/unittest/test_utilities.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,9 @@ void TestUtilities::testIsPowerOfTwo()
392392
UASSERT(is_power_of_two(2) == true);
393393
UASSERT(is_power_of_two(3) == false);
394394
for (int exponent = 2; exponent <= 31; ++exponent) {
395-
UASSERT(is_power_of_two((1 << exponent) - 1) == false);
396-
UASSERT(is_power_of_two((1 << exponent)) == true);
397-
UASSERT(is_power_of_two((1 << exponent) + 1) == false);
395+
UASSERT(is_power_of_two((1U << exponent) - 1) == false);
396+
UASSERT(is_power_of_two((1U << exponent)) == true);
397+
UASSERT(is_power_of_two((1U << exponent) + 1) == false);
398398
}
399399
UASSERT(is_power_of_two(U32_MAX) == false);
400400
}
@@ -629,4 +629,4 @@ void TestUtilities::testBase64()
629629
UASSERT(base64_is_valid("AAA=A") == false);
630630
UASSERT(base64_is_valid("AAAA=A") == false);
631631
UASSERT(base64_is_valid("AAAAA=A") == false);
632-
}
632+
}

0 commit comments

Comments
 (0)
Please sign in to comment.