Optimize the code that copies strings
[fio.git] / filesetup.c
index 17fa31fb3cd48924be886d55569b7c1356e72faf..57eca1bf5bf06f013c4c89e7ee553e440d9e15c3 100644 (file)
@@ -805,8 +805,7 @@ static unsigned long long get_fs_free_counts(struct thread_data *td)
                } else if (f->filetype != FIO_TYPE_FILE)
                        continue;
 
-               buf[255] = '\0';
-               strncpy(buf, f->file_name, 255);
+               snprintf(buf, ARRAY_SIZE(buf), "%s", f->file_name);
 
                if (stat(buf, &sb) < 0) {
                        if (errno != ENOENT)
@@ -829,8 +828,7 @@ 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));
-               fm->__base[255] = '\0'; 
+               snprintf(fm->__base, ARRAY_SIZE(fm->__base), "%s", buf);
                fm->base = basename(fm->__base);
                fm->key = sb.st_dev;
                flist_add(&fm->list, &list);