Fix string copy compilation warnings
authorDamien Le Moal <damien.lemoal@wdc.com>
Tue, 4 Jun 2019 07:07:31 +0000 (16:07 +0900)
committerJens Axboe <axboe@kernel.dk>
Tue, 4 Jun 2019 14:52:49 +0000 (08:52 -0600)
Fix the many warnings that gcc 9 spits out.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
exp/expression-parser.y
filesetup.c
init.c
server.c

index 04a6e07a38ae924ed04cbb6736b87894eeceee61..8619025c692c3c914f681e705677e99cadd69ed6 100644 (file)
@@ -204,9 +204,9 @@ static void setup_to_parse_string(const char *string)
 {
        unsigned int len;
 
-       len = strlen(string);
-       if (len > sizeof(lexer_input_buffer) - 3)
-               len = sizeof(lexer_input_buffer) - 3;
+       len = sizeof(lexer_input_buffer) - 3;
+       if (len > strlen(string))
+               len = strlen(string);
 
        strncpy(lexer_input_buffer, string, len);
        lexer_input_buffer[len] = '\0'; 
index 24e6fb0757d84d3ceafb21a18cd12b5016af8307..17fa31fb3cd48924be886d55569b7c1356e72faf 100644 (file)
@@ -829,7 +829,8 @@ static unsigned long long get_fs_free_counts(struct thread_data *td)
                        continue;
 
                fm = calloc(1, sizeof(*fm));
-               strncpy(fm->__base, buf, sizeof(fm->__base) - 1);
+               strncpy(fm->__base, buf, sizeof(fm->__base));
+               fm->__base[255] = '\0'; 
                fm->base = basename(fm->__base);
                fm->key = sb.st_dev;
                flist_add(&fm->list, &list);
diff --git a/init.c b/init.c
index 738342799c5cc391494b43d3de8433939698cb35..f2ba1e208e8f1cc44d37490501abb932c6b6ed4b 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1438,7 +1438,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num,
                   int recursed, int client_type)
 {
        unsigned int i;
-       char fname[PATH_MAX];
+       char fname[PATH_MAX + 1];
        int numjobs, file_alloced;
        struct thread_options *o = &td->o;
        char logname[PATH_MAX + 32];
@@ -2040,7 +2040,8 @@ static int __parse_jobs_ini(struct thread_data *td,
                                        strncpy(full_fn,
                                                file, (ts - file) + 1);
                                        strncpy(full_fn + (ts - file) + 1,
-                                               filename, strlen(filename));
+                                               filename,
+                                               len - (ts - file) - 1);
                                        full_fn[len - 1] = 0;
                                        filename = full_fn;
                                }
index 2a33770733e99e447f16511061f9f21a2699f2f5..23e549a590a709e4072b4de33704a32b46f3dd73 100644 (file)
--- a/server.c
+++ b/server.c
@@ -1470,9 +1470,12 @@ void fio_server_send_ts(struct thread_stat *ts, struct group_run_stats *rs)
 
        memset(&p, 0, sizeof(p));
 
-       strncpy(p.ts.name, ts->name, FIO_JOBNAME_SIZE - 1);
-       strncpy(p.ts.verror, ts->verror, FIO_VERROR_SIZE - 1);
-       strncpy(p.ts.description, ts->description, FIO_JOBDESC_SIZE - 1);
+       strncpy(p.ts.name, ts->name, FIO_JOBNAME_SIZE);
+       p.ts.name[FIO_JOBNAME_SIZE - 1] = '\0';
+       strncpy(p.ts.verror, ts->verror, FIO_VERROR_SIZE);
+       p.ts.verror[FIO_VERROR_SIZE - 1] = '\0';
+       strncpy(p.ts.description, ts->description, FIO_JOBDESC_SIZE);
+       p.ts.description[FIO_JOBDESC_SIZE - 1] = '\0';
 
        p.ts.error              = cpu_to_le32(ts->error);
        p.ts.thread_number      = cpu_to_le32(ts->thread_number);