From 1c1c97cbd1d7913ac12bf550ec02c97f843a0fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Blot?= Date: Sun, 20 Aug 2017 13:30:50 +0200 Subject: Modernize source code: last part (#6285) * Modernize source code: last par * Use empty when needed * Use emplace_back instead of push_back when needed * For range-based loops * Initializers fixes * constructors, destructors default * c++ C stl includes --- src/script/cpp_api/s_security.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/script/cpp_api/s_security.cpp') diff --git a/src/script/cpp_api/s_security.cpp b/src/script/cpp_api/s_security.cpp index 761597701..690a3b47f 100644 --- a/src/script/cpp_api/s_security.cpp +++ b/src/script/cpp_api/s_security.cpp @@ -260,7 +260,7 @@ void ScriptApiSecurity::initializeSecurityClient() static const char *os_whitelist[] = { "clock", "date", - "difftime", + "difftime", "time", "setlocale", }; @@ -504,7 +504,7 @@ bool ScriptApiSecurity::checkPath(lua_State *L, const char *path, // by the operating system anyways. return false; } - removed = component + (removed.empty() ? "" : DIR_DELIM + removed); + removed.append(component).append(removed.empty() ? "" : DIR_DELIM + removed); abs_path = fs::AbsolutePath(cur_path); } if (abs_path.empty()) @@ -550,9 +550,9 @@ bool ScriptApiSecurity::checkPath(lua_State *L, const char *path, // Allow read-only access to all mod directories if (!write_required) { - const std::vector mods = gamedef->getMods(); - for (size_t i = 0; i < mods.size(); ++i) { - str = fs::AbsolutePath(mods[i].path); + const std::vector &mods = gamedef->getMods(); + for (const ModSpec &mod : mods) { + str = fs::AbsolutePath(mod.path); if (!str.empty() && fs::PathStartsWith(abs_path, str)) { return true; } @@ -617,7 +617,9 @@ int ScriptApiSecurity::sl_g_load(lua_State *L) int t = lua_type(L, -1); if (t == LUA_TNIL) { break; - } else if (t != LUA_TSTRING) { + } + + if (t != LUA_TSTRING) { lua_pushnil(L); lua_pushliteral(L, "Loader didn't return a string"); return 2; -- cgit v1.2.3