Skip to content

Commit 6e4c57b

Browse files
committed
Hotfix #5629 read_as_string should open as binary
Root cause: read_as_string(const openstudio::path& t_path) in src/utilities/core/FilesystemHelpers.cpp opened the file with openstudio::filesystem::ifstream f(t_path); — no std::ios_base::binary flag. On Windows this defaults to text mode, which translates \r\n → \n while reading. The underlying read() helper computes file_len from tellg()/seekg() (the raw on-disk byte count) and then does a single t_file.read(&buf.front(), file_len). In text mode, the CRLF translation means fewer characters actually get read than the buffer was sized for, so the string gets truncated/corrupted with trailing garbage — silently, no error. This only manifests on Windows since POSIX has no text/binary distinction, which matches the "Windows and only Windows" symptom, and explains why parsing barreled all the way to line 8769 before choking on garbage. The sibling function read(const path&) already correctly used std::ios_base::binary — the string-returning overload just missed it. Fix: src/utilities/core/FilesystemHelpers.cpp:38 — added std::ios_base::binary to match. Verified by rebuilding openstudio_utilities_tests and running: - --gtest_filter=*EpwFile_UTF8BOM* → now passes - --gtest_filter=Filetypes.* → all 63 tests pass, no regressions
1 parent 79253ab commit 6e4c57b

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/utilities/core/FilesystemHelpers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace filesystem {
3535
}
3636

3737
std::string read_as_string(const openstudio::path& t_path) {
38-
openstudio::filesystem::ifstream f(t_path);
38+
openstudio::filesystem::ifstream f(t_path, std::ios_base::binary);
3939
return read_as_string(f);
4040
}
4141

0 commit comments

Comments
 (0)