aboutsummaryrefslogtreecommitdiff
path: root/libc/src/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'libc/src/stdlib')
-rw-r--r--libc/src/stdlib/CMakeLists.txt6
-rw-r--r--libc/src/stdlib/l64a.cpp6
-rw-r--r--libc/src/stdlib/strfromd.cpp11
-rw-r--r--libc/src/stdlib/strfromf.cpp11
-rw-r--r--libc/src/stdlib/strfroml.cpp11
5 files changed, 38 insertions, 7 deletions
diff --git a/libc/src/stdlib/CMakeLists.txt b/libc/src/stdlib/CMakeLists.txt
index c464f82..1ccdcc8 100644
--- a/libc/src/stdlib/CMakeLists.txt
+++ b/libc/src/stdlib/CMakeLists.txt
@@ -73,6 +73,8 @@ add_entrypoint_object(
strfromf.h
DEPENDS
.str_from_util
+ libc.src.__support.CPP.limits
+ libc.src.stdio.printf_core.error_mapper
)
add_entrypoint_object(
@@ -83,6 +85,8 @@ add_entrypoint_object(
strfromd.h
DEPENDS
.str_from_util
+ libc.src.__support.CPP.limits
+ libc.src.stdio.printf_core.error_mapper
)
add_entrypoint_object(
@@ -93,6 +97,8 @@ add_entrypoint_object(
strfroml.h
DEPENDS
.str_from_util
+ libc.src.__support.CPP.limits
+ libc.src.stdio.printf_core.error_mapper
)
add_header_library(
diff --git a/libc/src/stdlib/l64a.cpp b/libc/src/stdlib/l64a.cpp
index d59e65e..d8fe8ef 100644
--- a/libc/src/stdlib/l64a.cpp
+++ b/libc/src/stdlib/l64a.cpp
@@ -32,15 +32,13 @@ constexpr static char b64_int_to_char(uint32_t num) {
if (num == 1)
return '/';
if (num < 38)
- return static_cast<char>(
- internal::toupper(internal::int_to_b36_char(num - 2)));
+ return internal::toupper(internal::int_to_b36_char(num - 2));
// this tolower is technically unnecessary, but it provides safety if we
// change the default behavior of int_to_b36_char. Also the compiler
// completely elides it so there's no performance penalty, see:
// https://godbolt.org/z/o5ennv7fc
- return static_cast<char>(
- internal::tolower(internal::int_to_b36_char(num - 2 - 26)));
+ return internal::tolower(internal::int_to_b36_char(num - 2 - 26));
}
// This function takes a long and converts the low 32 bits of it into at most 6
diff --git a/libc/src/stdlib/strfromd.cpp b/libc/src/stdlib/strfromd.cpp
index f51e6d4..71e257f 100644
--- a/libc/src/stdlib/strfromd.cpp
+++ b/libc/src/stdlib/strfromd.cpp
@@ -7,7 +7,10 @@
//===----------------------------------------------------------------------===//
#include "src/stdlib/strfromd.h"
+#include "src/__support/CPP/limits.h"
#include "src/__support/macros/config.h"
+#include "src/stdio/printf_core/core_structs.h"
+#include "src/stdio/printf_core/error_mapper.h"
#include "src/stdlib/str_from_util.h"
namespace LIBC_NAMESPACE_DECL {
@@ -36,7 +39,13 @@ LLVM_LIBC_FUNCTION(int, strfromd,
if (n > 0)
wb.buff[wb.buff_cur] = '\0';
- return writer.get_chars_written();
+ if (writer.get_chars_written() >
+ static_cast<size_t>(cpp::numeric_limits<int>::max())) {
+ libc_errno =
+ printf_core::internal_error_to_errno(-printf_core::OVERFLOW_ERROR);
+ return -1;
+ }
+ return static_cast<int>(writer.get_chars_written());
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdlib/strfromf.cpp b/libc/src/stdlib/strfromf.cpp
index 14dbfdb..65f242b 100644
--- a/libc/src/stdlib/strfromf.cpp
+++ b/libc/src/stdlib/strfromf.cpp
@@ -7,7 +7,10 @@
//===----------------------------------------------------------------------===//
#include "src/stdlib/strfromf.h"
+#include "src/__support/CPP/limits.h"
#include "src/__support/macros/config.h"
+#include "src/stdio/printf_core/core_structs.h"
+#include "src/stdio/printf_core/error_mapper.h"
#include "src/stdlib/str_from_util.h"
namespace LIBC_NAMESPACE_DECL {
@@ -36,7 +39,13 @@ LLVM_LIBC_FUNCTION(int, strfromf,
if (n > 0)
wb.buff[wb.buff_cur] = '\0';
- return writer.get_chars_written();
+ if (writer.get_chars_written() >
+ static_cast<size_t>(cpp::numeric_limits<int>::max())) {
+ libc_errno =
+ printf_core::internal_error_to_errno(-printf_core::OVERFLOW_ERROR);
+ return -1;
+ }
+ return static_cast<int>(writer.get_chars_written());
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdlib/strfroml.cpp b/libc/src/stdlib/strfroml.cpp
index 12f22a8..31668a0 100644
--- a/libc/src/stdlib/strfroml.cpp
+++ b/libc/src/stdlib/strfroml.cpp
@@ -7,7 +7,10 @@
//===----------------------------------------------------------------------===//
#include "src/stdlib/strfroml.h"
+#include "src/__support/CPP/limits.h"
#include "src/__support/macros/config.h"
+#include "src/stdio/printf_core/core_structs.h"
+#include "src/stdio/printf_core/error_mapper.h"
#include "src/stdlib/str_from_util.h"
namespace LIBC_NAMESPACE_DECL {
@@ -41,7 +44,13 @@ LLVM_LIBC_FUNCTION(int, strfroml,
if (n > 0)
wb.buff[wb.buff_cur] = '\0';
- return writer.get_chars_written();
+ if (writer.get_chars_written() >
+ static_cast<size_t>(cpp::numeric_limits<int>::max())) {
+ libc_errno =
+ printf_core::internal_error_to_errno(-printf_core::OVERFLOW_ERROR);
+ return -1;
+ }
+ return static_cast<int>(writer.get_chars_written());
}
} // namespace LIBC_NAMESPACE_DECL