Fix error condition on strtof inline.
Test: make checkbuild
Test: pull into ndk, ./run_tests.py
Bug: https://github.com/android-ndk/ndk/issues/415
Change-Id: I1575f799c9e849d66456c785208a36709a7b8122
diff --git a/libc/include/android/legacy_stdlib_inlines.h b/libc/include/android/legacy_stdlib_inlines.h
index 82186c7..e26e5f2 100644
--- a/libc/include/android/legacy_stdlib_inlines.h
+++ b/libc/include/android/legacy_stdlib_inlines.h
@@ -29,6 +29,8 @@
#ifndef _ANDROID_LEGACY_STDLIB_INLINES_H_
#define _ANDROID_LEGACY_STDLIB_INLINES_H_
+#include <errno.h>
+#include <float.h>
#include <stdlib.h>
#include <sys/cdefs.h>
@@ -36,10 +38,16 @@
__BEGIN_DECLS
-__noreturn void _Exit(int) __RENAME(_exit);
-
-static __inline float strtof(const char *nptr, char **endptr) {
- return (float)strtod(nptr, endptr);
+static __inline float strtof(const char* nptr, char** endptr) {
+ double d = strtod(nptr, endptr);
+ if (d > FLT_MAX) {
+ errno = ERANGE;
+ return __builtin_huge_valf();
+ } else if (d < -FLT_MAX) {
+ errno = ERANGE;
+ return -__builtin_huge_valf();
+ }
+ return __BIONIC_CAST(static_cast, float, d);
}
static __inline double atof(const char *nptr) { return (strtod(nptr, NULL)); }