]> git.ipfire.org Git - thirdparty/git.git/commitdiff
diff: cast string constant in `fill_textconv()`
authorPatrick Steinhardt <ps@pks.im>
Fri, 7 Jun 2024 06:38:06 +0000 (08:38 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 Jun 2024 17:30:50 +0000 (10:30 -0700)
The `fill_textconv()` function is responsible for converting an input
file with a textconv driver, which is then passed to the caller. Weirdly
though, the function also handles the case where there is no textconv
driver at all. In that case, it will return either the contents of the
populated filespec, or an empty string if the filespec is invalid.

These two cases have differing memory ownership semantics. When there is
a textconv driver, then the result is an allocated string. Otherwise,
the result is either a string constant or owned by the filespec struct.
All callers are in fact aware of this weirdness and only end up freeing
the output buffer when they had a textconv driver.

Ideally, we'd split up this interface to only perform the conversion via
the textconv driver, and BUG in case the caller didn't provide one. This
would make memory ownership semantics much more straight forward. For
now though, let's simply cast the empty string constant to `char *` to
avoid a warning with `-Wwrite-strings`. This is equivalent to the same
cast that we already have in `fill_mmfile()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff.c

diff --git a/diff.c b/diff.c
index ffd867ef6ca2e50f11e899b22fcba313889c67a5..cecda216cfaf0a16b707d09e4081e0a0d773bf43 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -7235,7 +7235,7 @@ size_t fill_textconv(struct repository *r,
 
        if (!driver) {
                if (!DIFF_FILE_VALID(df)) {
-                       *outbuf = "";
+                       *outbuf = (char *) "";
                        return 0;
                }
                if (diff_populate_filespec(r, df, NULL))