From b13e16caa7c5838fb8459870033cec5db0318f2a Mon Sep 17 00:00:00 2001 From: "Benjamin A. Beasley" Date: Wed, 3 Feb 2021 12:57:30 -0500 Subject: [PATCH] Add well-considered patches for all compiler warnings --- libIDL-0.8.14-lexer-sscanf-type-punning.patch | 36 +++++++++++++++++++ libIDL-0.8.14-long-long-format-warnings.patch | 12 +++++++ ...rser-primary_expr-unused-parent-node.patch | 16 +++++++++ libIDL.spec | 12 +++++-- 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 libIDL-0.8.14-lexer-sscanf-type-punning.patch create mode 100644 libIDL-0.8.14-parser-primary_expr-unused-parent-node.patch diff --git a/libIDL-0.8.14-lexer-sscanf-type-punning.patch b/libIDL-0.8.14-lexer-sscanf-type-punning.patch new file mode 100644 index 0000000..c1f906a --- /dev/null +++ b/libIDL-0.8.14-lexer-sscanf-type-punning.patch @@ -0,0 +1,36 @@ +diff -Naur libIDL-0.8.14-original/lexer.l libIDL-0.8.14/lexer.l +--- libIDL-0.8.14-original/lexer.l 2009-04-18 08:20:37.000000000 -0400 ++++ libIDL-0.8.14/lexer.l 2021-02-03 12:56:01.237822569 -0500 +@@ -269,17 +269,29 @@ + <*>{whitespace} ; + {b8_int} { + yylval.integer = 0; +- sscanf (yytext, "%" IDL_LL "o", &yylval.integer); ++ { ++ long long unsigned yyltmp = 0; ++ sscanf (yytext, "%" IDL_LL "o", &yyltmp); ++ memmove (&yylval.integer, &yyltmp, sizeof (yylval.integer)); ++ } + tokreturn (TOK_INTEGER); + } + {b10_uint} { + yylval.integer = 0; +- sscanf (yytext, "%" IDL_LL "u", &yylval.integer); ++ { ++ long long unsigned yyltmp = 0; ++ sscanf (yytext, "%" IDL_LL "u", &yyltmp); ++ memmove (&yylval.integer, &yyltmp, sizeof (yylval.integer)); ++ } + tokreturn (TOK_INTEGER); + } + {b16_int} { + yylval.integer = 0; +- sscanf (yytext + 2, "%" IDL_LL "x", &yylval.integer); ++ { ++ long long unsigned yyltmp = 0; ++ sscanf (yytext + 2, "%" IDL_LL "x", &yyltmp); ++ memmove (&yylval.integer, &yyltmp, sizeof (yylval.integer)); ++ } + tokreturn (TOK_INTEGER); + } + {fixed_lit} { diff --git a/libIDL-0.8.14-long-long-format-warnings.patch b/libIDL-0.8.14-long-long-format-warnings.patch index b167400..22f7b47 100644 --- a/libIDL-0.8.14-long-long-format-warnings.patch +++ b/libIDL-0.8.14-long-long-format-warnings.patch @@ -17,3 +17,15 @@ diff -Naur libIDL-0.8.14-original/parser.y libIDL-0.8.14/parser.y if (ident) IDL_tree_warning (ident, IDL_WARNING1, "From constant declared here"); +diff -Naur libIDL-0.8.14-original/util.c libIDL-0.8.14/util.c +--- libIDL-0.8.14-original/util.c 2009-04-18 08:20:37.000000000 -0400 ++++ libIDL-0.8.14/util.c 2021-02-03 12:42:13.641470825 -0500 +@@ -2818,7 +2818,7 @@ + + case IDLN_INTEGER: + /* FIXME: sign */ +- dataf (data, "%" IDL_LL "d", IDL_INTEGER (p).value); ++ dataf (data, "%" IDL_LL "d", (long long) IDL_INTEGER (p).value); + break; + + case IDLN_FIXED: diff --git a/libIDL-0.8.14-parser-primary_expr-unused-parent-node.patch b/libIDL-0.8.14-parser-primary_expr-unused-parent-node.patch new file mode 100644 index 0000000..057af40 --- /dev/null +++ b/libIDL-0.8.14-parser-primary_expr-unused-parent-node.patch @@ -0,0 +1,16 @@ +diff -Naur libIDL-0.8.14-original/parser.y libIDL-0.8.14/parser.y +--- libIDL-0.8.14-original/parser.y 2009-04-18 08:20:37.000000000 -0400 ++++ libIDL-0.8.14/parser.y 2021-02-03 12:44:47.638466666 -0500 +@@ -898,11 +898,9 @@ + ; + + primary_expr: scoped_name { +- IDL_tree p, literal; ++ IDL_tree literal; + + assert (IDL_NODE_TYPE ($1) == IDLN_IDENT); +- +- p = IDL_NODE_UP ($1); + + if ((literal = IDL_resolve_const_exp ($1, IDLN_ANY))) { + ++IDL_NODE_REFS (literal); diff --git a/libIDL.spec b/libIDL.spec index 50cf260..e784e17 100644 --- a/libIDL.spec +++ b/libIDL.spec @@ -16,13 +16,21 @@ License: LGPLv2+ # Fix paths reported by the libIDL-config-2 tool to conform with Fedora # multilib installation paths: Patch0: %{name}-0.8.6-multilib.patch +# Remove an unused parent-node variable in the primary_expr part of the parser, +# which caused a compiler warning. +Patch1: %{name}-0.8.14-parser-primary_expr-unused-parent-node.patch # On platforms (such as 64-bit Linux), where long long int and long int are # both 64-bit, we can have IDL_LL defined to ll (format with %%lld) while # IDL_longlong_t, which is just gint64, may be ultimately defined to long int. # This results in compiler warnings about the mismatch between the long long # format and long parameter, even though the types are compatible. We can fix # this with a cast to (long long) before formatting. -Patch1: %{name}-0.8.14-long-long-format-warnings.patch +Patch2: %{name}-0.8.14-long-long-format-warnings.patch +# Instead of type-punning with sscanf, parse into a temporary with a type +# matching the format code and then memmove into the “integer” storage. This is +# no less platform-dependent, but does not invoke undefined behavior or produce +# a compiler warning. +Patch3: %{name}-0.8.14-lexer-sscanf-type-punning.patch BuildRequires: gcc BuildRequires: make @@ -98,7 +106,7 @@ rm '%{buildroot}%{_libdir}/%{name}-2.la' - Drop obsolete %%ldconfig_scriptlets macro - Use much stricter path globs - Use %%name macro -- Patch long long format warnings +- Add well-considered patches for all compiler warnings * Tue Jan 26 2021 Fedora Release Engineering - 0.8.14-23 - Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild