From 75bf9b75caba5fc876f20eabea3fabc142d1b51e Mon Sep 17 00:00:00 2001
From: sfan5 <sfan5@live.de>
Date: Sat, 11 Sep 2021 21:06:57 +0200
Subject: Make sure relevant std::stringstreams are set to binary

---
 src/script/common/c_converter.cpp |  5 +----
 src/script/lua_api/l_mapgen.cpp   |  4 +---
 src/script/lua_api/l_util.cpp     | 12 ++++++------
 3 files changed, 8 insertions(+), 13 deletions(-)

(limited to 'src/script')

diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp
index d848b75b8..19734b913 100644
--- a/src/script/common/c_converter.cpp
+++ b/src/script/common/c_converter.cpp
@@ -76,10 +76,7 @@ static void set_vector_metatable(lua_State *L)
 
 void push_float_string(lua_State *L, float value)
 {
-	std::stringstream ss;
-	std::string str;
-	ss << value;
-	str = ss.str();
+	auto str = ftos(value);
 	lua_pushstring(L, str.c_str());
 }
 
diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp
index eb3d49a5e..f173bd162 100644
--- a/src/script/lua_api/l_mapgen.cpp
+++ b/src/script/lua_api/l_mapgen.cpp
@@ -752,9 +752,7 @@ int ModApiMapgen::l_get_mapgen_params(lua_State *L)
 	lua_setfield(L, -2, "mgname");
 
 	settingsmgr->getMapSetting("seed", &value);
-	std::istringstream ss(value);
-	u64 seed;
-	ss >> seed;
+	u64 seed = from_string<u64>(value);
 	lua_pushinteger(L, seed);
 	lua_setfield(L, -2, "seed");
 
diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp
index 9152b5f7f..2405cd90d 100644
--- a/src/script/lua_api/l_util.cpp
+++ b/src/script/lua_api/l_util.cpp
@@ -272,11 +272,11 @@ int ModApiUtil::l_compress(lua_State *L)
 	const char *data = luaL_checklstring(L, 1, &size);
 
 	int level = -1;
-	if (!lua_isnone(L, 3) && !lua_isnil(L, 3))
-		level = readParam<float>(L, 3);
+	if (!lua_isnoneornil(L, 3))
+		level = readParam<int>(L, 3);
 
-	std::ostringstream os;
-	compressZlib(std::string(data, size), os, level);
+	std::ostringstream os(std::ios_base::binary);
+	compressZlib(reinterpret_cast<const u8 *>(data), size, os, level);
 
 	std::string out = os.str();
 
@@ -292,8 +292,8 @@ int ModApiUtil::l_decompress(lua_State *L)
 	size_t size;
 	const char *data = luaL_checklstring(L, 1, &size);
 
-	std::istringstream is(std::string(data, size));
-	std::ostringstream os;
+	std::istringstream is(std::string(data, size), std::ios_base::binary);
+	std::ostringstream os(std::ios_base::binary);
 	decompressZlib(is, os);
 
 	std::string out = os.str();
-- 
cgit v1.2.3