Commit 3c4430ab authored by Thomas Leibovici's avatar Thomas Leibovici
Browse files

Fix warnings reported by gcc8: 'output may be truncated'

See: https://developers.redhat.com/blog/2018/05/24/detecting-string-truncation-with-gcc-8/



Change-Id: Ibfc27472f55302c1f66e8cd53b3df89ffd4eab39
Signed-off-by: default avatarThomas Leibovici <thomas.leibovici@cea.fr>
Reviewed-on: https://cws-fleury.labs.ocre.cea.fr/gerrit/6719


Reviewed-by: Linter
Reviewed-by: default avatarPatrice LUCAS <patrice.lucas@cea.fr>
Reviewed-by: default avatarSebastien Gougeaud <sebastien.gougeaud@cea.fr>
Tested-by: default avatarJenkins s8open_nr <s8open_nr@ccc.ocre.cea.fr>
parent 04ebe7de
......@@ -119,6 +119,8 @@ int pho_comm_open(struct pho_comm_info *ci, const char *sock_path,
socka.sun_family = AF_UNIX;
strncpy(socka.sun_path, ci->path, sizeof(socka.sun_path));
/* make sure the path is zero-terminated */
socka.sun_path[sizeof(socka.sun_path)-1] = '\0';
if (!is_server) {
if (connect(ci->socket_fd, (struct sockaddr *)&socka, sizeof(socka)))
......
......@@ -1601,6 +1601,8 @@ static int dss_media_from_pg_row(void *void_media, PGresult *res, int row_num)
medium->fs.status = str2fs_status(PQgetvalue(res, row_num, 6));
strncpy(medium->fs.label, PQgetvalue(res, row_num, 7),
sizeof(medium->fs.label));
/* make sure the label is zero-terminated */
medium->fs.label[sizeof(medium->fs.label) - 1] = '\0';
medium->lock.lock = get_str_value(res, row_num, 10);
medium->lock.lock_ts = strtoul(PQgetvalue(res, row_num, 11), NULL, 10);
......
......@@ -1377,6 +1377,7 @@ static int sched_mount(struct dev_descr *dev)
/* update device state and set mount point */
dev->op_status = PHO_DEV_OP_ST_MOUNTED;
strncpy(dev->mnt_path, mnt_root, sizeof(dev->mnt_path));
dev->mnt_path[sizeof(dev->mnt_path) - 1] = '\0';
out_free:
free(mnt_root);
......@@ -2002,7 +2003,8 @@ static int sched_format(struct lrs_sched *sched, const struct pho_id *id,
LOG_GOTO(err_out, rc, "Cannot format media '%s'", id->name);
/* Systematically use the media ID as filesystem label */
strncpy(media_info->fs.label, id->name, sizeof(media_info->fs.label) - 1);
strncpy(media_info->fs.label, id->name, sizeof(media_info->fs.label));
media_info->fs.label[sizeof(media_info->fs.label) - 1] = '\0';
media_info->stats.phys_spc_used = spc.spc_used;
media_info->stats.phys_spc_free = spc.spc_avail;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment