From 097c911244b53a044c4d4dfd33fdf12fd9a9cdd3 Mon Sep 17 00:00:00 2001 From: Alex Zhuravlev Date: Wed, 22 May 2019 13:28:55 -0700 Subject: [PATCH] LU-11233 tests: fix gcc8 build warnings this patch covers Lustre tests Lustre-change: https://review.whamcloud.com/34661 Lustre-commit: 6733fbff9a682bcec5fdca6f7062c24f0fe27cfe Signed-off-by: Alex Zhuravlev Change-Id: I6345d603772fb32bbc4b38a758a3e97f0361d116 Reviewed-by: Jian Yu Reviewed-by: Li Dongyang Reviewed-by: James Simmons Signed-off-by: Minh Diep Reviewed-on: https://review.whamcloud.com/35005 Tested-by: Jenkins Reviewed-by: Andreas Dilger Tested-by: Maloo --- lustre/tests/fsx.c | 8 ++++---- lustre/tests/llapi_fid_test.c | 4 ++-- lustre/tests/llapi_layout_test.c | 14 +++++++------- lustre/tests/mpi/cascading_rw.c | 14 +++++++------- lustre/tests/mpi/mdsrate.c | 2 +- lustre/tests/mpi/parallel_grouplock.c | 2 +- lustre/tests/mpi/rr_alloc.c | 2 +- lustre/tests/openfile.c | 15 +++++++-------- lustre/utils/lfs.c | 4 ++-- 9 files changed, 32 insertions(+), 33 deletions(-) diff --git a/lustre/tests/fsx.c b/lustre/tests/fsx.c index aa8aaee..71711ab 100644 --- a/lustre/tests/fsx.c +++ b/lustre/tests/fsx.c @@ -115,8 +115,8 @@ char *original_buf; /* a pointer to the original data */ char *good_buf; /* a pointer to the correct data */ char *temp_buf; /* a pointer to the current data */ char *fname; /* name of our test file */ -char logfile[1024]; /* name of our log file */ -char goodfile[1024]; /* name of our test file */ +char logfile[PATH_MAX]; /* name of our log file */ +char goodfile[PATH_MAX]; /* name of our test file */ off_t file_size = 0; off_t biggest = 0; @@ -1278,9 +1278,9 @@ main(int argc, char **argv) randomoplen = 0; break; case 'P': - strncpy(goodfile, optarg, sizeof(goodfile)); + strncpy(goodfile, optarg, sizeof(goodfile) - 1); strcat(goodfile, "/"); - strncpy(logfile, optarg, sizeof(logfile)); + strncpy(logfile, optarg, sizeof(logfile) - 1); strcat(logfile, "/"); dirpath = 1; break; diff --git a/lustre/tests/llapi_fid_test.c b/lustre/tests/llapi_fid_test.c index cefc10d..8f2f946 100644 --- a/lustre/tests/llapi_fid_test.c +++ b/lustre/tests/llapi_fid_test.c @@ -333,7 +333,7 @@ static void test20(void) /* Create subdirectories as long as we can. Each new subdir is * "/x", so we need at least 3 characters left in testpath. */ while (len <= sizeof(testpath) - 3) { - strncat(testpath, "/x", 2); + strncat(testpath, "/x", sizeof(testpath) - 1); len += 2; @@ -369,7 +369,7 @@ static void test30(void) bool seen; } links[num_links]; char buf[PATH_MAX]; - char buf2[PATH_MAX]; + char buf2[PATH_MAX * 2]; struct lu_fid fid; char fidstr[FID_LEN + 1]; int rc; diff --git a/lustre/tests/llapi_layout_test.c b/lustre/tests/llapi_layout_test.c index 385b886..3002929 100644 --- a/lustre/tests/llapi_layout_test.c +++ b/lustre/tests/llapi_layout_test.c @@ -234,7 +234,7 @@ void test4(void) uint64_t size; const char *lfs = getenv("LFS"); char mypool[LOV_MAXPOOLNAME + 1] = { '\0' }; - char cmd[4096]; + char cmd[PATH_MAX + 128]; char path[PATH_MAX]; snprintf(path, sizeof(path), "%s/%s", lustre_dir, T4FILE); @@ -1083,7 +1083,7 @@ void test26(void) uint64_t size; uint64_t pattern; char dir[PATH_MAX]; - char cmd[4096]; + char cmd[PATH_MAX + 64]; snprintf(dir, sizeof(dir), "%s/%s", lustre_dir, T26DIR); rc = rmdir(dir); @@ -1130,11 +1130,11 @@ void test27(void) uint64_t count; uint64_t size; uint64_t pattern; - char dirpath[PATH_MAX]; - char filepath[PATH_MAX]; - char cmd[4096]; + char dirpath[PATH_MAX + 128]; + char filepath[PATH_MAX * 2]; + char cmd[PATH_MAX * 2]; - snprintf(dirpath, sizeof(dirpath), "%s/%s", lustre_dir, T27DIR); + snprintf(dirpath, sizeof(dirpath) - 1, "%s/%s", lustre_dir, T27DIR); snprintf(filepath, sizeof(filepath), "%s/nonesuch", dirpath); rc = rmdir(dirpath); @@ -1179,7 +1179,7 @@ void test28(void) const char *lfs = getenv("LFS"); uint64_t count; char dirpath[PATH_MAX]; - char cmd[4096]; + char cmd[PATH_MAX + 64]; snprintf(dirpath, sizeof(dirpath), "%s/%s", lustre_dir, T28DIR); diff --git a/lustre/tests/mpi/cascading_rw.c b/lustre/tests/mpi/cascading_rw.c index 2492728..0858939 100644 --- a/lustre/tests/mpi/cascading_rw.c +++ b/lustre/tests/mpi/cascading_rw.c @@ -60,13 +60,13 @@ char *testdir = NULL; void rw_file(char *name, long stride, unsigned int seed) { - char filename[MAX_FILENAME_LEN]; - char errmsg[MAX_FILENAME_LEN+20]; - char *buf, *o_buf; - struct lov_user_md lum = {0}; - int fd, rc, i, bad = 0, root = 0; - long off; - long page_size = sysconf(_SC_PAGESIZE); + char filename[MAX_FILENAME_LEN]; + char errmsg[MAX_FILENAME_LEN+32]; + char *buf, *o_buf; + struct lov_user_md lum = {0}; + int fd, rc, i, bad = 0, root = 0; + long off; + long page_size = sysconf(_SC_PAGESIZE); sprintf(filename, "%s/%s", testdir, name); diff --git a/lustre/tests/mpi/mdsrate.c b/lustre/tests/mpi/mdsrate.c index cdfab50..b20470f 100644 --- a/lustre/tests/mpi/mdsrate.c +++ b/lustre/tests/mpi/mdsrate.c @@ -118,7 +118,7 @@ int openflags = O_RDWR|O_CREAT|O_EXCL; int ndirs = 1; char * dirfmt; char dir[PATH_MAX]; -char mkdir_cmd[PATH_MAX+14]; +char mkdir_cmd[PATH_MAX+32]; int dirthreads; int dirnum; DIR * directory; diff --git a/lustre/tests/mpi/parallel_grouplock.c b/lustre/tests/mpi/parallel_grouplock.c index fb38130..9cf2464 100644 --- a/lustre/tests/mpi/parallel_grouplock.c +++ b/lustre/tests/mpi/parallel_grouplock.c @@ -74,7 +74,7 @@ char buf[LPGL_BUF_LEN]; char *lgbuf; int lgbuf_size; char filename[MAX_FILENAME_LEN]; -char errmsg[MAX_FILENAME_LEN+20]; +char errmsg[MAX_FILENAME_LEN+96]; static void alloc_lgbuf() diff --git a/lustre/tests/mpi/rr_alloc.c b/lustre/tests/mpi/rr_alloc.c index e65f711..c334b0d 100644 --- a/lustre/tests/mpi/rr_alloc.c +++ b/lustre/tests/mpi/rr_alloc.c @@ -117,7 +117,7 @@ int main(int argc, char **argv) fname = basename(path1); dname = basename(dirname(path2)); /* dirname looping depends on the depth of the file from mount path */ - strncpy(mnt_path, dirname(dirname(path3)), sizeof(mnt_path)); + strncpy(mnt_path, dirname(dirname(path3)), sizeof(mnt_path) - 1); file_no = atoi(argv[2]); if (!file_no) { diff --git a/lustre/tests/openfile.c b/lustre/tests/openfile.c index 0a7bb8c..c98313e 100644 --- a/lustre/tests/openfile.c +++ b/lustre/tests/openfile.c @@ -100,16 +100,15 @@ int main(int argc, char** argv) while ((c = getopt (argc, argv, "f:m:")) != -1) { switch (c) { case 'f': { - char *tmp; + char *tmp; - cloned_flags = (char *)malloc(strlen(optarg)+1); - if (cloned_flags == NULL) { - fprintf(stderr, "Insufficient memory.\n"); - save_errno = -1; - goto out; - } + cloned_flags = strdup(optarg); + if (cloned_flags == NULL) { + fprintf(stderr, "Insufficient memory.\n"); + save_errno = -1; + goto out; + } - strncpy(cloned_flags, optarg, strlen(optarg)+1); flags = atoi(cloned_flags); if (flags > 0) { flag_set = 1; diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index b878748..447d43c 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -3213,7 +3213,7 @@ static int lfs_setstripe_internal(int argc, char **argv, lmu->lum_hash_type = LMV_HASH_TYPE_FNV_1A_64; if (lsa.lsa_pool_name) strncpy(lmu->lum_pool_name, lsa.lsa_pool_name, - sizeof(lmu->lum_pool_name)); + sizeof(lmu->lum_pool_name) - 1); if (lsa.lsa_nr_tgts > 1) { int i; @@ -5140,7 +5140,7 @@ static int lfs_setdirstripe(int argc, char **argv) lsb->sb_count = 0; /* use mntdir for dirname() temporarily */ - strncpy(mntdir, dname, sizeof(mntdir)); + strncpy(mntdir, dname, sizeof(mntdir) - 1); if (!realpath(dirname(mntdir), path)) { result = -errno; fprintf(stderr, -- 1.8.3.1