]> git.ipfire.org Git - thirdparty/git.git/commitdiff
global: improve const correctness when assigning string constants
authorPatrick Steinhardt <ps@pks.im>
Fri, 7 Jun 2024 06:37:39 +0000 (08:37 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 Jun 2024 17:30:48 +0000 (10:30 -0700)
We're about to enable `-Wwrite-strings`, which changes the type of
string constants to `const char[]`. Fix various sites where we assign
such constants to non-const variables.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
38 files changed:
builtin/bisect.c
builtin/blame.c
builtin/bugreport.c
builtin/check-ignore.c
builtin/clone.c
builtin/commit.c
builtin/diagnose.c
builtin/log.c
builtin/mailsplit.c
builtin/pull.c
builtin/receive-pack.c
builtin/revert.c
compat/regex/regcomp.c
diff.c
diffcore-rename.c
fmt-merge-msg.c
fsck.c
fsck.h
gpg-interface.c
http-backend.c
imap-send.c
pretty.c
refs.c
refs.h
reftable/basics.c
reftable/basics.h
reftable/basics_test.c
reftable/record.c
reftable/stack.c
reftable/stack_test.c
run-command.c
t/helper/test-hashmap.c
t/helper/test-json-writer.c
t/helper/test-regex.c
t/helper/test-rot13-filter.c
t/unit-tests/t-strbuf.c
trailer.c
wt-status.c

index a58432b9d90293fbbe40073e999317813eda0b49..dabce9b542b1e001daea083b6e2bff4d5cf9d460 100644 (file)
@@ -262,7 +262,8 @@ static int bisect_reset(const char *commit)
        return bisect_clean_state();
 }
 
-static void log_commit(FILE *fp, char *fmt, const char *state,
+static void log_commit(FILE *fp,
+                      const char *fmt, const char *state,
                       struct commit *commit)
 {
        struct pretty_print_context pp = {0};
index 838cd476be091ea8bb908b4a6672bc246b0c455f..98c7629b6a7beb0dce713babfe510a326e1a0814 100644 (file)
@@ -134,7 +134,7 @@ static void get_ac_line(const char *inbuf, const char *what,
 {
        struct ident_split ident;
        size_t len, maillen, namelen;
-       char *tmp, *endp;
+       const char *tmp, *endp;
        const char *namebuf, *mailbuf;
 
        tmp = strstr(inbuf, what);
index 25f860a0d973caca44593cb28919e47afb13089d..b3cc77af53793f49a4d10fe9e3257370ef2ea871 100644 (file)
@@ -107,7 +107,7 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix)
        struct tm tm;
        enum diagnose_mode diagnose = DIAGNOSE_NONE;
        char *option_output = NULL;
-       char *option_suffix = "%Y-%m-%d-%H%M";
+       const char *option_suffix = "%Y-%m-%d-%H%M";
        const char *user_relative_path = NULL;
        char *prefixed_filename;
        size_t output_path_len;
index 6c43430ec4328ab21d96f07ec84719a515c2e135..2bda6a1d46291676533765925720b66ce3463a6f 100644 (file)
@@ -35,8 +35,8 @@ static const struct option check_ignore_options[] = {
 
 static void output_pattern(const char *path, struct path_pattern *pattern)
 {
-       char *bang  = (pattern && pattern->flags & PATTERN_FLAG_NEGATIVE)  ? "!" : "";
-       char *slash = (pattern && pattern->flags & PATTERN_FLAG_MUSTBEDIR) ? "/" : "";
+       const char *bang  = (pattern && pattern->flags & PATTERN_FLAG_NEGATIVE)  ? "!" : "";
+       const char *slash = (pattern && pattern->flags & PATTERN_FLAG_MUSTBEDIR) ? "/" : "";
        if (!nul_term_line) {
                if (!verbose) {
                        write_name_quoted(path, stdout, '\n');
index 23993b905b779671c7828876f918cfd1e04a92e0..92ab7d7165b7e74a78765ffa147bfce72e00159c 100644 (file)
@@ -71,7 +71,7 @@ static char *option_branch = NULL;
 static struct string_list option_not = STRING_LIST_INIT_NODUP;
 static const char *real_git_dir;
 static const char *ref_format;
-static char *option_upload_pack = "git-upload-pack";
+static const char *option_upload_pack = "git-upload-pack";
 static int option_verbosity;
 static int option_progress = -1;
 static int option_sparse_checkout;
@@ -177,8 +177,8 @@ static struct option builtin_clone_options[] = {
 
 static const char *get_repo_path_1(struct strbuf *path, int *is_bundle)
 {
-       static char *suffix[] = { "/.git", "", ".git/.git", ".git" };
-       static char *bundle_suffix[] = { ".bundle", "" };
+       static const char *suffix[] = { "/.git", "", ".git/.git", ".git" };
+       static const char *bundle_suffix[] = { ".bundle", "" };
        size_t baselen = path->len;
        struct stat st;
        int i;
index f53e7e86ff61191266da0fc779e2ed8d24c93abe..75c741173e8012882ea31d88e73c00b093ba3a05 100644 (file)
@@ -113,7 +113,7 @@ static char *template_file;
  * the commit message and/or authorship.
  */
 static const char *author_message, *author_message_buffer;
-static char *edit_message, *use_message;
+static const char *edit_message, *use_message;
 static char *fixup_message, *fixup_commit, *squash_message;
 static const char *fixup_prefix;
 static int all, also, interactive, patch_interactive, only, amend, signoff;
@@ -121,8 +121,8 @@ static int edit_flag = -1; /* unspecified */
 static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
 static int config_commit_verbose = -1; /* unspecified */
 static int no_post_rewrite, allow_empty_message, pathspec_file_nul;
-static char *untracked_files_arg, *force_date, *ignore_submodule_arg, *ignored_arg;
-static char *sign_commit, *pathspec_from_file;
+static const char *untracked_files_arg, *force_date, *ignore_submodule_arg, *ignored_arg;
+static const char *sign_commit, *pathspec_from_file;
 static struct strvec trailer_args = STRVEC_INIT;
 
 /*
index 4f22eb2b55d06968896d12ae9257d470d5d3a8fb..4857a4395ba6dedf39f27e102ab0d04f077366c6 100644 (file)
@@ -18,7 +18,7 @@ int cmd_diagnose(int argc, const char **argv, const char *prefix)
        struct tm tm;
        enum diagnose_mode mode = DIAGNOSE_STATS;
        char *option_output = NULL;
-       char *option_suffix = "%Y-%m-%d-%H%M";
+       const char *option_suffix = "%Y-%m-%d-%H%M";
        char *prefixed_filename;
 
        const struct option diagnose_options[] = {
index 78a247d8a94d077a4bd829b65228afb64e03e6dc..b8846a945829e34c752a86f0b56608652543d985 100644 (file)
@@ -1283,7 +1283,7 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)
        o2->flags = flags2;
 }
 
-static void gen_message_id(struct rev_info *info, char *base)
+static void gen_message_id(struct rev_info *info, const char *base)
 {
        struct strbuf buf = STRBUF_INIT;
        strbuf_addf(&buf, "%s.%"PRItime".git.%s", base,
index 3af9ddb8ae5c7e902937ada927590d908c193e0f..fe6dbc5d0538912cfb3b620d1b337de16d91fd5c 100644 (file)
@@ -113,8 +113,8 @@ static int populate_maildir_list(struct string_list *list, const char *path)
        DIR *dir;
        struct dirent *dent;
        char *name = NULL;
-       char *subs[] = { "cur", "new", NULL };
-       char **sub;
+       const char *subs[] = { "cur", "new", NULL };
+       const char **sub;
        int ret = -1;
 
        for (sub = subs; *sub; ++sub) {
index d622202bcecad62be2eec1f1917733bedccaa525..2d0429f14fe22dfdb55536791c7b2b21f66ab95b 100644 (file)
@@ -71,48 +71,48 @@ static const char * const pull_usage[] = {
 
 /* Shared options */
 static int opt_verbosity;
-static char *opt_progress;
+static const char *opt_progress;
 static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
 static int recurse_submodules_cli = RECURSE_SUBMODULES_DEFAULT;
 
 /* Options passed to git-merge or git-rebase */
 static enum rebase_type opt_rebase = -1;
-static char *opt_diffstat;
-static char *opt_log;
-static char *opt_signoff;
-static char *opt_squash;
-static char *opt_commit;
-static char *opt_edit;
-static char *cleanup_arg;
-static char *opt_ff;
-static char *opt_verify_signatures;
-static char *opt_verify;
+static const char *opt_diffstat;
+static const char *opt_log;
+static const char *opt_signoff;
+static const char *opt_squash;
+static const char *opt_commit;
+static const char *opt_edit;
+static const char *cleanup_arg;
+static const char *opt_ff;
+static const char *opt_verify_signatures;
+static const char *opt_verify;
 static int opt_autostash = -1;
 static int config_autostash;
 static int check_trust_level = 1;
 static struct strvec opt_strategies = STRVEC_INIT;
 static struct strvec opt_strategy_opts = STRVEC_INIT;
-static char *opt_gpg_sign;
+static const char *opt_gpg_sign;
 static int opt_allow_unrelated_histories;
 
 /* Options passed to git-fetch */
-static char *opt_all;
-static char *opt_append;
-static char *opt_upload_pack;
+static const char *opt_all;
+static const char *opt_append;
+static const char *opt_upload_pack;
 static int opt_force;
-static char *opt_tags;
-static char *opt_prune;
-static char *max_children;
+static const char *opt_tags;
+static const char *opt_prune;
+static const char *max_children;
 static int opt_dry_run;
-static char *opt_keep;
-static char *opt_depth;
-static char *opt_unshallow;
-static char *opt_update_shallow;
-static char *opt_refmap;
-static char *opt_ipv4;
-static char *opt_ipv6;
+static const char *opt_keep;
+static const char *opt_depth;
+static const char *opt_unshallow;
+static const char *opt_update_shallow;
+static const char *opt_refmap;
+static const char *opt_ipv4;
+static const char *opt_ipv6;
 static int opt_show_forced_updates = -1;
-static char *set_upstream;
+static const char *set_upstream;
 static struct strvec opt_fetch = STRVEC_INIT;
 
 static struct option pull_options[] = {
index 01c1f04ece386b2441c1a7c9b995050b16d00617..c8d12ee0a7f186194498f55bc58f1b3017797d47 100644 (file)
@@ -1249,7 +1249,7 @@ cleanup:
        return code;
 }
 
-static char *refuse_unconfigured_deny_msg =
+static const char *refuse_unconfigured_deny_msg =
        N_("By default, updating the current branch in a non-bare repository\n"
           "is denied, because it will make the index and work tree inconsistent\n"
           "with what you pushed, and will require 'git reset --hard' to match\n"
@@ -1269,7 +1269,7 @@ static void refuse_unconfigured_deny(void)
        rp_error("%s", _(refuse_unconfigured_deny_msg));
 }
 
-static char *refuse_unconfigured_deny_delete_current_msg =
+static const char *refuse_unconfigured_deny_delete_current_msg =
        N_("By default, deleting the current branch is denied, because the next\n"
           "'git clone' won't result in any file checked out, causing confusion.\n"
           "\n"
index 53935d2c68a1653bbf17399ede26b5586ac46ba0..7bf2b4e11d6149d5d5e9d07cf810d56272447776 100644 (file)
@@ -179,7 +179,7 @@ static int run_sequencer(int argc, const char **argv, const char *prefix,
 
        /* Check for incompatible command line arguments */
        if (cmd) {
-               char *this_operation;
+               const char *this_operation;
                if (cmd == 'q')
                        this_operation = "--quit";
                else if (cmd == 'c')
index 2bc0f1187a18f22b7c0ffc0d58af18e311429615..6c5d455e9263d72e3052f0a4a73c37461d9b3867 100644 (file)
@@ -848,7 +848,7 @@ init_dfa (re_dfa_t *dfa, size_t pat_len)
 {
   unsigned int table_size;
 #ifndef _LIBC
-  char *codeset_name;
+  const char *codeset_name;
 #endif
 
   memset (dfa, '\0', sizeof (re_dfa_t));
diff --git a/diff.c b/diff.c
index e70301df76743ab196d8f046748d4cb1ca0a5434..ffd867ef6ca2e50f11e899b22fcba313889c67a5 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -3764,7 +3764,7 @@ static void builtin_diff(const char *name_a,
        return;
 }
 
-static char *get_compact_summary(const struct diff_filepair *p, int is_renamed)
+static const char *get_compact_summary(const struct diff_filepair *p, int is_renamed)
 {
        if (!is_renamed) {
                if (p->status == DIFF_STATUS_ADDED) {
@@ -4076,7 +4076,7 @@ static int reuse_worktree_file(struct index_state *istate,
 static int diff_populate_gitlink(struct diff_filespec *s, int size_only)
 {
        struct strbuf buf = STRBUF_INIT;
-       char *dirty = "";
+       const char *dirty = "";
 
        /* Are we looking at the work tree? */
        if (s->dirty_submodule)
index 5a6e2bcac7147e487624c1bf53e1572a54b0d93d..0e1adb87df18888508688b725bbc8d31695f998b 100644 (file)
@@ -406,7 +406,7 @@ static const char *get_highest_rename_path(struct strintmap *counts)
        return highest_destination_dir;
 }
 
-static char *UNKNOWN_DIR = "/";  /* placeholder -- short, illegal directory */
+static const char *UNKNOWN_DIR = "/";  /* placeholder -- short, illegal directory */
 
 static int dir_rename_already_determinable(struct strintmap *counts)
 {
@@ -429,8 +429,8 @@ static int dir_rename_already_determinable(struct strintmap *counts)
 }
 
 static void increment_count(struct dir_rename_info *info,
-                           char *old_dir,
-                           char *new_dir)
+                           const char *old_dir,
+                           const char *new_dir)
 {
        struct strintmap *counts;
        struct strmap_entry *e;
index 7d144b803aef0653ff80ed58ab8607713dbc6726..5af63ab5ab9b3a288c80bc67d09d759361a7e74c 100644 (file)
@@ -447,7 +447,7 @@ static void fmt_merge_msg_title(struct strbuf *out,
                                const char *current_branch)
 {
        int i = 0;
-       char *sep = "";
+       const char *sep = "";
 
        strbuf_addstr(out, "Merge ");
        for (i = 0; i < srcs.nr; i++) {
diff --git a/fsck.c b/fsck.c
index 7dff41413eb62f4ca4b2b70a19d5b8d2515d4276..61cd48aa25d43b1951857e9f8c0628b8b32bb91a 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -1231,7 +1231,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
 }
 
 int fsck_buffer(const struct object_id *oid, enum object_type type,
-               void *data, unsigned long size,
+               const void *data, unsigned long size,
                struct fsck_options *options)
 {
        if (type == OBJ_BLOB)
diff --git a/fsck.h b/fsck.h
index 17fa2dda5dee3de5553da16fc9f9d337087701ea..4f0c4e6479c7c491e9ddd126239ac88a9fecfabb 100644 (file)
--- a/fsck.h
+++ b/fsck.h
@@ -202,7 +202,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
  * struct.
  */
 int fsck_buffer(const struct object_id *oid, enum object_type,
-               void *data, unsigned long size,
+               const void *data, unsigned long size,
                struct fsck_options *options);
 
 /*
index 51932237140fdf8932536d50a72d7cb03b32d990..71a9382a611e56516bdba0593ac5a78515a2a299 100644 (file)
@@ -727,7 +727,7 @@ static int git_gpg_config(const char *var, const char *value,
                          void *cb UNUSED)
 {
        struct gpg_format *fmt = NULL;
-       char *fmtname = NULL;
+       const char *fmtname = NULL;
        char *trust;
        int ret;
 
index 5b65287ac90f24e70af6b1cfed08843aa6bbe774..5b4dca65ed25d3c097f5a67975ddbfe48b63c369 100644 (file)
@@ -753,7 +753,7 @@ static int bad_request(struct strbuf *hdr, const struct service_cmd *c)
 
 int cmd_main(int argc UNUSED, const char **argv UNUSED)
 {
-       char *method = getenv("REQUEST_METHOD");
+       const char *method = getenv("REQUEST_METHOD");
        const char *proto_header;
        char *dir;
        struct service_cmd *cmd = NULL;
index a5d15101806c93a8c72830150113bce8ee600680..8b723b34a55d193efdf597c3628dbbae7290e11b 100644 (file)
@@ -1215,9 +1215,9 @@ static int imap_store_msg(struct imap_store *ctx, struct strbuf *msg)
 static void wrap_in_html(struct strbuf *msg)
 {
        struct strbuf buf = STRBUF_INIT;
-       static char *content_type = "Content-Type: text/html;\n";
-       static char *pre_open = "<pre>\n";
-       static char *pre_close = "</pre>\n";
+       static const char *content_type = "Content-Type: text/html;\n";
+       static const char *pre_open = "<pre>\n";
+       static const char *pre_close = "</pre>\n";
        const char *body = strstr(msg->buf, "\n\n");
 
        if (!body)
index 22a81506b7a42c8dbb98f5c4b46d75a5366073f8..ec05db5655b165ab7a394724cc938e68ed98b27d 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -1325,7 +1325,7 @@ int format_set_trailers_options(struct process_trailer_options *opts,
 static size_t parse_describe_args(const char *start, struct strvec *args)
 {
        struct {
-               char *name;
+               const char *name;
                enum {
                        DESCRIBE_ARG_BOOL,
                        DESCRIBE_ARG_INTEGER,
diff --git a/refs.c b/refs.c
index 8260c27cde294ec2fdce69b6f4b5367eb5c53df4..292e8d947e3028039545ce2b637313390c4dca18 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -159,7 +159,7 @@ void update_ref_namespace(enum ref_namespace namespace, char *ref)
 {
        struct ref_namespace_info *info = &ref_namespace[namespace];
        if (info->ref_updated)
-               free(info->ref);
+               free((char *)info->ref);
        info->ref = ref;
        info->ref_updated = 1;
 }
diff --git a/refs.h b/refs.h
index 34568ee1fbb83b80bec1c54f8a062fdb47f86532..923f751d18b4d48947a45e99c910ac56633bad57 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -975,7 +975,7 @@ struct ref_store *get_worktree_ref_store(const struct worktree *wt);
  */
 
 struct ref_namespace_info {
-       char *ref;
+       const char *ref;
        enum decoration_type decoration;
 
        /*
index fea711db7e23e680fbf1937df43d625bb9c055fb..0058619ca6742ae29b4f50d7188b0fc19d87f45b 100644 (file)
@@ -67,9 +67,9 @@ void free_names(char **a)
        reftable_free(a);
 }
 
-size_t names_length(char **names)
+size_t names_length(const char **names)
 {
-       char **p = names;
+       const char **p = names;
        while (*p)
                p++;
        return p - names;
@@ -102,15 +102,12 @@ void parse_names(char *buf, int size, char ***namesp)
        *namesp = names;
 }
 
-int names_equal(char **a, char **b)
+int names_equal(const char **a, const char **b)
 {
-       int i = 0;
-       for (; a[i] && b[i]; i++) {
-               if (strcmp(a[i], b[i])) {
+       size_t i = 0;
+       for (; a[i] && b[i]; i++)
+               if (strcmp(a[i], b[i]))
                        return 0;
-               }
-       }
-
        return a[i] == b[i];
 }
 
index 523ecd530762f6e4cde48edfa3761b3139b21b92..c8fec68d4e887e24b793cac656e2f34d0c93635f 100644 (file)
@@ -42,10 +42,10 @@ void free_names(char **a);
 void parse_names(char *buf, int size, char ***namesp);
 
 /* compares two NULL-terminated arrays of strings. */
-int names_equal(char **a, char **b);
+int names_equal(const char **a, const char **b);
 
 /* returns the array size of a NULL-terminated array of strings. */
-size_t names_length(char **names);
+size_t names_length(const char **names);
 
 /* Allocation routines; they invoke the functions set through
  * reftable_set_alloc() */
index 997c4d9e0113ba52fcaaaa423aabe08c511322af..13bc761817ccd9518598d12dd6042480b2469b18 100644 (file)
@@ -58,8 +58,8 @@ static void test_binsearch(void)
 
 static void test_names_length(void)
 {
-       char *a[] = { "a", "b", NULL };
-       EXPECT(names_length(a) == 2);
+       const char *names[] = { "a", "b", NULL };
+       EXPECT(names_length(names) == 2);
 }
 
 static void test_parse_names_normal(void)
index 5506f3e913860eb2b76c5db2e9f48cede4965bf3..a2cba5ef7470f9980b914bc41ed6b7063ec4a4d5 100644 (file)
@@ -116,7 +116,7 @@ static int decode_string(struct strbuf *dest, struct string_view in)
        return start_len - in.len;
 }
 
-static int encode_string(char *str, struct string_view s)
+static int encode_string(const char *str, struct string_view s)
 {
        struct string_view start = s;
        int l = strlen(str);
@@ -969,9 +969,9 @@ done:
        return REFTABLE_FORMAT_ERROR;
 }
 
-static int null_streq(char *a, char *b)
+static int null_streq(const char *a, const char *b)
 {
-       char *empty = "";
+       const char *empty = "";
        if (!a)
                a = empty;
 
index a59ebe038d01d215ca0a5a4e9b6d737a6dca344e..09549c51c9f5f91026302897c4a7352190130b11 100644 (file)
@@ -204,7 +204,8 @@ static struct reftable_reader **stack_copy_readers(struct reftable_stack *st,
        return cur;
 }
 
-static int reftable_stack_reload_once(struct reftable_stack *st, char **names,
+static int reftable_stack_reload_once(struct reftable_stack *st,
+                                     const char **names,
                                      int reuse_open)
 {
        size_t cur_len = !st->merged ? 0 : st->merged->stack_len;
@@ -222,7 +223,7 @@ static int reftable_stack_reload_once(struct reftable_stack *st, char **names,
 
        while (*names) {
                struct reftable_reader *rd = NULL;
-               char *name = *names++;
+               const char *name = *names++;
 
                /* this is linear; we assume compaction keeps the number of
                   tables under control so this is not quadratic. */
@@ -354,7 +355,7 @@ static int reftable_stack_reload_maybe_reuse(struct reftable_stack *st,
                                goto out;
                }
 
-               err = reftable_stack_reload_once(st, names, reuse_open);
+               err = reftable_stack_reload_once(st, (const char **) names, reuse_open);
                if (!err)
                        break;
                if (err != REFTABLE_NOT_EXIST_ERROR)
@@ -368,7 +369,8 @@ static int reftable_stack_reload_maybe_reuse(struct reftable_stack *st,
                err = read_lines(st->list_file, &names_after);
                if (err < 0)
                        goto out;
-               if (names_equal(names_after, names)) {
+               if (names_equal((const char **) names_after,
+                               (const char **) names)) {
                        err = REFTABLE_NOT_EXIST_ERROR;
                        goto out;
                }
index 7889f818d16ebb96a169bf2b95f4b2dbd071b75a..07d89b45dac770357d0d231304a0c924a33c4323 100644 (file)
@@ -83,7 +83,7 @@ static void test_read_file(void)
        char out[1024] = "line1\n\nline2\nline3";
        int n, err;
        char **names = NULL;
-       char *want[] = { "line1", "line2", "line3" };
+       const char *want[] = { "line1", "line2", "line3" };
        int i = 0;
 
        EXPECT(fd > 0);
@@ -116,9 +116,9 @@ static void test_parse_names(void)
 
 static void test_names_equal(void)
 {
-       char *a[] = { "a", "b", "c", NULL };
-       char *b[] = { "a", "b", "d", NULL };
-       char *c[] = { "a", "b", NULL };
+       const char *a[] = { "a", "b", "c", NULL };
+       const char *b[] = { "a", "b", "d", NULL };
+       const char *c[] = { "a", "b", NULL };
 
        EXPECT(names_equal(a, a));
        EXPECT(!names_equal(a, b));
index 1b821042b4e0671f0088177881a45e257d0a9297..7600531fb676a36e45b35afe7602cccf94723a84 100644 (file)
@@ -663,7 +663,7 @@ int start_command(struct child_process *cmd)
        int need_in, need_out, need_err;
        int fdin[2], fdout[2], fderr[2];
        int failed_errno;
-       char *str;
+       const char *str;
 
        /*
         * In case of errors we must keep the promise to close FDs
index 0eb0b3d49cecc57ae08a4760065eb7b530a5f191..2912899558eafa595b7d644293d8e7b660993789 100644 (file)
@@ -36,7 +36,8 @@ static int test_entry_cmp(const void *cmp_data,
 }
 
 static struct test_entry *alloc_test_entry(unsigned int hash,
-                                          char *key, char *value)
+                                          const char *key,
+                                          const char *value)
 {
        size_t klen = strlen(key);
        size_t vlen = strlen(value);
index afe393f5974131b390f2eca932960cbd962f0b6d..ed52eb76bfcbb2830080e40c25a6d59bf7d336da 100644 (file)
@@ -174,7 +174,7 @@ static void make_arr4(int pretty)
        jw_end(&arr4);
 }
 
-static char *expect_nest1 =
+static const char *expect_nest1 =
        "{\"obj1\":{\"a\":\"abc\",\"b\":42,\"c\":true},\"arr1\":[\"abc\",42,true]}";
 
 static struct json_writer nest1 = JSON_WRITER_INIT;
@@ -195,10 +195,10 @@ static void make_nest1(int pretty)
        jw_release(&arr1);
 }
 
-static char *expect_inline1 =
+static const char *expect_inline1 =
        "{\"obj1\":{\"a\":\"abc\",\"b\":42,\"c\":true},\"arr1\":[\"abc\",42,true]}";
 
-static char *pretty_inline1 =
+static const char *pretty_inline1 =
        ("{\n"
         "  \"obj1\": {\n"
         "    \"a\": \"abc\",\n"
@@ -236,10 +236,10 @@ static void make_inline1(int pretty)
        jw_end(&inline1);
 }
 
-static char *expect_inline2 =
+static const char *expect_inline2 =
        "[[1,2],[3,4],{\"a\":\"abc\"}]";
 
-static char *pretty_inline2 =
+static const char *pretty_inline2 =
        ("[\n"
         "  [\n"
         "    1,\n"
index 80042eafc20603e0c84cb83d3ba400cd316010c7..366bd709762627d643897dd8844835b3ccc5d390 100644 (file)
@@ -20,8 +20,8 @@ static struct reg_flag reg_flags[] = {
 
 static int test_regex_bug(void)
 {
-       char *pat = "[^={} \t]+";
-       char *str = "={}\nfred";
+       const char *pat = "[^={} \t]+";
+       const char *str = "={}\nfred";
        regex_t r;
        regmatch_t m[1];
 
index f8d564c622acaa4888384f709ef515384661280f..7e1d9e0ee47303b46693b91032dd2eadb98c80bf 100644 (file)
@@ -136,7 +136,7 @@ static void free_delay_entries(void)
        strmap_clear(&delay, 0);
 }
 
-static void add_delay_entry(char *pathname, int count, int requested)
+static void add_delay_entry(const char *pathname, int count, int requested)
 {
        struct delay_entry *entry = xcalloc(1, sizeof(*entry));
        entry->count = count;
@@ -189,7 +189,8 @@ static void reply_list_available_blobs_cmd(void)
 static void command_loop(void)
 {
        for (;;) {
-               char *buf, *output;
+               char *buf;
+               const char *output;
                char *pathname;
                struct delay_entry *entry;
                struct strbuf input = STRBUF_INIT;
index de434a4441d64f37f19f95038e4935045cc4116a..6027dafef70867b10fb12e395868c4829a9a1082 100644 (file)
@@ -2,7 +2,8 @@
 #include "strbuf.h"
 
 /* wrapper that supplies tests with an empty, initialized strbuf */
-static void setup(void (*f)(struct strbuf*, void*), void *data)
+static void setup(void (*f)(struct strbuf*, const void*),
+                 const void *data)
 {
        struct strbuf buf = STRBUF_INIT;
 
@@ -13,7 +14,8 @@ static void setup(void (*f)(struct strbuf*, void*), void *data)
 }
 
 /* wrapper that supplies tests with a populated, initialized strbuf */
-static void setup_populated(void (*f)(struct strbuf*, void*), char *init_str, void *data)
+static void setup_populated(void (*f)(struct strbuf*, const void*),
+                           const char *init_str, const void *data)
 {
        struct strbuf buf = STRBUF_INIT;
 
@@ -64,7 +66,7 @@ static void t_dynamic_init(void)
        strbuf_release(&buf);
 }
 
-static void t_addch(struct strbuf *buf, void *data)
+static void t_addch(struct strbuf *buf, const void *data)
 {
        const char *p_ch = data;
        const char ch = *p_ch;
@@ -83,7 +85,7 @@ static void t_addch(struct strbuf *buf, void *data)
        check_char(buf->buf[buf->len], ==, '\0');
 }
 
-static void t_addstr(struct strbuf *buf, void *data)
+static void t_addstr(struct strbuf *buf, const void *data)
 {
        const char *text = data;
        size_t len = strlen(text);
index 2bcb9ba8f7b44bb957b129a014821899fe47436d..72e5136c73d194b20d9bf6c0ff17a40b40239a05 100644 (file)
--- a/trailer.c
+++ b/trailer.c
@@ -63,7 +63,7 @@ struct arg_item {
 
 static LIST_HEAD(conf_head);
 
-static char *separators = ":";
+static const char *separators = ":";
 
 static int configured;
 
index ff4be071ca4f8366e4ddf926cf1fc94aea195eca..7912545e4ea9ca111df1e3a6158951efdb99e86f 100644 (file)
@@ -2408,7 +2408,7 @@ static void wt_porcelain_v2_print_unmerged_entry(
                int mode;
                struct object_id oid;
        } stages[3];
-       char *key;
+       const char *key;
        char submodule_token[5];
        char unmerged_prefix = 'u';
        char eol_char = s->null_termination ? '\0' : '\n';