Fix mte build breakage.
The strerror_buf is way too large, so instead of using a separate
buffer for just this string, reuse the already existing buffer.
Increase the buffer size to cover the maximum errno string.
Add a unit test to verify that none of the errno values are cut off
in the async_safe_format_buffer function when passing %m.
Bug: 274474681
Test: New unit test passes.
Test: Changing the buffer to a small value and verify that the test fails.
Change-Id: I4cb4652709582a8a6b958e12de5d923ec950e6b6
diff --git a/libc/async_safe/async_safe_log.cpp b/libc/async_safe/async_safe_log.cpp
index d31fe03..420560f 100644
--- a/libc/async_safe/async_safe_log.cpp
+++ b/libc/async_safe/async_safe_log.cpp
@@ -254,7 +254,7 @@
bool alternate = false;
size_t bytelen = sizeof(int);
int slen;
- char buffer[32]; /* temporary buffer used to format numbers */
+ char buffer[64]; // temporary buffer used to format numbers/format errno string
char c;
@@ -345,7 +345,6 @@
/* conversion specifier */
const char* str = buffer;
- char strerror_buf[256];
if (c == 's') {
/* string */
str = va_arg(args, const char*);
@@ -360,7 +359,7 @@
buffer[1] = 'x';
format_integer(buffer + 2, sizeof(buffer) - 2, value, 'x');
} else if (c == 'm') {
- str = strerror_r(errno, strerror_buf, sizeof(strerror_buf));
+ strerror_r(errno, buffer, sizeof(buffer));
} else if (c == 'd' || c == 'i' || c == 'o' || c == 'u' || c == 'x' || c == 'X') {
/* integers - first read value from stack */
uint64_t value;