diff options
Diffstat (limited to 'src/user')
-rw-r--r-- | src/user/app/tests/kernel/path.c | 2 | ||||
-rw-r--r-- | src/user/lib/include/unistd.h | 3 | ||||
-rw-r--r-- | src/user/lib/unistd.c | 2 |
3 files changed, 5 insertions, 2 deletions
diff --git a/src/user/app/tests/kernel/path.c b/src/user/app/tests/kernel/path.c index 5fb3123..ddaf692 100644 --- a/src/user/app/tests/kernel/path.c +++ b/src/user/app/tests/kernel/path.c @@ -55,7 +55,7 @@ static void test_path_simplify(void) { const char *expected = testcases[i][1]; int len = path_simplify(input, buf, strlen(input)); if (expected == NULL) { - test(len < 0); + test(len == 0); } else { // TODO an argument for printing info on test failure test(len == (int)strlen(expected) && !memcmp(expected, buf, len)); diff --git a/src/user/lib/include/unistd.h b/src/user/lib/include/unistd.h index 1f0c002..59af24b 100644 --- a/src/user/lib/include/unistd.h +++ b/src/user/lib/include/unistd.h @@ -19,6 +19,9 @@ char *getcwd(char *buf, size_t size); * except for the root dir. Includes the null byte. * If size isn't enough to fit the path, returns the amount of bytes needed to fit * it, including the null byte. + * + * Note that some errors are only detected if *out != NULL, so you must check the return + * value twice. * @return 0 on failure, length of the path otherwise */ size_t absolutepath(char *out, const char *in, size_t size); diff --git a/src/user/lib/unistd.c b/src/user/lib/unistd.c index 1a50c3e..ce43551 100644 --- a/src/user/lib/unistd.c +++ b/src/user/lib/unistd.c @@ -163,7 +163,7 @@ size_t absolutepath(char *out, const char *in, size_t size) { if (pos <= size) { pos = path_simplify(out, out, pos); - if (pos > 0) out[pos] = '\0'; + if (pos == 0) return 0; } if (pos + 1 <= size) out[pos] = '\0'; |