Commit 1430f02c authored by Tim-Philipp Müller's avatar Tim-Philipp Müller 🐠

orcc: fix reading .orc files with win32 line endings on windows

We used to open the files in text/translation mode, which
makes fread() convert all windows-style line endings (\r\n)
to unix style line endings (\n) under the hood. However, the
file size we get from the seek is apparently still the original
binary size, and then we just get less data because the \r have
been removed. This means we put our zero terminator in the wrong
place, and there might be some junk between the end of the
text data and the zero terminator.

Fix this by reading the file in binary mode (who knows what
else the text mode might mess up or trip over, e.g. unicode
chars in comments or such) and pass it to the orc parser
as-is now that the parser can handle win32 line endings.

Spotted by Ray Molenkamp.
parent 3ba19894
......@@ -134,7 +134,7 @@ read_file (const char *filename)
long size;
int ret;
file = fopen (filename, "r");
file = fopen (filename, "rb");
if (file == NULL) return NULL;
ret = fseek (file, 0, SEEK_END);
......
......@@ -459,7 +459,7 @@ read_file (const char *filename)
long size;
int ret;
file = fopen (filename, "r");
file = fopen (filename, "rb");
if (file == NULL) return NULL;
ret = fseek (file, 0, SEEK_END);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment