diff --git a/libc/include/bits/fortify/stdlib.h b/libc/include/bits/fortify/stdlib.h index 0bb3d0d66..623be583b 100644 --- a/libc/include/bits/fortify/stdlib.h +++ b/libc/include/bits/fortify/stdlib.h @@ -36,10 +36,11 @@ #define __PATH_MAX 4096 char* realpath(const char* path, char* resolved) + __clang_error_if(!path, "'realpath': NULL path is never correct; flipped arguments?") __clang_error_if(__bos_unevaluated_lt(__bos(resolved), __PATH_MAX), "'realpath' output parameter must be NULL or a pointer to a buffer " - "with >= PATH_MAX bytes") - __clang_error_if(!path, "'realpath': NULL path is never correct; flipped arguments?"); + "with >= PATH_MAX bytes"); + /* No need for a definition; the only issues we can catch are at compile-time. */ #undef __PATH_MAX diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h index d5b861983..b66e3c64e 100644 --- a/libc/include/stdlib.h +++ b/libc/include/stdlib.h @@ -90,7 +90,7 @@ int atoi(const char* __s) __attribute_pure__; long atol(const char* __s) __attribute_pure__; long long atoll(const char* __s) __attribute_pure__; -char* realpath(const char* __path, char* __resolved); +__wur char* realpath(const char* __path, char* __resolved); int system(const char* __command); void* bsearch(const void* __key, const void* __base, size_t __nmemb, size_t __size, int (*__comparator)(const void* __lhs, const void* __rhs)); diff --git a/tests/clang_fortify_tests.cpp b/tests/clang_fortify_tests.cpp index 4c4e51024..8b90df460 100644 --- a/tests/clang_fortify_tests.cpp +++ b/tests/clang_fortify_tests.cpp @@ -391,20 +391,17 @@ static void testFormatStrings() { static void testStdlib() { char path_buffer[PATH_MAX - 1]; -#if 0 - // expected-error@+2{{ignoring return value of function}} -#endif + // expected-warning@+2{{ignoring return value of function}} // expected-error@+1{{must be NULL or a pointer to a buffer with >= PATH_MAX bytes}} realpath("/", path_buffer); -#if 0 - // expected-error@+1{{ignoring return value of function}} -#endif + // expected-warning@+1{{ignoring return value of function}} realpath("/", nullptr); - // FIXME: This should complain about flipped arguments, instead of objectsize. - // expected-error@+1{{must be NULL or a pointer to a buffer with >= PATH_MAX bytes}} + // expected-warning@+2{{ignoring return value of function}} + // expected-error@+1{{flipped arguments?}} realpath(nullptr, path_buffer); + // expected-warning@+2{{ignoring return value of function}} // expected-error@+1{{flipped arguments?}} realpath(nullptr, nullptr); }