Skip to content

Commit c726f84

Browse files
committed
Fixing compilation warnings in building glusterfs
``` client_t.c: In function 'gf_client_dump_fdtables': client_t.c:601:17: warning: the comparison will always evaluate as 'true' for the address of 'client_uid' will never be NULL [-Waddress] 601 | if (client->client_uid) { | ^~~~~~ In file included from ./glusterfs/stack.h:31, from ./glusterfs/xlator.h:53, from ./glusterfs/fd.h:79, from ./glusterfs/inode.h:33, from glusterfs/statedump.h:15, from client_t.c:12: ./glusterfs/client_t.h:59:10: note: 'client_uid' declared here 59 | char client_uid[]; | ^~~~~~~~~~ .... glusterd-svc-mgmt.c: In function 'glusterd_svc_build_volfile_path': glusterd-svc-mgmt.c:298:38: warning: '-server.vol' directive output may be truncated writing 11 bytes into a region of size between 0 and 4095 [-Wformat-truncation=] 298 | snprintf(volfile, len, "%s/%s-server.vol", dir, server); | ^~~~~~~~~~~ glusterd-svc-mgmt.c:298:9: note: 'snprintf' output 13 or more bytes (assuming 4108) into a destination of size 4096 298 | snprintf(volfile, len, "%s/%s-server.vol", dir, server); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ glusterd-svc-mgmt.c:296:38: warning: '.vol' directive output may be truncated writing 4 bytes into a region of size between 0 and 4095 [-Wformat-truncation=] 296 | snprintf(volfile, len, "%s/%s.vol", dir, server); | ^~~~ glusterd-svc-mgmt.c:296:9: note: 'snprintf' output 6 or more bytes (assuming 4101) into a destination of size 4096 296 | snprintf(volfile, len, "%s/%s.vol", dir, server); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ glusterd-svc-mgmt.c: In function 'glusterd_svc_build_pidfile_path': glusterd-svc-mgmt.c:279:31: warning: '.pid' directive output may be truncated writing 4 bytes into a region of size between 0 and 4095 [-Wformat-truncation=] 279 | snprintf(path, len, "%s/%s.pid", dir, server); | ^~~~ glusterd-svc-mgmt.c:279:5: note: 'snprintf' output 6 or more bytes (assuming 4101) into a destination of size 4096 279 | snprintf(path, len, "%s/%s.pid", dir, server); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ glusterd-utils.c: In function 'glusterd_is_path_in_use': glusterd-utils.c:7676:40: warning: '%s' directive output may be truncated writing up to 4095 bytes into a region of size 2031 [-Wformat-truncation=] 7676 | "parent directory %s is " | ^~ glusterd-utils.c:7675:13: note: 'snprintf' output between 46 and 4141 bytes into a destination of size 2048 7675 | snprintf(msg, sizeof(msg), | ^~~~~~~~~~~~~~~~~~~~~~~~~~ 7676 | "parent directory %s is " | ~~~~~~~~~~~~~~~~~~~~~~~~~ 7677 | "already part of a volume", | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7678 | curdir); | ~~~~~~~ glusterd-mgmt.c: In function 'gd_mgmt_v3_collate_errors': glusterd-mgmt.c:82:77: warning: '%s' directive output may be truncated writing up to 4095 bytes into a region of size 4072 [-Wformat-truncation=] 82 | snprintf(op_err, sizeof(op_err), "Post commit failed on %s. %s", | ^~ glusterd-mgmt.c:82:17: note: 'snprintf' output 25 or more bytes (assuming 4120) into a destination of size 4096 82 | snprintf(op_err, sizeof(op_err), "Post commit failed on %s. %s", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 83 | peer_str, err_string); | ~~~~~~~~~~~~~~~~~~~~~ glusterd-mgmt.c:93:75: warning: '%s' directive output may be truncated writing up to 4095 bytes into a region of size 4074 [-Wformat-truncation=] 93 | snprintf(op_err, sizeof(op_err), "Unlocking failed on %s. %s", | ^~ glusterd-mgmt.c:93:17: note: 'snprintf' output 23 or more bytes (assuming 4118) into a destination of size 4096 93 | snprintf(op_err, sizeof(op_err), "Unlocking failed on %s. %s", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 94 | peer_str, err_string); | ~~~~~~~~~~~~~~~~~~~~~ glusterd-mgmt.c:88:57: warning: '%s' directive output may be truncated writing up to 4095 bytes into a region of size 4068 [-Wformat-truncation=] 88 | "Post Validation failed on %s. %s", peer_str, | ^~ glusterd-mgmt.c:87:17: note: 'snprintf' output 29 or more bytes (assuming 4124) into a destination of size 4096 87 | snprintf(op_err, sizeof(op_err), | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 88 | "Post Validation failed on %s. %s", peer_str, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 89 | err_string); | ~~~~~~~~~~~ glusterd-mgmt.c:77:72: warning: '%s' directive output may be truncated writing up to 4095 bytes into a region of size 4077 [-Wformat-truncation=] 77 | snprintf(op_err, sizeof(op_err), "Commit failed on %s. %s", | ^~ glusterd-mgmt.c:77:17: note: 'snprintf' output 20 or more bytes (assuming 4115) into a destination of size 4096 77 | snprintf(op_err, sizeof(op_err), "Commit failed on %s. %s", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 78 | peer_str, err_string); | ~~~~~~~~~~~~~~~~~~~~~ glusterd-mgmt.c:72:75: warning: '%s' directive output may be truncated writing up to 4095 bytes into a region of size 4074 [-Wformat-truncation=] 72 | snprintf(op_err, sizeof(op_err), "Brick ops failed on %s. %s", | ^~ glusterd-mgmt.c:72:17: note: 'snprintf' output 23 or more bytes (assuming 4118) into a destination of size 4096 72 | snprintf(op_err, sizeof(op_err), "Brick ops failed on %s. %s", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 73 | peer_str, err_string); | ~~~~~~~~~~~~~~~~~~~~~ glusterd-mgmt.c:67:56: warning: '%s' directive output may be truncated writing up to 4095 bytes into a region of size 4069 [-Wformat-truncation=] 67 | "Pre Validation failed on %s. %s", peer_str, | ^~ glusterd-mgmt.c:66:17: note: 'snprintf' output 28 or more bytes (assuming 4123) into a destination of size 4096 66 | snprintf(op_err, sizeof(op_err), | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 67 | "Pre Validation failed on %s. %s", peer_str, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 68 | err_string); | ~~~~~~~~~~~ glusterd-mgmt.c:61:73: warning: '%s' directive output may be truncated writing up to 4095 bytes into a region of size 4076 [-Wformat-truncation=] 61 | snprintf(op_err, sizeof(op_err), "Locking failed on %s. %s", | ^~ glusterd-mgmt.c:61:17: note: 'snprintf' output 21 or more bytes (assuming 4116) into a destination of size 4096 61 | snprintf(op_err, sizeof(op_err), "Locking failed on %s. %s", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 62 | peer_str, err_string); | ~~~~~~~~~~~~~~~~~~~~~ glusterd-mgmt.c:98:73: warning: '%s' directive output may be truncated writing up to 4095 bytes into a region of size 4076 [-Wformat-truncation=] 98 | snprintf(op_err, sizeof(op_err), "Unknown error! on %s. %s", | ^~ glusterd-mgmt.c:98:17: note: 'snprintf' output 21 or more bytes (assuming 4116) into a destination of size 4096 98 | snprintf(op_err, sizeof(op_err), "Unknown error! on %s. %s", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 99 | peer_str, err_string); | ~~~~~~~~~~~~~~~~~~~~~ ``` Change-Id: I327fb1826eda66ae283547d9319435b2aac3ada4 Signed-off-by: Pranith Kumar Karampuri <[email protected]> Signed-off-by: Pranith Kumar Karampuri <[email protected]>
1 parent 7663679 commit c726f84

File tree

4 files changed

+43
-32
lines changed

4 files changed

+43
-32
lines changed

libglusterfs/src/client_t.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -598,10 +598,8 @@ gf_client_dump_fdtables(xlator_t *this)
598598
clienttable->cliententries[count].next_free)
599599
continue;
600600
client = clienttable->cliententries[count].client;
601-
if (client->client_uid) {
602-
gf_proc_dump_build_key(key, "conn", "%d.id", count);
603-
gf_proc_dump_write(key, "%s", client->client_uid);
604-
}
601+
gf_proc_dump_build_key(key, "conn", "%d.id", count);
602+
gf_proc_dump_write(key, "%s", client->client_uid);
605603

606604
if (client->subdir_mount) {
607605
gf_proc_dump_build_key(key, "conn", "%d.subdir", count);

xlators/mgmt/glusterd/src/glusterd-mgmt.c

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,45 +58,56 @@ gd_mgmt_v3_collate_errors(struct syncargs *args, int op_ret, int op_errno,
5858

5959
switch (op_code) {
6060
case GLUSTERD_MGMT_V3_LOCK: {
61-
snprintf(op_err, sizeof(op_err), "Locking failed on %s. %s",
62-
peer_str, err_string);
61+
len = snprintf(op_err, sizeof(op_err),
62+
"Locking failed on %s. %s", peer_str,
63+
err_string);
6364
break;
6465
}
6566
case GLUSTERD_MGMT_V3_PRE_VALIDATE: {
66-
snprintf(op_err, sizeof(op_err),
67-
"Pre Validation failed on %s. %s", peer_str,
68-
err_string);
67+
len = snprintf(op_err, sizeof(op_err),
68+
"Pre Validation failed on %s. %s", peer_str,
69+
err_string);
6970
break;
7071
}
7172
case GLUSTERD_MGMT_V3_BRICK_OP: {
72-
snprintf(op_err, sizeof(op_err), "Brick ops failed on %s. %s",
73-
peer_str, err_string);
73+
len = snprintf(op_err, sizeof(op_err),
74+
"Brick ops failed on %s. %s", peer_str,
75+
err_string);
7476
break;
7577
}
7678
case GLUSTERD_MGMT_V3_COMMIT: {
77-
snprintf(op_err, sizeof(op_err), "Commit failed on %s. %s",
78-
peer_str, err_string);
79+
len = snprintf(op_err, sizeof(op_err),
80+
"Commit failed on %s. %s", peer_str, err_string);
7981
break;
8082
}
8183
case GLUSTERD_MGMT_V3_POST_COMMIT: {
82-
snprintf(op_err, sizeof(op_err), "Post commit failed on %s. %s",
83-
peer_str, err_string);
84+
len = snprintf(op_err, sizeof(op_err),
85+
"Post commit failed on %s. %s", peer_str,
86+
err_string);
8487
break;
8588
}
8689
case GLUSTERD_MGMT_V3_POST_VALIDATE: {
87-
snprintf(op_err, sizeof(op_err),
88-
"Post Validation failed on %s. %s", peer_str,
89-
err_string);
90+
len = snprintf(op_err, sizeof(op_err),
91+
"Post Validation failed on %s. %s", peer_str,
92+
err_string);
9093
break;
9194
}
9295
case GLUSTERD_MGMT_V3_UNLOCK: {
93-
snprintf(op_err, sizeof(op_err), "Unlocking failed on %s. %s",
94-
peer_str, err_string);
96+
len = snprintf(op_err, sizeof(op_err),
97+
"Unlocking failed on %s. %s", peer_str,
98+
err_string);
9599
break;
96100
}
97101
default:
98-
snprintf(op_err, sizeof(op_err), "Unknown error! on %s. %s",
99-
peer_str, err_string);
102+
len = snprintf(op_err, sizeof(op_err),
103+
"Unknown error! on %s. %s", peer_str,
104+
err_string);
105+
}
106+
107+
gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_MGMTV3_OP_FAIL, "%s",
108+
op_err);
109+
if (len >= sizeof(op_err)) {
110+
strcpy(op_err, "Truncated error message, check logfile");
100111
}
101112

102113
if (args->errstr) {
@@ -110,8 +121,6 @@ gd_mgmt_v3_collate_errors(struct syncargs *args, int op_ret, int op_errno,
110121
} else
111122
snprintf(err_str, sizeof(err_str), "%s", op_err);
112123

113-
gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_MGMTV3_OP_FAIL, "%s",
114-
op_err);
115124
args->errstr = gf_strdup(err_str);
116125
}
117126

xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ void
271271
glusterd_svc_build_pidfile_path(char *server, char *workdir, char *path,
272272
size_t len)
273273
{
274-
char dir[PATH_MAX] = {0};
274+
char dir[VALID_GLUSTERD_PATHMAX] = {0};
275275

276276
GF_ASSERT(len == PATH_MAX);
277277

@@ -283,7 +283,7 @@ void
283283
glusterd_svc_build_volfile_path(char *server, char *workdir, char *volfile,
284284
size_t len)
285285
{
286-
char dir[PATH_MAX] = {
286+
char dir[VALID_GLUSTERD_PATHMAX] = {
287287
0,
288288
};
289289

@@ -301,15 +301,15 @@ glusterd_svc_build_volfile_path(char *server, char *workdir, char *volfile,
301301
void
302302
glusterd_svc_build_svcdir(char *server, char *workdir, char *path, size_t len)
303303
{
304-
GF_ASSERT(len == PATH_MAX);
304+
GF_ASSERT(len == VALID_GLUSTERD_PATHMAX);
305305

306306
snprintf(path, len, "%s/%s", workdir, server);
307307
}
308308

309309
void
310310
glusterd_svc_build_rundir(char *server, char *workdir, char *path, size_t len)
311311
{
312-
char dir[PATH_MAX] = {0};
312+
char dir[VALID_GLUSTERD_PATHMAX] = {0};
313313

314314
GF_ASSERT(len == PATH_MAX);
315315

xlators/mgmt/glusterd/src/glusterd-utils.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7672,10 +7672,14 @@ glusterd_is_path_in_use(char *path, gf_boolean_t *in_use, char **op_errstr)
76727672
ret = -1;
76737673
}
76747674
} else {
7675-
snprintf(msg, sizeof(msg),
7676-
"parent directory %s is "
7677-
"already part of a volume",
7678-
curdir);
7675+
int z = snprintf(msg, sizeof(msg),
7676+
"parent directory %s is "
7677+
"already part of a volume",
7678+
curdir);
7679+
if (z < 0 || z >= sizeof(msg)) {
7680+
snprintf(msg, sizeof(msg), "path too big");
7681+
ret = -1;
7682+
}
76797683
}
76807684
}
76817685

0 commit comments

Comments
 (0)