Commit
88d06b1c911e8491029ef24e96e3f412ce24c2ae
pathspec: match and original in pathspec_item are const
No existing code modifies these two strings in pathspec elements after they are created via these two pointers. Declare them as "const char *" to stress on this fact and cast away constness from the code that frees these two strings. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano <gitster@pobox.com> · 2026-09-03 18:13 UTC
2 files changed,
+4
−4
modified pathspec.c
| @@ -749,8 +749,8 @@ void clear_pathspec(struct pathspec *pathspec) | |||
| 749 | 749 | int i, j; | |
| 750 | 750 | ||
| 751 | 751 | for (i = 0; i < pathspec->nr; i++) { | |
| 752 | - | free(pathspec->items[i].match); | |
| 753 | - | free(pathspec->items[i].original); | |
| 752 | + | free((void *)pathspec->items[i].match); | |
| 753 | + | free((void *)pathspec->items[i].original); | |
| 754 | 754 | ||
| 755 | 755 | for (j = 0; j < pathspec->items[i].attr_match_nr; j++) | |
| 756 | 756 | free(pathspec->items[i].attr_match[j].value); | |
modified pathspec.h
| @@ -35,8 +35,8 @@ struct pathspec { | |||
| 35 | 35 | unsigned magic; | |
| 36 | 36 | int max_depth; | |
| 37 | 37 | struct pathspec_item { | |
| 38 | - | char *match; | |
| 39 | - | char *original; | |
| 38 | + | const char *match; | |
| 39 | + | const char *original; | |
| 40 | 40 | unsigned magic; | |
| 41 | 41 | int len, prefix; | |
| 42 | 42 | int nowildcard_len; | |