[File] [PATCH] Fix build with gcc 4.8

Xi Ruoyao xry111 at xry111.site
Thu Mar 2 04:21:28 UTC 2023


Fix the following build failure with gcc 4.8:

../../src/funcs.c: In function 'check_regex':
../../src/funcs.c:665:2: error: 'for' loop initial declarations are only allowed in C99 mode
  for (const char *p = pat; *p; p++) {
  ^
../../src/funcs.c:665:2: note: use option -std=c99 or -std=gnu99 to compile your code

Fixes: https://bugs.astron.com/view.php?id=429
Signed-off-by: Xi Ruoyao <xry111 at xry111.site>
---
 src/funcs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/funcs.c b/src/funcs.c
index e265de8c..792310bb 100644
--- a/src/funcs.c
+++ b/src/funcs.c
@@ -661,8 +661,9 @@ check_regex(struct magic_set *ms, const char *pat)
 {
 	char sbuf[512];
 	unsigned char oc = '\0';
+	const char *p;
 
-	for (const char *p = pat; *p; p++) {
+	for (p = pat; *p; p++) {
 		unsigned char c = *p;
 		// Avoid repetition
 		if (c == oc && strchr("?*+{", c) != NULL) {
-- 
2.39.2



More information about the File mailing list