libc/Android.bp: more cleanup.
These files were segregated because they were lacking a little cleanup.
Unfortunately that means this change has to do some of the cleanup, but
that's probably for the best.
Test: treehugger
Change-Id: I2dd33504787fc3313995de99e0745a0df22915b3
diff --git a/libc/stdio/local.h b/libc/stdio/local.h
index a5eb636..62efea1 100644
--- a/libc/stdio/local.h
+++ b/libc/stdio/local.h
@@ -236,7 +236,7 @@
/* OpenBSD exposes these in <stdio.h>, but we only want them exposed to the implementation. */
#define __sferror(p) (((p)->_flags & __SERR) != 0)
#define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR | __SEOF)))
-#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
+#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : __BIONIC_CAST(static_cast, int, *(p)->_p++))
/* OpenBSD declares these in fvwrite.h, but we share them with C++ parts of the implementation. */
struct __siov {
@@ -288,7 +288,7 @@
char* __hldtoa(long double, const char*, int, int*, int*, char**);
char* __ldtoa(long double*, int, int, int*, int*, char**);
-#define WCIO_GET(fp) (_EXT(fp) ? &(_EXT(fp)->_wcio) : (struct wchar_io_data*)0)
+#define WCIO_GET(fp) (_EXT(fp) ? &(_EXT(fp)->_wcio) : NULL)
#define ORIENT_BYTES (-1)
#define ORIENT_UNKNOWN 0
diff --git a/libc/stdio/scanf_common.h b/libc/stdio/scanf_common.h
index 8132e90..1b6b87f 100644
--- a/libc/stdio/scanf_common.h
+++ b/libc/stdio/scanf_common.h
@@ -82,7 +82,7 @@
#define CT_FLOAT 4 // Float: strtod
#define to_digit(c) static_cast<int>((c) - '0')
-#define is_digit(c) ((unsigned)to_digit(c) <= 9)
+#define is_digit(c) (static_cast<unsigned>(to_digit(c)) <= 9)
// Append a digit to a value and check for overflow.
#define APPEND_DIGIT(val, dig) \
@@ -112,4 +112,4 @@
__fortify_fatal("%%w%s%d is unsupported", fast ? "f" : "", size);
}
-#pragma clang diagnostic pop
\ No newline at end of file
+#pragma clang diagnostic pop
diff --git a/libc/stdio/vfscanf.cpp b/libc/stdio/vfscanf.cpp
index 3607995..92ff541 100644
--- a/libc/stdio/vfscanf.cpp
+++ b/libc/stdio/vfscanf.cpp
@@ -629,10 +629,10 @@
* as `[-+]0`.
*/
if (flags & NDIGITS) {
- if (p > buf) (void)ungetc(*(u_char*)--p, fp);
+ if (p > buf) ungetc(*reinterpret_cast<u_char*>(--p), fp);
goto match_failure;
}
- c = ((u_char*)p)[-1];
+ c = reinterpret_cast<u_char*>(p)[-1];
if ((base == 2 && (c == 'b' || c == 'B')) || c == 'x' || c == 'X') {
--p;
(void)ungetc(c, fp);
@@ -647,7 +647,7 @@
res = strtoimax(buf, nullptr, base);
}
if (flags & POINTER) {
- *va_arg(ap, void**) = (void*)(uintptr_t)res;
+ *va_arg(ap, void**) = reinterpret_cast<void*>(res);
} else if (flags & MAXINT) {
*va_arg(ap, intmax_t*) = res;
} else if (flags & LLONG) {
@@ -685,7 +685,7 @@
float res = strtof(buf, &p);
*va_arg(ap, float*) = res;
}
- if ((size_t)(p - buf) != width) abort();
+ if (static_cast<size_t>(p - buf) != width) abort();
nassigned++;
}
nread += width;
diff --git a/libc/stdio/vfwscanf.cpp b/libc/stdio/vfwscanf.cpp
index 3df4a87..21d1783 100644
--- a/libc/stdio/vfwscanf.cpp
+++ b/libc/stdio/vfwscanf.cpp
@@ -32,6 +32,7 @@
*/
#include "scanf_common.h"
+
// An interpretive version of __sccl from vfscanf.c --- a table of all wchar_t values would
// be a little too expensive, and some kind of compressed version isn't worth the trouble.
static inline bool in_ccl(wchar_t wc, const wchar_t* ccl) {
@@ -335,7 +336,7 @@
if (!(flags & SUPPRESS)) p = va_arg(ap, wchar_t*);
n = 0;
while (width-- != 0 && (wi = __fgetwc_unlock(fp)) != WEOF) {
- if (!(flags & SUPPRESS)) *p++ = (wchar_t)wi;
+ if (!(flags & SUPPRESS)) *p++ = static_cast<wchar_t>(wi);
n++;
}
if (n == 0) goto input_failure;
@@ -348,10 +349,10 @@
while (width != 0 && (wi = __fgetwc_unlock(fp)) != WEOF) {
if (width >= MB_CUR_MAX && !(flags & SUPPRESS)) {
nconv = wcrtomb(mbp, wi, &mbs);
- if (nconv == (size_t)-1) goto input_failure;
+ if (nconv == static_cast<size_t>(-1)) goto input_failure;
} else {
nconv = wcrtomb(mbbuf, wi, &mbs);
- if (nconv == (size_t)-1) goto input_failure;
+ if (nconv == static_cast<size_t>(-1)) goto input_failure;
if (nconv > width) {
__ungetwc(wi, fp);
break;
@@ -373,7 +374,7 @@
case CT_STRING:
// CT_CCL: scan a (nonempty) character class (sets NOSKIP).
// CT_STRING: like CCL, but zero-length string OK, & no NOSKIP.
- if (width == 0) width = (size_t)~0; // 'infinity'.
+ if (width == 0) width = SIZE_MAX; // 'infinity'.
if ((flags & SUPPRESS) && (flags & LONG)) {
n = 0;
while ((wi = __fgetwc_unlock(fp)) != WEOF && width-- != 0 && ((c == CT_CCL && in_ccl(wi, ccl)) || (c == CT_STRING && !iswspace(wi)))) n++;
@@ -381,7 +382,7 @@
} else if (flags & LONG) {
p0 = p = va_arg(ap, wchar_t*);
while ((wi = __fgetwc_unlock(fp)) != WEOF && width-- != 0 && ((c == CT_CCL && in_ccl(wi, ccl)) || (c == CT_STRING && !iswspace(wi)))) {
- *p++ = (wchar_t)wi;
+ *p++ = static_cast<wchar_t>(wi);
}
if (wi != WEOF) __ungetwc(wi, fp);
n = p - p0;
@@ -392,10 +393,10 @@
while ((wi = __fgetwc_unlock(fp)) != WEOF && width != 0 && ((c == CT_CCL && in_ccl(wi, ccl)) || (c == CT_STRING && !iswspace(wi)))) {
if (width >= MB_CUR_MAX && !(flags & SUPPRESS)) {
nconv = wcrtomb(mbp, wi, &mbs);
- if (nconv == (size_t)-1) goto input_failure;
+ if (nconv == static_cast<size_t>(-1)) goto input_failure;
} else {
nconv = wcrtomb(mbbuf, wi, &mbs);
- if (nconv == (size_t)-1) goto input_failure;
+ if (nconv == static_cast<size_t>(-1)) goto input_failure;
if (nconv > width) break;
if (!(flags & SUPPRESS)) memcpy(mbp, mbbuf, nconv);
}
@@ -485,7 +486,7 @@
case 'e':
case 'f':
if (base == 0) base = 10;
- if (base != 16 && (int)(c - '0') >= base) break; /* not legal here */
+ if (base != 16 && static_cast<int>(c - '0') >= base) break; /* not legal here */
flags &= ~(SIGNOK | PFBOK | PFXOK | NDIGITS);
goto ok;
@@ -523,7 +524,7 @@
/*
* c is legal: store it and look at the next.
*/
- *p++ = (wchar_t)c;
+ *p++ = static_cast<wchar_t>(c);
}
/*
* If we had only a sign, it is no good; push back the sign.
@@ -548,7 +549,7 @@
else
res = wcstoumax(buf, NULL, base);
if (flags & POINTER)
- *va_arg(ap, void**) = (void*)(uintptr_t)res;
+ *va_arg(ap, void**) = reinterpret_cast<void*>(res);
else if (flags & MAXINT)
*va_arg(ap, intmax_t*) = res;
else if (flags & LLONG)
@@ -587,7 +588,7 @@
float res = wcstof(buf, &p);
*va_arg(ap, float*) = res;
}
- if (p - buf != (ptrdiff_t)width) abort();
+ if (static_cast<size_t>(p - buf) != width) abort();
nassigned++;
}
nread += width;