summaryrefslogtreecommitdiff
path: root/sys-devel/flex/files/flex-2.6.4-implicit-func-decl.patch
blob: 1900ae0529b98d21d20f87d32a7438be1e149a94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
https://github.com/westes/flex/commit/4b5111d9772b5c160340ca96f08d30d7f6db5cda
https://github.com/westes/flex/issues/436
https://bugs.gentoo.org/705800
https://developers.redhat.com/blog/2019/04/22/implicit-function-declarations-flexs-use-of-reallocarray

From 4b5111d9772b5c160340ca96f08d30d7f6db5cda Mon Sep 17 00:00:00 2001
From: Explorer09 <explorer09@gmail.com>
Date: Mon, 4 Sep 2017 08:28:53 +0800
Subject: [PATCH] scanner: Include flexdef.h at %top block of scan.l

config.h may define macros that alter the API of the standard library
funtions, and so it should be included before any other standard
header, even before the skeleton's standard header inclusion.

For example: config.h may #define _GNU_SOURCE that would expose the
reallocarray() prototype from <stdlib.h> on glibc 2.26+ systems. If we
include <stdlib.h> before config.h, reallocarray() would not be
available for use in lex file since the second include doesn't help
due to header guard.

For now our config.h might `#define malloc rpl_malloc` -- this
substitution must work before including stdlib.h, or else the compiler
will complain about missing prototypes, and may result in incorrect
code in scan.l (gcc warning: return makes pointer from integer without
a cast [-Wint-conversion]).

Fixes #247.
--- a/src/scan.l
+++ b/src/scan.l
@@ -1,5 +1,11 @@
 /* scan.l - scanner for flex input -*-C-*- */
 
+%top{
+/* flexdef.h includes config.h, which may contain macros that alter the API */
+/* of libc functions. Must include first before any libc header. */
+#include "flexdef.h"
+}
+
 %{
 /*  Copyright (c) 1990 The Regents of the University of California. */
 /*  All rights reserved. */
@@ -32,7 +38,6 @@
 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
 /*  PURPOSE. */
 
-#include "flexdef.h"
 #include "parse.h"
 extern bool tablesverify, tablesext;
 extern int trlcontxt; /* Set in  parse.y for each rule. */