Skip to content

Commit 7986451

Browse files
committed
Merge branch 'ps/no-writable-strings' into jk/imap-send-plug-all-msgs-leak
* ps/no-writable-strings: (46 commits) config.mak.dev: enable `-Wwrite-strings` warning builtin/merge: always store allocated strings in `pull_twohead` builtin/rebase: always store allocated string in `options.strategy` builtin/rebase: do not assign default backend to non-constant field imap-send: fix leaking memory in `imap_server_conf` imap-send: drop global `imap_server_conf` variable mailmap: always store allocated strings in mailmap blob revision: always store allocated strings in output encoding remote-curl: avoid assigning string constant to non-const variable send-pack: always allocate receive status parse-options: cast long name for OPTION_ALIAS http: do not assign string constant to non-const field compat/win32: fix const-correctness with string constants pretty: add casts for decoration option pointers object-file: make `buf` parameter of `index_mem()` a constant object-file: mark cached object buffers as const ident: add casts for fallback name and GECOS entry: refactor how we remove items for delayed checkouts line-log: always allocate the output prefix line-log: stop assigning string constant to file parent buffer ...
2 parents 6c5be97 + d66fe07 commit 7986451

File tree

149 files changed

+1564
-935
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+1564
-935
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,7 @@ UNIT_TEST_PROGRAMS += t-ctype
13381338
UNIT_TEST_PROGRAMS += t-mem-pool
13391339
UNIT_TEST_PROGRAMS += t-prio-queue
13401340
UNIT_TEST_PROGRAMS += t-strbuf
1341+
UNIT_TEST_PROGRAMS += t-strvec
13411342
UNIT_TEST_PROGRAMS += t-trailer
13421343
UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS))
13431344
UNIT_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(UNIT_TEST_PROGRAMS))

alias.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ static int config_alias_cb(const char *key, const char *value,
2121
return 0;
2222

2323
if (data->alias) {
24-
if (!strcasecmp(p, data->alias))
25-
return git_config_string((const char **)&data->v,
24+
if (!strcasecmp(p, data->alias)) {
25+
FREE_AND_NULL(data->v);
26+
return git_config_string(&data->v,
2627
key, value);
28+
}
2729
} else if (data->list) {
2830
string_list_append(data->list, p);
2931
}

attr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "tree-walk.h"
2626
#include "object-name.h"
2727

28-
const char *git_attr_tree;
28+
char *git_attr_tree;
2929

3030
const char git_attr__true[] = "(builtin)true";
3131
const char git_attr__false[] = "\0(builtin)false";

attr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,6 @@ const char *git_attr_global_file(void);
236236
/* Return whether the system gitattributes file is enabled and should be used. */
237237
int git_attr_system_is_enabled(void);
238238

239-
extern const char *git_attr_tree;
239+
extern char *git_attr_tree;
240240

241241
#endif /* ATTR_H */

builtin/bisect.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ static int bisect_reset(const char *commit)
262262
return bisect_clean_state();
263263
}
264264

265-
static void log_commit(FILE *fp, char *fmt, const char *state,
265+
static void log_commit(FILE *fp,
266+
const char *fmt, const char *state,
266267
struct commit *commit)
267268
{
268269
struct pretty_print_context pp = {0};

builtin/blame.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static void get_ac_line(const char *inbuf, const char *what,
134134
{
135135
struct ident_split ident;
136136
size_t len, maillen, namelen;
137-
char *tmp, *endp;
137+
const char *tmp, *endp;
138138
const char *namebuf, *mailbuf;
139139

140140
tmp = strstr(inbuf, what);
@@ -718,7 +718,7 @@ static int git_blame_config(const char *var, const char *value,
718718
return 0;
719719
}
720720
if (!strcmp(var, "blame.ignorerevsfile")) {
721-
const char *str;
721+
char *str;
722722
int ret;
723723

724724
ret = git_config_pathname(&str, var, value);

builtin/bugreport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix)
107107
struct tm tm;
108108
enum diagnose_mode diagnose = DIAGNOSE_NONE;
109109
char *option_output = NULL;
110-
char *option_suffix = "%Y-%m-%d-%H%M";
110+
const char *option_suffix = "%Y-%m-%d-%H%M";
111111
const char *user_relative_path = NULL;
112112
char *prefixed_filename;
113113
size_t output_path_len;

builtin/check-ignore.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ static const struct option check_ignore_options[] = {
3535

3636
static void output_pattern(const char *path, struct path_pattern *pattern)
3737
{
38-
char *bang = (pattern && pattern->flags & PATTERN_FLAG_NEGATIVE) ? "!" : "";
39-
char *slash = (pattern && pattern->flags & PATTERN_FLAG_MUSTBEDIR) ? "/" : "";
38+
const char *bang = (pattern && pattern->flags & PATTERN_FLAG_NEGATIVE) ? "!" : "";
39+
const char *slash = (pattern && pattern->flags & PATTERN_FLAG_MUSTBEDIR) ? "/" : "";
4040
if (!nul_term_line) {
4141
if (!verbose) {
4242
write_name_quoted(path, stdout, '\n');

builtin/checkout.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,12 +1275,12 @@ static void setup_new_branch_info_and_source_tree(
12751275
}
12761276
}
12771277

1278-
static const char *parse_remote_branch(const char *arg,
1279-
struct object_id *rev,
1280-
int could_be_checkout_paths)
1278+
static char *parse_remote_branch(const char *arg,
1279+
struct object_id *rev,
1280+
int could_be_checkout_paths)
12811281
{
12821282
int num_matches = 0;
1283-
const char *remote = unique_tracking_name(arg, rev, &num_matches);
1283+
char *remote = unique_tracking_name(arg, rev, &num_matches);
12841284

12851285
if (remote && could_be_checkout_paths) {
12861286
die(_("'%s' could be both a local file and a tracking branch.\n"
@@ -1316,6 +1316,7 @@ static int parse_branchname_arg(int argc, const char **argv,
13161316
const char **new_branch = &opts->new_branch;
13171317
int argcount = 0;
13181318
const char *arg;
1319+
char *remote = NULL;
13191320
int dash_dash_pos;
13201321
int has_dash_dash = 0;
13211322
int i;
@@ -1416,8 +1417,8 @@ static int parse_branchname_arg(int argc, const char **argv,
14161417
recover_with_dwim = 0;
14171418

14181419
if (recover_with_dwim) {
1419-
const char *remote = parse_remote_branch(arg, rev,
1420-
could_be_checkout_paths);
1420+
remote = parse_remote_branch(arg, rev,
1421+
could_be_checkout_paths);
14211422
if (remote) {
14221423
*new_branch = arg;
14231424
arg = remote;
@@ -1459,6 +1460,7 @@ static int parse_branchname_arg(int argc, const char **argv,
14591460
argc--;
14601461
}
14611462

1463+
free(remote);
14621464
return argcount;
14631465
}
14641466

builtin/clone.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static char *option_branch = NULL;
7171
static struct string_list option_not = STRING_LIST_INIT_NODUP;
7272
static const char *real_git_dir;
7373
static const char *ref_format;
74-
static char *option_upload_pack = "git-upload-pack";
74+
static const char *option_upload_pack = "git-upload-pack";
7575
static int option_verbosity;
7676
static int option_progress = -1;
7777
static int option_sparse_checkout;
@@ -177,8 +177,8 @@ static struct option builtin_clone_options[] = {
177177

178178
static const char *get_repo_path_1(struct strbuf *path, int *is_bundle)
179179
{
180-
static char *suffix[] = { "/.git", "", ".git/.git", ".git" };
181-
static char *bundle_suffix[] = { ".bundle", "" };
180+
static const char *suffix[] = { "/.git", "", ".git/.git", ".git" };
181+
static const char *bundle_suffix[] = { ".bundle", "" };
182182
size_t baselen = path->len;
183183
struct stat st;
184184
int i;
@@ -523,6 +523,9 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
523523
struct ref *head = copy_ref(find_ref_by_name(refs, "HEAD"));
524524
struct ref *local_refs = head;
525525
struct ref **tail = head ? &head->next : &local_refs;
526+
struct refspec_item tag_refspec;
527+
528+
refspec_item_init(&tag_refspec, TAG_REFSPEC, 0);
526529

527530
if (option_single_branch) {
528531
struct ref *remote_head = NULL;
@@ -545,7 +548,7 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
545548
&tail, 0);
546549

547550
/* if --branch=tag, pull the requested tag explicitly */
548-
get_fetch_map(remote_head, tag_refspec, &tail, 0);
551+
get_fetch_map(remote_head, &tag_refspec, &tail, 0);
549552
}
550553
free_refs(remote_head);
551554
} else {
@@ -555,8 +558,9 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
555558
}
556559

557560
if (!option_mirror && !option_single_branch && !option_no_tags)
558-
get_fetch_map(refs, tag_refspec, &tail, 0);
561+
get_fetch_map(refs, &tag_refspec, &tail, 0);
559562

563+
refspec_item_clear(&tag_refspec);
560564
return local_refs;
561565
}
562566

0 commit comments

Comments
 (0)