Skip to content

Commit 2b5ce43

Browse files
committed
Test the null string and add length in fuzz file
1 parent 8218b96 commit 2b5ce43

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

fuzzing/fuzz_from_chars_float.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, std::size_t size
2828
}
2929

3030
// Now with strings
31-
const auto c_data_str = std::string(c_data);
31+
const auto c_data_str = std::string(c_data, size);
3232
for (const auto format : formats)
3333
{
3434
boost::decimal::decimal32 f_val;

test/test_from_chars.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,20 @@ void test_string_interface()
325325
constexpr T correct_val {42};
326326
std::string str {"42"};
327327
T val;
328-
const auto r = from_chars(str, val);
328+
auto r = from_chars(str, val);
329329
BOOST_TEST(r);
330330
BOOST_TEST_EQ(val, correct_val);
331+
332+
// Empty string
333+
std::string empty;
334+
r = from_chars(empty, val);
335+
BOOST_TEST(r.ec == std::errc::invalid_argument);
336+
337+
#ifdef BOOST_DECIMAL_HAS_STD_STRING_VIEW
338+
std::string_view empty_view = std::string_view(empty);
339+
r = from_chars(empty_view, val);
340+
BOOST_TEST(r.ec == std::errc::invalid_argument);
341+
#endif
331342
}
332343

333344
int main()

0 commit comments

Comments
 (0)