Various coverage improvements.
Mostly from extra test cases, but also:
* Move the fgets size < 0 assertion into fgets.
* Use ELF aliases for strtoq/strtouq rather than duplicating code.
* Don't check uname() succeeded, since it can't fail.
Test: treehugger
Change-Id: I2e6b3b88b0a3eb16bd68be68b9bc9f40d8043291
diff --git a/libc/bionic/fortify.cpp b/libc/bionic/fortify.cpp
index 3b804b0..88ae477 100644
--- a/libc/bionic/fortify.cpp
+++ b/libc/bionic/fortify.cpp
@@ -94,9 +94,6 @@
}
char* __fgets_chk(char* dst, int supplied_size, FILE* stream, size_t dst_len_from_compiler) {
- if (supplied_size < 0) {
- __fortify_fatal("fgets: buffer size %d < 0", supplied_size);
- }
__check_buffer_access("fgets", "write into", supplied_size, dst_len_from_compiler);
return fgets(dst, supplied_size, stream);
}
diff --git a/libc/bionic/gethostname.cpp b/libc/bionic/gethostname.cpp
index 962fea1..b780a2f 100644
--- a/libc/bionic/gethostname.cpp
+++ b/libc/bionic/gethostname.cpp
@@ -32,10 +32,8 @@
#include <unistd.h>
int gethostname(char* buf, size_t n) {
- struct utsname name;
- if (uname(&name) == -1) {
- return -1;
- }
+ utsname name = {};
+ uname(&name);
size_t name_length = static_cast<size_t>(strlen(name.nodename) + 1);
if (name_length > n) {
diff --git a/libc/bionic/strtol.cpp b/libc/bionic/strtol.cpp
index 63ac102..77f1d92 100644
--- a/libc/bionic/strtol.cpp
+++ b/libc/bionic/strtol.cpp
@@ -184,9 +184,7 @@
}
// Public API since L, but not in any header.
-extern "C" long long strtoq(const char* s, char** end, int base) {
- return strtoll(s, end, base);
-}
+__strong_alias(strtoq, strtoll);
unsigned long strtoul(const char* s, char** end, int base) {
return StrToU<unsigned long, ULONG_MAX>(s, end, base);
@@ -201,6 +199,4 @@
}
// Public API since L, but not in any header.
-extern "C" unsigned long long strtouq(const char* s, char** end, int base) {
- return strtoull(s, end, base);
-}
+__strong_alias(strtouq, strtoull);
diff --git a/libc/stdio/stdio.cpp b/libc/stdio/stdio.cpp
index afc2c48..b8aced8 100644
--- a/libc/stdio/stdio.cpp
+++ b/libc/stdio/stdio.cpp
@@ -773,10 +773,7 @@
// Returns first argument, or nullptr if no characters were read.
// Does not return nullptr if n == 1.
char* fgets_unlocked(char* buf, int n, FILE* fp) {
- if (n <= 0) {
- errno = EINVAL;
- return nullptr;
- }
+ if (n <= 0) __fortify_fatal("fgets: buffer size %d <= 0", n);
_SET_ORIENTATION(fp, -1);