Skip to content

Commit

Permalink
Fix various code & correctness issues (#11815)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Dec 5, 2021
1 parent 7a043b3 commit ff934d5
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 37 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/client/content_cao.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/client/game.cpp
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions src/gettext.h
Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions src/server.cpp
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/settings.cpp
Expand Up @@ -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;
Expand Down
36 changes: 16 additions & 20 deletions src/unittest/test_gettext.cpp
Expand Up @@ -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();
};

Expand All @@ -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);
}
8 changes: 4 additions & 4 deletions src/unittest/test_utilities.cpp
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}

0 comments on commit ff934d5

Please sign in to comment.