Hi,

Building GRUB using the default configuration (-Werror -Wunused-value)
fails with flex >2.6.3.

The problem is with the script lexer, which defines fprintf to 0. The
replacement triggers -Wunused-value in the default flex template for
yy_fatal_error. In previous versions of the template the fprintf call
was cast to void, which silenced the warning. However, the cast was
removed in the latest version of flex.

I’m attaching a patch to fix this by replacing fprintf with grub_printf
instead. Alternatively, fprintf could be #defined to ((void)0), but that
might break if the flex template changes to not ignore the return value.
Another option would be to add a #pragma in yylex.l to ignore unused
values. In any case, the lexer overrides yy_fatal_error, so this code is
never actually executed, only compiled.

Thanks,
Timotej Lazar
>From 2ea83d3f51c42b9150b295a9e3fc3b1b5a94b1e0 Mon Sep 17 00:00:00 2001
From: Timotej Lazar <timotej.la...@araneo.si>
Date: Sun, 4 Jun 2017 18:47:51 +0200
Subject: [PATCH] lexer: fix a #define to avoid unused-value warning

Template for the default yy_fatal_error function changed in flex 2.6.4
to remove the void cast for the fprintf call. Because script/yylex.l
defines fprintf as 0, this triggered the unused-value warning, breaking
compilation with -Werror (on by default). This commit avoids the warning
by replacing fprintf with grub_printf instead.
---
 grub-core/script/yylex.l | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/grub-core/script/yylex.l b/grub-core/script/yylex.l
index 95b219170..43595266f 100644
--- a/grub-core/script/yylex.l
+++ b/grub-core/script/yylex.l
@@ -91,7 +91,7 @@ typedef size_t yy_size_t;
 #define stdin  0
 #define stdout 0
 
-#define fprintf(...) 0
+#define fprintf(stream, ...) grub_printf(__VA_ARGS__)
 #define exit(...) grub_fatal("fatal error in lexer")
 #endif
 
-- 
2.13.0

_______________________________________________
Bug-grub mailing list
Bug-grub@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-grub

Reply via email to