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@
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
diff --git a/Makefile.inc b/Makefile.inc
index ef99224..2b72df1 100644
--- a/Makefile.inc
+++ b/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}
diff --git a/gotweb/gotweb.c b/gotweb/gotweb.c
index e1fc7e7..a6bd009 100644
--- a/gotweb/gotweb.c
+++ b/gotweb/gotweb.c
@@ -237,7 +237,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 {
@@ -2716,11 +2716,11 @@ gw_get_time_str(char **repo_age, time_t committer_time, int ref_tm)
{
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;
@@ -4763,7 +4763,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)
diff --git a/include/got_diff.h b/include/got_diff.h
index 5dbe18b..4f53711 100644
--- a/include/got_diff.h
+++ b/include/got_diff.h
@@ -166,7 +166,7 @@ const struct got_error *got_diff_objects_as_blobs(off_t **, size_t *,
*/
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 *);
/*
diff --git a/lib/dial.c b/lib/dial.c
index 4f688a9..b7ce464 100644
--- a/lib/dial.c
+++ b/lib/dial.c
@@ -67,7 +67,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;
@@ -207,7 +207,7 @@ got_dial_ssh(pid_t *newpid, int *newfd, const char *host,
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;
@@ -252,7 +252,7 @@ got_dial_ssh(pid_t *newpid, int *newfd, const char *host,
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 {
diff --git a/lib/diff.c b/lib/diff.c
index 8337d25..773169c 100644
--- a/lib/diff.c
+++ b/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, const char *obj_typestr,
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;
diff --git a/lib/diff_output.c b/lib/diff_output.c
index 7038352..e44ac0a 100644
--- a/lib/diff_output.c
+++ b/lib/diff_output.c
@@ -262,7 +262,7 @@ diff_output_match_function_prototype(char *prototype, size_t prototype_size,
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) {
diff --git a/lib/pack_create.c b/lib/pack_create.c
index 16d1a75..384b6d4 100644
--- a/lib/pack_create.c
+++ b/lib/pack_create.c
@@ -1829,7 +1829,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;
diff --git a/lib/path.c b/lib/path.c
index 19dc9c9..e3d7799 100644
--- a/lib/path.c
+++ b/lib/path.c
@@ -458,10 +458,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;
@@ -480,19 +481,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;
}
@@ -503,7 +507,7 @@ got_path_find_prog(char **filename, const char *prog)
*filename = NULL;
continue;
}
- free(path);
+ free(dup);
return err;
}
diff --git a/lib/reference.c b/lib/reference.c
index 8616b4e..de71b58 100644
--- a/lib/reference.c
+++ b/lib/reference.c
@@ -998,8 +998,8 @@ got_ref_list(struct got_reflist_head *refs, struct got_repository *repo,
{
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;
diff --git a/regress/fetch/fetch_test.c b/regress/fetch/fetch_test.c
index 9d84105..c0e7187 100644
--- a/regress/fetch/fetch_test.c
+++ b/regress/fetch/fetch_test.c
@@ -46,7 +46,7 @@ static int verbose;
static int quiet;
static void
-test_printf(char *fmt, ...)
+test_printf(const char *fmt, ...)
{
va_list ap;
diff --git a/regress/path/path_test.c b/regress/path/path_test.c
index e8001a5..bbf71a7 100644
--- a/regress/path/path_test.c
+++ b/regress/path/path_test.c
@@ -34,7 +34,7 @@ static int verbose;
static int quiet;
static void
-test_printf(char *fmt, ...)
+test_printf(const char *fmt, ...)
{
va_list ap;