Fix various code & correctness issues (#11815)

This commit is contained in:
sfan5 2021-12-05 14:40:30 +01:00 committed by GitHub
parent 7a043b3ebb
commit ff934d538c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 30 additions and 37 deletions

@ -26,7 +26,7 @@ set(DEVELOPMENT_BUILD TRUE)
set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
if(VERSION_EXTRA) if(VERSION_EXTRA)
set(VERSION_STRING ${VERSION_STRING}-${VERSION_EXTRA}) set(VERSION_STRING "${VERSION_STRING}-${VERSION_EXTRA}")
elseif(DEVELOPMENT_BUILD) elseif(DEVELOPMENT_BUILD)
set(VERSION_STRING "${VERSION_STRING}-dev") set(VERSION_STRING "${VERSION_STRING}-dev")
endif() endif()

@ -850,7 +850,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr)
logOnce(oss, warningstream); logOnce(oss, warningstream);
video::ITexture *last = m_animated_meshnode->getMaterial(0).TextureLayer[0].Texture; 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]; auto &layer = m_animated_meshnode->getMaterial(i).TextureLayer[0];
if (!layer.Texture) if (!layer.Texture)
layer.Texture = last; layer.Texture = last;

@ -1383,7 +1383,7 @@ bool Game::createClient(const GameStartData &start_data)
str += L" ["; str += L" [";
str += text; str += text;
str += L"]"; str += L"]";
delete text; delete[] text;
} }
str += L" ["; str += L" [";
str += driver->getName(); str += driver->getName();

@ -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); extern wchar_t *utf8_to_wide_c(const char *str);
// You must free the returned string! // The returned string must be freed using delete[]
// The returned string is allocated using new
inline const wchar_t *wgettext(const char *str) inline const wchar_t *wgettext(const char *str)
{ {
// We must check here that is not an empty string to avoid trying to translate it // We must check here that is not an empty string to avoid trying to translate it

@ -517,9 +517,7 @@ void Server::stop()
// Stop threads (set run=false first so both start stopping) // Stop threads (set run=false first so both start stopping)
m_thread->stop(); m_thread->stop();
//m_emergethread.setRun(false);
m_thread->wait(); m_thread->wait();
//m_emergethread.stop();
infostream<<"Server: Threads stopped"<<std::endl; 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 Trigger emerge thread
bysy state sometimes) Doing this every 2s is left over from old code, unclear if this is still needed.
*/ */
{ {
float &counter = m_emergethread_trigger_timer; float &counter = m_emergethread_trigger_timer;
counter += dtime; counter -= dtime;
if (counter >= 2.0) { if (counter <= 0.0f) {
counter = 0.0; counter = 2.0f;
m_emerge->startThreads(); m_emerge->startThreads();
} }

@ -88,7 +88,7 @@ void SettingsHierarchy::onLayerCreated(int layer, Settings *obj)
void SettingsHierarchy::onLayerRemoved(int layer) void SettingsHierarchy::onLayerRemoved(int layer)
{ {
assert(layer >= 0 && layer < layers.size()); assert(layer >= 0 && layer < (int)layers.size());
layers[layer] = nullptr; layers[layer] = nullptr;
if (this == &g_hierarchy && layer == (int)SL_GLOBAL) if (this == &g_hierarchy && layer == (int)SL_GLOBAL)
g_settings = nullptr; g_settings = nullptr;

@ -7,13 +7,12 @@ class TestGettext : public TestBase
public: public:
TestGettext() { TestGettext() {
TestManager::registerTestModule(this); TestManager::registerTestModule(this);
} }
const char *getName() { return "TestGettext"; } const char *getName() { return "TestGettext"; }
void runTests(IGameDef *gamedef); void runTests(IGameDef *gamedef);
void testSnfmtgettext();
void testFmtgettext(); void testFmtgettext();
}; };
@ -24,24 +23,21 @@ void TestGettext::runTests(IGameDef *gamedef)
TEST(testFmtgettext); TEST(testFmtgettext);
} }
// Make sure updatepo.sh does not pick up the strings
#define dummyname fmtgettext
void TestGettext::testFmtgettext() void TestGettext::testFmtgettext()
{ {
std::string buf = fmtgettext("Viewing range changed to %d", 12); std::string buf = dummyname("sample text %d", 12);
UASSERTEQ(std::string, buf, "Viewing range changed to 12"); UASSERTEQ(std::string, buf, "sample text 12");
buf = fmtgettext(
"You are about to join this server with the name \"%s\" for the " std::string src, expect;
"first time.\n" src = "You are about to join this server with the name \"%s\".\n";
"If you proceed, a new account using your credentials will be " expect = "You are about to join this server with the name \"foo\".\n";
"created on this server.\n" for (int i = 0; i < 20; i++) {
"Please retype your password and click 'Register and Join' to " src.append("loooong text");
"confirm account creation, or click 'Cancel' to abort." expect.append("loooong text");
, "A"); }
UASSERTEQ(std::string, buf, buf = dummyname(src.c_str(), "foo");
"You are about to join this server with the name \"A\" for the " UASSERTEQ(const std::string &, buf, expect);
"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."
);
} }

@ -392,9 +392,9 @@ void TestUtilities::testIsPowerOfTwo()
UASSERT(is_power_of_two(2) == true); UASSERT(is_power_of_two(2) == true);
UASSERT(is_power_of_two(3) == false); UASSERT(is_power_of_two(3) == false);
for (int exponent = 2; exponent <= 31; ++exponent) { for (int exponent = 2; exponent <= 31; ++exponent) {
UASSERT(is_power_of_two((1 << exponent) - 1) == false); UASSERT(is_power_of_two((1U << exponent) - 1) == false);
UASSERT(is_power_of_two((1 << exponent)) == true); UASSERT(is_power_of_two((1U << 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(U32_MAX) == 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("AAA=A") == false);
UASSERT(base64_is_valid("AAAA=A") == false); UASSERT(base64_is_valid("AAAA=A") == false);
UASSERT(base64_is_valid("AAAAA=A") == false); UASSERT(base64_is_valid("AAAAA=A") == false);
} }