From be145da783c9bef7d9f8c37ec84ce0981867fd9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Sat, 6 May 2023 23:02:02 +0200 Subject: [PATCH 1/4] Fix compatibility with GCC 13.1 --- src/openrct2-ui/windows/Changelog.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/openrct2-ui/windows/Changelog.cpp b/src/openrct2-ui/windows/Changelog.cpp index 75c3a89204..5df248f68f 100644 --- a/src/openrct2-ui/windows/Changelog.cpp +++ b/src/openrct2-ui/windows/Changelog.cpp @@ -73,7 +73,12 @@ public: { throw std::runtime_error("Unable to open " + path); } - return std::string((std::istreambuf_iterator(fs)), std::istreambuf_iterator()); + auto length = fs.tellg(); + char* buffer = new char[length]; + fs.read(buffer, length); + auto result = std::string(buffer, buffer + length); + delete[] buffer; + return result; } /** From 851632510fc4895fd73a3b41014439192d28b991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Sun, 7 May 2023 19:37:56 +0200 Subject: [PATCH 2/4] Use unique_ptr --- src/openrct2-ui/windows/Changelog.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/openrct2-ui/windows/Changelog.cpp b/src/openrct2-ui/windows/Changelog.cpp index 5df248f68f..d61be74075 100644 --- a/src/openrct2-ui/windows/Changelog.cpp +++ b/src/openrct2-ui/windows/Changelog.cpp @@ -74,10 +74,9 @@ public: throw std::runtime_error("Unable to open " + path); } auto length = fs.tellg(); - char* buffer = new char[length]; - fs.read(buffer, length); - auto result = std::string(buffer, buffer + length); - delete[] buffer; + std::unique_ptr buffer = std::make_unique(length); + fs.read(buffer.get(), length); + auto result = std::string(buffer.get(), buffer.get() + length); return result; } From 01f32a660fa8c4e449af8769362f8c5c773cb025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Sun, 7 May 2023 20:00:37 +0200 Subject: [PATCH 3/4] Fix length calculation --- src/openrct2-ui/windows/Changelog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2-ui/windows/Changelog.cpp b/src/openrct2-ui/windows/Changelog.cpp index d61be74075..39165e71f3 100644 --- a/src/openrct2-ui/windows/Changelog.cpp +++ b/src/openrct2-ui/windows/Changelog.cpp @@ -73,7 +73,7 @@ public: { throw std::runtime_error("Unable to open " + path); } - auto length = fs.tellg(); + auto length = fs.end - fs.beg; std::unique_ptr buffer = std::make_unique(length); fs.read(buffer.get(), length); auto result = std::string(buffer.get(), buffer.get() + length); From 6f2bf26ce16c574a87fc128403119b9690caefc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Sun, 7 May 2023 20:46:05 +0200 Subject: [PATCH 4/4] Do the seekg thing --- src/openrct2-ui/windows/Changelog.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/openrct2-ui/windows/Changelog.cpp b/src/openrct2-ui/windows/Changelog.cpp index 39165e71f3..5e018d2849 100644 --- a/src/openrct2-ui/windows/Changelog.cpp +++ b/src/openrct2-ui/windows/Changelog.cpp @@ -73,7 +73,9 @@ public: { throw std::runtime_error("Unable to open " + path); } - auto length = fs.end - fs.beg; + fs.seekg(0, fs.end); + auto length = fs.tellg(); + fs.seekg(0, fs.beg); std::unique_ptr buffer = std::make_unique(length); fs.read(buffer.get(), length); auto result = std::string(buffer.get(), buffer.get() + length);