Skip to content

Commit 1e62cce

Browse files
committed
[libs][decrypt] rading a file in safe way to prevent gcc13 warning
1 parent 1b7bfeb commit 1e62cce

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

libs/libdecrypt/test/src/test.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ void createTestXMLFile(const std::string& filePath) {
1515

1616
// Function to read the contents of a file into a string
1717
std::string readFileToString(const std::string& filePath) {
18-
std::ifstream inFile(filePath);
19-
std::string content((std::istreambuf_iterator<char>(inFile)), std::istreambuf_iterator<char>());
20-
inFile.close();
21-
return content;
18+
std::ifstream inFile(filePath, std::ios::binary);
19+
if (!inFile) {
20+
throw std::runtime_error("Unable to open file: " + filePath);
21+
}
22+
23+
std::ostringstream ss;
24+
ss << inFile.rdbuf();
25+
return ss.str();
2226
}

0 commit comments

Comments
 (0)