diff options
author | Stephen Gallagher <sgallagh@redhat.com> | 2012-03-07 09:29:46 -0500 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2012-03-08 08:10:56 -0500 |
commit | 1f9961c46d1d507046e57bb08e0d2e25d77f2d82 (patch) | |
tree | 6ce0e6cae33c3b9b5a92567d47d1d22e0767a83f /path_utils/path_utils_ut.c | |
parent | 030d99cef35962dc78111407218d66215296de4b (diff) | |
download | ding-libs-1f9961c46d1d507046e57bb08e0d2e25d77f2d82.tar.gz ding-libs-1f9961c46d1d507046e57bb08e0d2e25d77f2d82.tar.xz ding-libs-1f9961c46d1d507046e57bb08e0d2e25d77f2d82.zip |
path_utils: path_concat should return empty string on ENOBUFS
Also clean up the code a bit and add more comments
Diffstat (limited to 'path_utils/path_utils_ut.c')
-rw-r--r-- | path_utils/path_utils_ut.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/path_utils/path_utils_ut.c b/path_utils/path_utils_ut.c index 34462cf..aadd89b 100644 --- a/path_utils/path_utils_ut.c +++ b/path_utils/path_utils_ut.c @@ -252,24 +252,35 @@ START_TEST(test_path_concat_neg) char small[3]; char small2[5]; char small3[7]; - char p2[9]; + char p2[10]; /* these two test different conditions */ /* Test if head is longer than the buffer */ fail_unless(path_concat(small, 3, "/foo", "bar") == ENOBUFS); + /* On ENOBUFS, path should be empty */ + fail_unless_str_equal(small, ""); /* Test if head is the same length as the buffer */ fail_unless(path_concat(small2, 5, "/foo", "bar") == ENOBUFS); + /* On ENOBUFS, path should be empty */ + fail_unless_str_equal(small2, ""); /* Test if head+tail is the longer than the buffer */ fail_unless(path_concat(small3, 7, "/foo", "bar") == ENOBUFS); + /* On ENOBUFS, path should be empty */ + fail_unless_str_equal(small3, ""); /* off-by-one */ - p2[8] = 1; /* Check whether we've written too far */ + /* Fill with garbage data for now */ + memset(p2, 'Z', 9); + p2[9] = '\0'; + fail_unless(path_concat(p2, 8, "/foo", "bar") == ENOBUFS); - fail_unless(p2[8] == 1); /* This should be untouched */ - fail_unless_str_equal(p2, "/foo/ba"); + /* Make sure we don't write past the end of the buffer */ + fail_unless(p2[8] == 'Z', "Got [%d]", p2[8]); + /* On ENOBUFS, path should be empty */ + fail_unless_str_equal(p2, ""); } END_TEST |