[PATCH] target/hexagon/idef-parser: open input file in binary mode

Brian Cain posted 1 patch 1 month, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260619042840.2169504-1-brian.cain@oss.qualcomm.com
Maintainers: Alessandro Di Federico <ale@rev.ng>, Anton Johansson <anjo@rev.ng>
target/hexagon/idef-parser/idef-parser.y | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] target/hexagon/idef-parser: open input file in binary mode
Posted by Brian Cain 1 month, 1 week ago
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.

Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
---
 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 c6f17c6afa7..caba0d2644d 100644
--- a/target/hexagon/idef-parser/idef-parser.y
+++ b/target/hexagon/idef-parser/idef-parser.y
@@ -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));
-- 
2.34.1

Re: [PATCH] target/hexagon/idef-parser: open input file in binary mode
Posted by Pierrick Bouvier 1 month ago
On 6/18/2026 9:28 PM, Brian Cain wrote:
> 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.
> 
> Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
> ---
>  target/hexagon/idef-parser/idef-parser.y | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Re: [PATCH] target/hexagon/idef-parser: open input file in binary mode
Posted by Philippe Mathieu-Daudé 1 month, 1 week ago
On 19/6/26 06:28, Brian Cain wrote:
> 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.
> 
> Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
> ---
>   target/hexagon/idef-parser/idef-parser.y | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>