Skip to content

Commit 86badd4

Browse files
pks-tgitster
authored andcommitted
diff: cast string constant in fill_textconv()
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 81654d2 commit 86badd4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7235,7 +7235,7 @@ size_t fill_textconv(struct repository *r,
72357235

72367236
if (!driver) {
72377237
if (!DIFF_FILE_VALID(df)) {
7238-
*outbuf = "";
7238+
*outbuf = (char *) "";
72397239
return 0;
72407240
}
72417241
if (diff_populate_filespec(r, df, NULL))

0 commit comments

Comments
 (0)