commit 0c6f49baf2b43adf1cd027050d27fc32ef8454da from: Omar Polo via: Thomas Adam date: Fri Jul 01 21:13:24 2022 UTC build with -Wwrite-strings Throwing this into the mix for a while, we can always get rid of it again if it becomes annoying. No objections from stsp@ commit - 68036464ea72a92fd21d72135814faed6abad71a commit + 0c6f49baf2b43adf1cd027050d27fc32ef8454da blob - ef99224d337170364b2e5458bf6e2a3206c3e05a blob + 2b72df1a3c9e149cff31460ae7090698a3416a61 --- Makefile.inc +++ Makefile.inc @@ -11,7 +11,7 @@ LIBEXECDIR ?= ${PREFIX}/libexec MANDIR ?= ${PREFIX}/man/man .else CFLAGS += -Werror -Wall -Wstrict-prototypes -Wmissing-prototypes -CFLAGS += -Wunused-variable +CFLAGS += -Wwrite-strings -Wunused-variable PREFIX ?= ${HOME} BINDIR ?= ${PREFIX}/bin LIBEXECDIR ?= ${BINDIR} blob - de5b3ba2ac5ecbd777d97ec3af715442065f7284 blob + 82a511cd01114ad856ae35699580cea0aad840cc --- gotweb/gotweb.c +++ gotweb/gotweb.c @@ -236,7 +236,7 @@ struct gw_query_action { unsigned int func_id; const char *func_name; const struct got_error *(*func_main)(struct gw_trans *); - char *template; + const char *template; }; enum gw_query_actions { @@ -2715,11 +2715,11 @@ gw_get_time_str(char **repo_age, time_t committer_time { struct tm tm; time_t diff_time; - char *years = "years ago", *months = "months ago"; - char *weeks = "weeks ago", *days = "days ago", *hours = "hours ago"; - char *minutes = "minutes ago", *seconds = "seconds ago"; - char *now = "right now"; - char *s; + const char *years = "years ago", *months = "months ago"; + const char *weeks = "weeks ago", *days = "days ago", *hours = "hours ago"; + const char *minutes = "minutes ago", *seconds = "seconds ago"; + const char *now = "right now"; + const char *s; char datebuf[29]; *repo_age = NULL; @@ -4762,7 +4762,7 @@ static const struct got_error * gw_colordiff_line(struct gw_trans *gw_trans, char *buf) { const struct got_error *error = NULL; - char *color = NULL; + const char *color = NULL; enum kcgi_err kerr = KCGI_OK; if (strncmp(buf, "-", 1) == 0) blob - 5dbe18b856a53a58bee722d773249a93e91993a8 blob + 4f537113e196997bfae7b568a9d90ab8fe9e77b0 --- include/got_diff.h +++ include/got_diff.h @@ -166,7 +166,7 @@ const struct got_error *got_diff_objects_as_blobs(off_ */ const struct got_error *got_diff_objects_as_trees(off_t **, size_t *, FILE *, FILE *, struct got_object_id *, struct got_object_id *, - struct got_pathlist_head *, char *, char *, int, int, int, + struct got_pathlist_head *, const char *, const char *, int, int, int, struct got_repository *, FILE *); /* blob - a4c18d064bd644c6fd5c1a0b49fb88bcdb340def blob + 73d6e90e84e9a1c3190d740b2a5f86409b553e8f --- lib/dial.c +++ lib/dial.c @@ -68,7 +68,7 @@ got_dial_apply_unveil(const char *proto) } static int -hassuffix(char *base, char *suf) +hassuffix(const char *base, const char *suf) { int nb, ns; @@ -208,7 +208,7 @@ got_dial_ssh(pid_t *newpid, int *newfd, const char *ho const struct got_error *error = NULL; int pid, pfd[2]; char cmd[64]; - char *argv[11]; + const char *argv[11]; int i = 0, j; *newpid = -1; @@ -253,7 +253,7 @@ got_dial_ssh(pid_t *newpid, int *newfd, const char *ho n = snprintf(cmd, sizeof(cmd), "git-%s-pack", direction); if (n < 0 || n >= ssizeof(cmd)) err(1, "snprintf"); - if (execv(GOT_DIAL_PATH_SSH, argv) == -1) + if (execv(GOT_DIAL_PATH_SSH, (char *const *)argv) == -1) err(1, "execv"); abort(); /* not reached */ } else { blob - 4325a3c18009b1a5e03a0b8dae4202531c186761 blob + fea8300f838a573db96d58e41398f9efda236a06 --- lib/diff.c +++ lib/diff.c @@ -62,7 +62,7 @@ diff_blobs(off_t **line_offsets, size_t *nlines, const struct got_error *err = NULL, *free_err; char hex1[SHA1_DIGEST_STRING_LENGTH]; char hex2[SHA1_DIGEST_STRING_LENGTH]; - char *idstr1 = NULL, *idstr2 = NULL; + const char *idstr1 = NULL, *idstr2 = NULL; off_t size1, size2; struct got_diffreg_result *result; off_t outoff = 0; @@ -220,7 +220,7 @@ diff_blob_file(struct got_diffreg_result **resultp, { const struct got_error *err = NULL, *free_err; char hex1[SHA1_DIGEST_STRING_LENGTH]; - char *idstr1 = NULL; + const char *idstr1 = NULL; struct got_diffreg_result *result = NULL; if (resultp) @@ -904,9 +904,9 @@ show_object_id(off_t **line_offsets, size_t *nlines, c static const struct got_error * diff_objects_as_trees(off_t **line_offsets, size_t *nlines, FILE *f1, FILE *f2, struct got_object_id *id1, struct got_object_id *id2, - struct got_pathlist_head *paths, - char *label1, char *label2, int diff_context, int ignore_whitespace, - int force_text_diff, struct got_repository *repo, FILE *outfile) + struct got_pathlist_head *paths, const char *label1, const char *label2, + int diff_context, int ignore_whitespace, int force_text_diff, + struct got_repository *repo, FILE *outfile) { const struct got_error *err; struct got_tree_object *tree1 = NULL, *tree2 = NULL; @@ -960,9 +960,9 @@ done: const struct got_error * got_diff_objects_as_trees(off_t **line_offsets, size_t *nlines, FILE *f1, FILE *f2, struct got_object_id *id1, struct got_object_id *id2, - struct got_pathlist_head *paths, - char *label1, char *label2, int diff_context, int ignore_whitespace, - int force_text_diff, struct got_repository *repo, FILE *outfile) + struct got_pathlist_head *paths, const char *label1, const char *label2, + int diff_context, int ignore_whitespace, int force_text_diff, + struct got_repository *repo, FILE *outfile) { const struct got_error *err; char *idstr = NULL; blob - 70383527274d9e8c501d2480b0479657ced378b7 blob + e44ac0a4e3f7fe9caf5b350a89c7e5c5beba00be --- lib/diff_output.c +++ lib/diff_output.c @@ -262,7 +262,7 @@ diff_output_match_function_prototype(char *prototype, struct diff_atom *start_atom, *atom; const struct diff_data *data; unsigned char buf[DIFF_FUNCTION_CONTEXT_SIZE]; - char *state = NULL; + const char *state = NULL; int rc, i, ch; if (result->left->atoms.len > 0 && cc->left.start > 0) { blob - 207a6edd8617d1afeb8e3b428a73d56ebf40f146 blob + 497731a807222354a7f51153b7938cd3af00b638 --- lib/pack_create.c +++ lib/pack_create.c @@ -1828,7 +1828,7 @@ done: } static const struct got_error * -hwrite(FILE *f, void *buf, off_t len, SHA1_CTX *ctx) +hwrite(FILE *f, const void *buf, off_t len, SHA1_CTX *ctx) { size_t n; blob - eee49ec5ceec50d6d9ca6892a0641f9ae82608ff blob + 91e2238d72a1db8caed92af293dbe6909e84d4eb --- lib/path.c +++ lib/path.c @@ -459,10 +459,11 @@ const struct got_error * got_path_find_prog(char **filename, const char *prog) { const struct got_error *err = NULL; + const char *path; char *p; int len; struct stat sbuf; - char *path, *pathcpy; + char *pathcpy, *dup = NULL; *filename = NULL; @@ -481,19 +482,22 @@ got_path_find_prog(char **filename, const char *prog) return NULL; } - if ((path = strdup(path)) == NULL) + if ((dup = strdup(path)) == NULL) return got_error_from_errno("strdup"); - pathcpy = path; + pathcpy = dup; while ((p = strsep(&pathcpy, ":")) != NULL) { - if (*p == '\0') - p = "."; + const char *d; len = strlen(p); while (len > 0 && p[len-1] == '/') p[--len] = '\0'; /* strip trailing '/' */ - if (asprintf(filename, "%s/%s", p, prog) == -1) { + d = p; + if (*d == '\0') + d = "."; + + if (asprintf(filename, "%s/%s", d, prog) == -1) { err = got_error_from_errno("asprintf"); break; } @@ -504,7 +508,7 @@ got_path_find_prog(char **filename, const char *prog) *filename = NULL; continue; } - free(path); + free(dup); return err; } blob - fac056e27fdaad60303e17cfd5dcd95ca749eab2 blob + 01e0b4c5dacf2ce7ab96d2acbe62a77fc849d931 --- lib/reference.c +++ lib/reference.c @@ -997,8 +997,8 @@ got_ref_list(struct got_reflist_head *refs, struct got { const struct got_error *err; char *packed_refs_path, *path_refs = NULL; - char *abs_namespace = NULL; - char *buf = NULL, *ondisk_ref_namespace = NULL; + char *abs_namespace = NULL, *buf = NULL; + const char *ondisk_ref_namespace = NULL; char *line = NULL; FILE *f = NULL; struct got_reference *ref; blob - d67081715f628dd92add8cfb5bb5cf950f5dcf87 blob + 60e2434696a95fcabec91967fcd34c362ae30aad --- regress/fetch/fetch_test.c +++ regress/fetch/fetch_test.c @@ -44,7 +44,7 @@ static int verbose; static int quiet; static void -test_printf(char *fmt, ...) +test_printf(const char *fmt, ...) { va_list ap; blob - f1e809c24d6f539ddb632ad6655346337a07215d blob + 3381d631df8b38fed1f956c7c9292b22021abddb --- regress/path/path_test.c +++ regress/path/path_test.c @@ -33,7 +33,7 @@ static int verbose; static int quiet; static void -test_printf(char *fmt, ...) +test_printf(const char *fmt, ...) { va_list ap;