Whamcloud - gitweb
LU-11233 tests: fix gcc8 build warnings 05/35005/2
authorAlex Zhuravlev <bzzz@whamcloud.com>
Wed, 22 May 2019 20:28:55 +0000 (13:28 -0700)
committerOleg Drokin <green@whamcloud.com>
Sat, 8 Jun 2019 02:38:01 +0000 (02:38 +0000)
this patch covers Lustre tests

Lustre-change: https://review.whamcloud.com/34661
Lustre-commit: 6733fbff9a682bcec5fdca6f7062c24f0fe27cfe

Signed-off-by: Alex Zhuravlev <bzzz@whamcloud.com>
Change-Id: I6345d603772fb32bbc4b38a758a3e97f0361d116
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Li Dongyang <dongyangli@ddn.com>
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
Signed-off-by: Minh Diep <mdiep@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/35005
Tested-by: Jenkins
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/tests/fsx.c
lustre/tests/llapi_fid_test.c
lustre/tests/llapi_layout_test.c
lustre/tests/mpi/cascading_rw.c
lustre/tests/mpi/mdsrate.c
lustre/tests/mpi/parallel_grouplock.c
lustre/tests/mpi/rr_alloc.c
lustre/tests/openfile.c
lustre/utils/lfs.c

index aa8aaee..71711ab 100644 (file)
@@ -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   *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;
 
 off_t          file_size = 0;
 off_t          biggest = 0;
@@ -1278,9 +1278,9 @@ main(int argc, char **argv)
                        randomoplen = 0;
                        break;
                case 'P':
                        randomoplen = 0;
                        break;
                case 'P':
-                       strncpy(goodfile, optarg, sizeof(goodfile));
+                       strncpy(goodfile, optarg, sizeof(goodfile) - 1);
                        strcat(goodfile, "/");
                        strcat(goodfile, "/");
-                       strncpy(logfile, optarg, sizeof(logfile));
+                       strncpy(logfile, optarg, sizeof(logfile) - 1);
                        strcat(logfile, "/");
                        dirpath = 1;
                        break;
                        strcat(logfile, "/");
                        dirpath = 1;
                        break;
index cefc10d..8f2f946 100644 (file)
@@ -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) {
        /* 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;
 
 
                len += 2;
 
@@ -369,7 +369,7 @@ static void test30(void)
                bool seen;
        } links[num_links];
        char buf[PATH_MAX];
                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;
        struct lu_fid fid;
        char fidstr[FID_LEN + 1];
        int rc;
index 385b886..3002929 100644 (file)
@@ -234,7 +234,7 @@ void test4(void)
        uint64_t size;
        const char *lfs = getenv("LFS");
        char mypool[LOV_MAXPOOLNAME + 1] = { '\0' };
        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);
        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];
        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);
 
        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;
        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);
        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];
        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);
 
 
        snprintf(dirpath, sizeof(dirpath), "%s/%s", lustre_dir, T28DIR);
 
index 2492728..0858939 100644 (file)
@@ -60,13 +60,13 @@ char *testdir = NULL;
 
 void rw_file(char *name, long stride, unsigned int seed)
 {
 
 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);
 
 
         sprintf(filename, "%s/%s", testdir, name);
 
index cdfab50..b20470f 100644 (file)
@@ -118,7 +118,7 @@ int    openflags = O_RDWR|O_CREAT|O_EXCL;
 int    ndirs = 1;
 char * dirfmt;
 char   dir[PATH_MAX];
 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;
 int    dirthreads;
 int    dirnum;
 DIR *  directory;
index fb38130..9cf2464 100644 (file)
@@ -74,7 +74,7 @@ char  buf[LPGL_BUF_LEN];
 char *lgbuf;
 int   lgbuf_size;
 char  filename[MAX_FILENAME_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()
 
 static void
 alloc_lgbuf()
index e65f711..c334b0d 100644 (file)
@@ -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 */
        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) {
 
        file_no = atoi(argv[2]);
        if (!file_no) {
index 0a7bb8c..c98313e 100644 (file)
@@ -100,16 +100,15 @@ int main(int argc, char** argv)
         while ((c = getopt (argc, argv, "f:m:")) != -1) {
                 switch (c) {
                 case 'f': {
         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;
                         flags = atoi(cloned_flags);
                         if (flags > 0) {
                                 flag_set = 1;
index b878748..447d43c 100644 (file)
@@ -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,
                        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;
 
                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 */
                                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,
                                if (!realpath(dirname(mntdir), path)) {
                                        result = -errno;
                                        fprintf(stderr,