threads / patch / 52363

patchgrep: don't return an expression from pcre2_free()

Subject: [PATCH 0/1] grep: don't return an expression from pcre2_free()

## tl;dr

2 messages between Nov 27, 2019 and Nov 27, 2019. Diffs are folded; open one to read it.

replies: 1people: 1as markdown or json

Hans Jerry Illikainen· Nov 27, 2019, 20:24 UTC · lore

This is a simple one-line fix for a bug I ran into when enabling pedantic builds with DEVELOPER=1 and --with-libpcre. Previously, the void function pcre2_free() returned an expression. This commit changes that as per section 6.8.6.4 in C99 [1] and C11 [2]:

> A return statement with an expression shall not appear in a function
> whose return type is void.

[1] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf [2] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf

Hans Jerry Illikainen (1):
  grep: don't return an expression from pcre2_free()
 grep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 2.24.0.156.g00c62833a5

Hans Jerry Illikainen· Nov 27, 2019, 20:24 UTC · re: Hans Jerry Illikainen · lore

[PATCH 1/1] grep: don't return an expression from pcre2_free()

Previously, the void pcre2_free() function in grep.c returned free(). While free() itself is void, afaict it's still an expression as per section A.2.3, subsection 6.8.6 (jump-statement) in both C99 [1] and C11 [2]:

> return expression
Section 6.8.6.4 in C99 [1] and C11 [2] says that:
> A return statement with an expression shall not appear in a function
> whose return type is void.

The consequence of the old behavior was that developer builds with pedantic errors enabled broke Git if PCRE2 was enabled and a smart-enough compiler to detect these errors was used. This commit fixes pedantic builds of Git that enables --with-libpcre.

[1] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf [2] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf

Signed-off-by: Hans Jerry Illikainen <hji@dyntopia.com>
---
 grep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to grep.c +1 −1
diff --git a/grep.c b/grep.c
index b7ae5a442a..0552b127c1 100644
--- a/grep.c
+++ b/grep.c
@@ -26,7 +26,7 @@ static void *pcre2_malloc(PCRE2_SIZE size, MAYBE_UNUSED void *memory_data)
 
 static void pcre2_free(void *pointer, MAYBE_UNUSED void *memory_data)
 {
-	return free(pointer);
+	free(pointer);
 }
 #endif
 
-- 
2.24.0.156.g00c62833a5

← back to recent threads