Skip to content

Commit

Permalink
Enable -Wwrite-strings
Browse files Browse the repository at this point in the history
Also, fix leak from ztest_global_vars_to_zdb_args()

Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes openzfs#13348
  • Loading branch information
nabijaczleweli authored and behlendorf committed Jun 29, 2022
1 parent e7d9036 commit a926aab
Show file tree
Hide file tree
Showing 99 changed files with 638 additions and 722 deletions.
13 changes: 7 additions & 6 deletions cmd/mount_zfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,21 @@ mtab_is_writeable(void)
}

static int
mtab_update(char *dataset, char *mntpoint, char *type, char *mntopts)
mtab_update(const char *dataset, const char *mntpoint, const char *type,
const char *mntopts)
{
struct mntent mnt;
FILE *fp;
int error;

mnt.mnt_fsname = dataset;
mnt.mnt_dir = mntpoint;
mnt.mnt_type = type;
mnt.mnt_opts = mntopts ? mntopts : "";
mnt.mnt_fsname = (char *)dataset;
mnt.mnt_dir = (char *)mntpoint;
mnt.mnt_type = (char *)type;
mnt.mnt_opts = (char *)(mntopts ?: "");
mnt.mnt_freq = 0;
mnt.mnt_passno = 0;

fp = setmntent("/etc/mtab", "a+");
fp = setmntent("/etc/mtab", "a+e");
if (!fp) {
(void) fprintf(stderr, gettext(
"filesystem '%s' was mounted, but /etc/mtab "
Expand Down
2 changes: 1 addition & 1 deletion cmd/raidz_test/raidz_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static void sig_handler(int signo)

static void print_opts(raidz_test_opts_t *opts, boolean_t force)
{
char *verbose;
const char *verbose;
switch (opts->rto_v) {
case D_ALL:
verbose = "no";
Expand Down
48 changes: 24 additions & 24 deletions cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
#define ZDB_MAP_OBJECT_ID(obj) (obj)
#endif

static char *
static const char *
zdb_ot_name(dmu_object_type_t type)
{
if (type < DMU_OT_NUMTYPES)
Expand Down Expand Up @@ -2922,7 +2922,7 @@ dsl_deadlist_entry_dump(void *arg, dsl_deadlist_entry_t *dle)
}

static void
dump_blkptr_list(dsl_deadlist_t *dl, char *name)
dump_blkptr_list(dsl_deadlist_t *dl, const char *name)
{
char bytes[32];
char comp[32];
Expand Down Expand Up @@ -2963,7 +2963,7 @@ dump_blkptr_list(dsl_deadlist_t *dl, char *name)
if (dump_opt['d'] < 4)
return;

(void) printf("\n");
(void) putchar('\n');

dsl_deadlist_iterate(dl, dsl_deadlist_entry_dump, NULL);
}
Expand Down Expand Up @@ -3098,9 +3098,8 @@ static void
print_idstr(uint64_t id, const char *id_type)
{
if (FUID_INDEX(id)) {
char *domain;

domain = zfs_fuid_idx_domain(&idx_tree, FUID_INDEX(id));
const char *domain =
zfs_fuid_idx_domain(&idx_tree, FUID_INDEX(id));
(void) printf("\t%s %llx [%s-%d]\n", id_type,
(u_longlong_t)id, domain, (int)FUID_RID(id));
} else {
Expand Down Expand Up @@ -3643,7 +3642,7 @@ count_ds_mos_objects(dsl_dataset_t *ds)
}
}

static const char *objset_types[DMU_OST_NUMTYPES] = {
static const char *const objset_types[DMU_OST_NUMTYPES] = {
"NONE", "META", "ZPL", "ZVOL", "OTHER", "ANY" };

/*
Expand All @@ -3653,7 +3652,7 @@ static const char *objset_types[DMU_OST_NUMTYPES] = {
* pointer to point to a descriptive error message.
*/
static int
parse_object_range(char *range, zopt_object_range_t *zor, char **msg)
parse_object_range(char *range, zopt_object_range_t *zor, const char **msg)
{
uint64_t flags = 0;
char *p, *s, *dup, *flagstr, *tmp = NULL;
Expand Down Expand Up @@ -4236,13 +4235,13 @@ first_label(cksum_record_t *rec)
}

static void
print_label_numbers(char *prefix, cksum_record_t *rec)
print_label_numbers(const char *prefix, const cksum_record_t *rec)
{
printf("%s", prefix);
fputs(prefix, stdout);
for (int i = 0; i < VDEV_LABELS; i++)
if (rec->labels[i] == B_TRUE)
printf("%d ", i);
printf("\n");
putchar('\n');
}

#define MAX_UBERBLOCK_COUNT (VDEV_UBERBLOCK_RING >> UBERBLOCK_SHIFT)
Expand Down Expand Up @@ -5126,7 +5125,7 @@ same_metaslab(spa_t *spa, uint64_t vdev, uint64_t off1, uint64_t off2)
* Used to simplify reporting of the histogram data.
*/
typedef struct one_histo {
char *name;
const char *name;
uint64_t *count;
uint64_t *len;
uint64_t cumulative;
Expand Down Expand Up @@ -8093,32 +8092,33 @@ zdb_read_block(char *thing, spa_t *spa)
vdev_t *vd;
abd_t *pabd;
void *lbuf, *buf;
char *s, *p, *dup, *vdev, *flagstr, *sizes, *tmp = NULL;
char *s, *p, *dup, *flagstr, *sizes, *tmp = NULL;
const char *vdev, *errmsg = NULL;
int i, error;
boolean_t borrowed = B_FALSE, found = B_FALSE;

dup = strdup(thing);
s = strtok_r(dup, ":", &tmp);
vdev = s ? s : "";
vdev = s ?: "";
s = strtok_r(NULL, ":", &tmp);
offset = strtoull(s ? s : "", NULL, 16);
sizes = strtok_r(NULL, ":", &tmp);
s = strtok_r(NULL, ":", &tmp);
flagstr = strdup(s ? s : "");
flagstr = strdup(s ?: "");

s = NULL;
tmp = NULL;
if (!zdb_parse_block_sizes(sizes, &lsize, &psize))
s = "invalid size(s)";
errmsg = "invalid size(s)";
if (!IS_P2ALIGNED(psize, DEV_BSIZE) || !IS_P2ALIGNED(lsize, DEV_BSIZE))
s = "size must be a multiple of sector size";
errmsg = "size must be a multiple of sector size";
if (!IS_P2ALIGNED(offset, DEV_BSIZE))
s = "offset must be a multiple of sector size";
if (s) {
(void) printf("Invalid block specifier: %s - %s\n", thing, s);
errmsg = "offset must be a multiple of sector size";
if (errmsg) {
(void) printf("Invalid block specifier: %s - %s\n",
thing, errmsg);
goto done;
}

tmp = NULL;
for (s = strtok_r(flagstr, ":", &tmp);
s != NULL;
s = strtok_r(NULL, ":", &tmp)) {
Expand Down Expand Up @@ -8930,13 +8930,13 @@ main(int argc, char **argv)
sizeof (zopt_object_range_t));
for (unsigned i = 0; i < zopt_object_args; i++) {
int err;
char *msg = NULL;
const char *msg = NULL;

err = parse_object_range(argv[i],
&zopt_object_ranges[i], &msg);
if (err != 0)
fatal("Bad object or range: '%s': %s\n",
argv[i], msg ? msg : "");
argv[i], msg ?: "");
}
} else if (argc > 0 && dump_opt['m']) {
zopt_metaslab_args = argc;
Expand Down
3 changes: 2 additions & 1 deletion cmd/zed/agents/fmd_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ zed_log_fault(nvlist_t *nvl, const char *uuid, const char *code)
static const char *
fmd_fault_mkcode(nvlist_t *fault)
{
char *class, *code = "-";
char *class;
const char *code = "-";

/*
* Note: message codes come from: openzfs/usr/src/cmd/fm/dicts/ZFS.po
Expand Down
Loading

0 comments on commit a926aab

Please sign in to comment.