On Windows, opening a file in text mode causes fread() to return fewer
bytes than ftell() reported, because CRLF sequences are translated to
LF on read. This causes idef-parser to report an error and abort.
Open the input file in binary mode ("rb") so that ftell() and fread()
agree on the file size across all platforms.
Reviewed-by: Pierrick Bouvier <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Brian Cain <[email protected]>
---
target/hexagon/idef-parser/idef-parser.y | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/target/hexagon/idef-parser/idef-parser.y
b/target/hexagon/idef-parser/idef-parser.y
index 22070d8c3fe..3cffafa5b76 100644
--- a/target/hexagon/idef-parser/idef-parser.y
+++ b/target/hexagon/idef-parser/idef-parser.y
@@ -872,7 +872,7 @@ int main(int argc, char **argv)
context.header_str = g_string_new(NULL);
context.ternary = g_array_new(FALSE, TRUE, sizeof(Ternary));
/* Read input file */
- FILE *input_file = fopen(argv[ARG_INDEX_IDEFS], "r");
+ FILE *input_file = fopen(argv[ARG_INDEX_IDEFS], "rb");
fseek(input_file, 0L, SEEK_END);
long input_size = ftell(input_file);
context.input_buffer = (char *) calloc(input_size + 1, sizeof(char));
--
2.34.1