Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/fs/vfs - use snprintf



details:   https://anonhg.NetBSD.org/src/rev/d1ab77f32798
branches:  trunk
changeset: 347304:d1ab77f32798
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Aug 20 15:48:18 2016 +0000

description:
- use snprintf
- print the argument that caused the error

diffstat:

 tests/fs/vfs/t_vnops.c |  74 +++++++++++++++++++++++++-------------------------
 1 files changed, 37 insertions(+), 37 deletions(-)

diffs (234 lines):

diff -r 5fc8550b015b -r d1ab77f32798 tests/fs/vfs/t_vnops.c
--- a/tests/fs/vfs/t_vnops.c    Sat Aug 20 15:24:29 2016 +0000
+++ b/tests/fs/vfs/t_vnops.c    Sat Aug 20 15:48:18 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_vnops.c,v 1.55 2016/01/28 10:10:09 martin Exp $      */
+/*     $NetBSD: t_vnops.c,v 1.56 2016/08/20 15:48:18 christos Exp $    */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -55,10 +55,10 @@
        atf_tc_skip("symlinks not supported by file system")
 
 static char *
-md(char *buf, const char *base, const char *tail)
+md(char *buf, size_t buflen, const char *base, const char *tail)
 {
 
-       sprintf(buf, "%s/%s", base, tail);
+       snprintf(buf, buflen, "%s/%s", base, tail);
        return buf;
 }
 
@@ -69,11 +69,11 @@
        struct stat sb1, sb2;
 
        strcpy(final, mountpath);
-       sprintf(pb, "%s/../%s", mountpath, basename(final));
+       snprintf(pb, sizeof(pb), "%s/../%s", mountpath, basename(final));
        if (rump_sys_stat(pb, &sb1) == -1)
                atf_tc_fail_errno("stat 1");
 
-       sprintf(pb, "%s/./../%s", mountpath, basename(final));
+       snprintf(pb, sizeof(pb), "%s/./../%s", mountpath, basename(final));
        if (rump_sys_stat(pb, &sb2) == -1)
                atf_tc_fail_errno("stat 2");
 
@@ -91,13 +91,13 @@
        if (FSTYPE_UDF(tc))
                atf_tc_expect_fail("PR kern/49033");
 
-       sprintf(pb, "%s/dir", mountpath);
+       snprintf(pb, sizeof(pb), "%s/dir", mountpath);
        if (rump_sys_mkdir(pb, 0777) == -1)
                atf_tc_fail_errno("mkdir");
        if (rump_sys_stat(pb, &sb1) == -1)
                atf_tc_fail_errno("stat 1");
 
-       sprintf(pb, "%s/./dir/../././dir/.", mountpath);
+       snprintf(pb, sizeof(pb), "%s/./dir/../././dir/.", mountpath);
        if (rump_sys_stat(pb, &sb2) == -1)
                atf_tc_fail_errno("stat 2");
 
@@ -147,7 +147,7 @@
        USES_DIRS;
 
        /* check we can create directories */
-       sprintf(pb, "%s/dir", mountpath);
+       snprintf(pb, sizeof(pb), "%s/dir", mountpath);
        if (rump_sys_mkdir(pb, 0777) == -1)
                atf_tc_fail_errno("mkdir");
        if (rump_sys_stat(pb, &sb) == -1)
@@ -169,11 +169,11 @@
        USES_DIRS;
 
        /* check we can create directories */
-       sprintf(pb, "%s/dir", mountpath);
+       snprintf(pb, sizeof(pb), "%s/dir", mountpath);
        if (rump_sys_mkdir(pb, 0777) == -1)
                atf_tc_fail_errno("mkdir");
 
-       sprintf(pb2, "%s/dir/file", mountpath);
+       snprintf(pb2, sizeof(pb2), "%s/dir/file", mountpath);
        fd = rump_sys_open(pb2, O_RDWR | O_CREAT, 0777);
        if (fd == -1)
                atf_tc_fail_errno("create file");
@@ -205,9 +205,9 @@
        RL(rump_sys_mkdir("subtest", 0777));
        RL(rump_sys_chdir("subtest"));
 
-       md(pb, mp, "test/subtest");
+       md(pb, sizeof(pb), mp, "test/subtest");
        RL(rump_sys_rmdir(pb));
-       md(pb, mp, "test");
+       md(pb, sizeof(pb), mp, "test");
        RL(rump_sys_rmdir(pb));
 
        if (FSTYPE_NFS(tc))
@@ -225,7 +225,7 @@
        struct stat sb;
        static int n = 1;
 
-       md(buf, path, "file");
+       md(buf, sizeof(buf), path, "file");
        if (rump_sys_stat(buf, &sb) == -1)
                atf_tc_fail_errno("cannot stat file %d (%s)", n, buf);
        if (memcmp(&sb, refp, sizeof(sb)) != 0)
@@ -244,18 +244,18 @@
 
        USES_DIRS;
 
-       md(pb1, mp, "dir1");
+       md(pb1, sizeof(pb1), mp, "dir1");
        if (rump_sys_mkdir(pb1, 0777) == -1)
                atf_tc_fail_errno("mkdir 1");
 
-       md(pb2, mp, "dir2");
+       md(pb2, sizeof(pb2), mp, "dir2");
        if (rump_sys_mkdir(pb2, 0777) == -1)
                atf_tc_fail_errno("mkdir 2");
-       md(pb2, mp, "dir2/subdir");
+       md(pb2, sizeof(pb2), mp, "dir2/subdir");
        if (rump_sys_mkdir(pb2, 0777) == -1)
                atf_tc_fail_errno("mkdir 3");
 
-       md(pb3, mp, "dir1/file");
+       md(pb3, sizeof(pb3), mp, "dir1/file");
        if (rump_sys_mknod(pb3, S_IFREG | 0777, -1) == -1)
                atf_tc_fail_errno("create file");
        if (rump_sys_stat(pb3, &ref) == -1)
@@ -266,13 +266,13 @@
         */
 
        /* rename within directory */
-       md(pb3, mp, "dir3");
+       md(pb3, sizeof(pb3), mp, "dir3");
        if (rump_sys_rename(pb1, pb3) == -1)
                atf_tc_fail_errno("rename 1");
        checkfile(pb3, &ref);
 
        /* rename directory onto itself (two ways, should fail) */
-       md(pb1, mp, "dir3/.");
+       md(pb1, sizeof(pb1), mp, "dir3/.");
        if (rump_sys_rename(pb1, pb3) != -1 || errno != EINVAL)
                atf_tc_fail_errno("rename 2");
        if (rump_sys_rename(pb3, pb1) != -1 || errno != EISDIR)
@@ -281,13 +281,13 @@
        checkfile(pb3, &ref);
 
        /* rename father of directory into directory */
-       md(pb1, mp, "dir2/dir");
-       md(pb2, mp, "dir2");
+       md(pb1, sizeof(pb1), mp, "dir2/dir");
+       md(pb2, sizeof(pb2), mp, "dir2");
        if (rump_sys_rename(pb2, pb1) != -1 || errno != EINVAL)
                atf_tc_fail_errno("rename 4");
 
        /* same for grandfather */
-       md(pb1, mp, "dir2/subdir/dir2");
+       md(pb1, sizeof(pb1), mp, "dir2/subdir/dir2");
        if (rump_sys_rename(pb2, pb1) != -1 || errno != EINVAL)
                atf_tc_fail("rename 5");
 
@@ -298,29 +298,29 @@
                atf_tc_fail("rename 6");
 
        /* cross-directory rename */
-       md(pb1, mp, "dir3");
-       md(pb2, mp, "dir2/somedir");
+       md(pb1, sizeof(pb1), mp, "dir3");
+       md(pb2, sizeof(pb2), mp, "dir2/somedir");
        if (rump_sys_rename(pb1, pb2) == -1)
                atf_tc_fail_errno("rename 7");
        checkfile(pb2, &ref);
 
        /* move to parent directory */
-       md(pb1, mp, "dir2/somedir/../../dir3");
+       md(pb1, sizeof(pb1), mp, "dir2/somedir/../../dir3");
        if (rump_sys_rename(pb2, pb1) == -1)
                atf_tc_fail_errno("rename 8");
-       md(pb1, mp, "dir2/../dir3");
+       md(pb1, sizeof(pb1), mp, "dir2/../dir3");
        checkfile(pb1, &ref);
 
        /* atomic cross-directory rename */
-       md(pb3, mp, "dir2/subdir");
+       md(pb3, sizeof(pb3), mp, "dir2/subdir");
        if (rump_sys_rename(pb1, pb3) == -1)
                atf_tc_fail_errno("rename 9");
        checkfile(pb3, &ref);
 
        /* rename directory over an empty directory */
-       md(pb1, mp, "parent");
-       md(pb2, mp, "parent/dir1");
-       md(pb3, mp, "parent/dir2");
+       md(pb1, sizeof(pb1), mp, "parent");
+       md(pb2, sizeof(pb2), mp, "parent/dir1");
+       md(pb3, sizeof(pb3), mp, "parent/dir2");
        RL(rump_sys_mkdir(pb1, 0777));
        RL(rump_sys_mkdir(pb2, 0777));
        RL(rump_sys_mkdir(pb3, 0777));
@@ -467,15 +467,15 @@
        for (i = 0; i < nfiles; i++) {
                int fd;
 
-               sprintf(buf, TESTFN "%d", i);
+               snprintf(buf, sizeof(buf), TESTFN "%d", i);
                RL(fd = rump_sys_open(buf, O_RDWR|O_CREAT|O_EXCL, 0666));
                RL(rump_sys_close(fd));
        }
 
        /* wipe them out */
        for (i = 0; i < nfiles; i++) {
-               sprintf(buf, TESTFN "%d", i);
-               RL(rump_sys_unlink(buf));
+               snprintf(buf, sizeof(buf), TESTFN "%d", i);
+               RLF(rump_sys_unlink(buf), "%s", buf);
        }
 #undef TESTFN
 
@@ -499,12 +499,12 @@
 
        for (i = 0; i < 256; i++) {
                int fd;
-               sprintf(buf, "%c", i);
+               snprintf(buf, sizeof(buf), "%c", i);
                fd = rump_sys_open(buf, O_RDWR|O_CREAT|O_EXCL, 0666);
                if (fd == -1)
                        continue;
-               RL(rump_sys_close(fd));
-               RL(rump_sys_unlink(buf));
+               RLF(rump_sys_close(fd), "%d", fd);
+               RLF(rump_sys_unlink(buf), "%s", buf);
        }
        printf("\n");
 
@@ -632,7 +632,7 @@
 
        USES_SYMLINKS;
 
-       RL(rump_sys_chdir(mp));
+       RLF(rump_sys_chdir(mp), "%s", buf);
 
        buf = malloc(len + 1);
        ATF_REQUIRE(buf);



Home | Main Index | Thread Index | Old Index