Module Name:    src
Committed By:   christos
Date:           Sat Aug 20 15:48:18 UTC 2016

Modified Files:
        src/tests/fs/vfs: t_vnops.c

Log Message:
- use snprintf
- print the argument that caused the error


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/tests/fs/vfs/t_vnops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/fs/vfs/t_vnops.c
diff -u src/tests/fs/vfs/t_vnops.c:1.55 src/tests/fs/vfs/t_vnops.c:1.56
--- src/tests/fs/vfs/t_vnops.c:1.55	Thu Jan 28 05:10:09 2016
+++ src/tests/fs/vfs/t_vnops.c	Sat Aug 20 11:48:18 2016
@@ -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 @@ lookup_simple(const atf_tc_t *tc, const 
 	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 @@ lookup_complex(const atf_tc_t *tc, const
 	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 @@ dir_simple(const atf_tc_t *tc, const cha
 	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 @@ dir_notempty(const atf_tc_t *tc, const c
 	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 @@ dir_rmdirdotdot(const atf_tc_t *tc, cons
 	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 @@ checkfile(const char *path, struct stat 
 	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 @@ rename_dir(const atf_tc_t *tc, const cha
 
 	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_dir(const atf_tc_t *tc, const cha
 	 */
 
 	/* 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 @@ rename_dir(const atf_tc_t *tc, const cha
 	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 @@ rename_dir(const atf_tc_t *tc, const cha
 		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 @@ create_many(const atf_tc_t *tc, const ch
 	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 @@ create_nonalphanum(const atf_tc_t *tc, c
 
 	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 @@ symlink_len(const atf_tc_t *tc, const ch
 
 	USES_SYMLINKS;
 
-	RL(rump_sys_chdir(mp));
+	RLF(rump_sys_chdir(mp), "%s", buf);
 
 	buf = malloc(len + 1);
 	ATF_REQUIRE(buf);

Reply via email to