target/hexagon/idef-parser: open input file in binary mode
PATCH 1/1 target/hexagon/idef-parser: open input file in binary mode
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.
--- target/hexagon/idef-parser/idef-parser.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/hexagon/idef-parser/idef-parser.y +1 -1
@@ -869,7 +869,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));
Signature · 1 line
2.34.1
Quoted 11 lines · Brian Cain
On Windows, opening a file in text mode causes
fread()to return fewer bytes thanftell()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()andfread()agree on the file size across all platforms.Signed-off-by Brian Cain <[email protected]>--- target/hexagon/idef-parser/idef-parser.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 4 lines · Brian Cain
On Windows, opening a file in text mode causes
fread()to return fewer bytes thanftell()reported, because CRLF sequences are translated to LF on read. This causes idef-parser to report an error and abort.
Quoted 8 lines
Open the input file in binary mode ("rb") so that
ftell()andfread()agree on the file size across all platforms.Signed-off-by Brian Cain <[email protected]>--- target/hexagon/idef-parser/idef-parser.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)