Skip to content

Commit

Permalink
add fuzzing test
Browse files Browse the repository at this point in the history
  • Loading branch information
phlptp committed Oct 23, 2023
1 parent c857f1c commit 1118dd8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
Binary file added test/files/fuzz_issues/crash28
Binary file not shown.
2 changes: 1 addition & 1 deletion test/fuzz_issue_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ TEST_P(crashProblems, crashFiles)
EXPECT_NO_THROW(unit_from_string(cdata));
}

INSTANTIATE_TEST_SUITE_P(crashFiles, crashProblems, ::testing::Range(1, 28));
INSTANTIATE_TEST_SUITE_P(crashFiles, crashProblems, ::testing::Range(1, 29));

TEST(fuzzFailures, timeouts)
{ // testing string that have caused a timeout from fuzz testing
Expand Down
5 changes: 5 additions & 0 deletions units/commodity_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace commodities {
((digit) ? 0x1000000U : 0U);
}

// NOLINTBEGIN(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
template<size_t N>
constexpr std::uint32_t generateStringCode(const char (&code)[N])
{
Expand All @@ -58,6 +59,7 @@ namespace commodities {
(((code[3] - '@') & 0X1FU) << 5U) + ((code[4] - '@') & 0X1FU);
}

// NOLINTEND(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
template<size_t N>
constexpr std::uint32_t generateShareCode(const char (&code)[N])
{
Expand All @@ -79,6 +81,8 @@ namespace commodities {
return 0x20000000U + (((code & 0x7FU) + 0x80U) << 21U);
}

// NOLINTBEGIN(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)

template<size_t N>
constexpr std::uint32_t generateCurrencyCode(const char (&code)[N])
{
Expand All @@ -94,6 +98,7 @@ namespace commodities {
(((code[1] - ' ') & 0X3FU) << 12U) +
(((code[2] - ' ') & 0X3FU) << 6U) + ((code[3] - ' ') & 0X3FU);
}
// NOLINTEND(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)

namespace packaging {
/** Enumeration of potential packaging/form factor modifiers
Expand Down
2 changes: 1 addition & 1 deletion units/units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3564,7 +3564,7 @@ static bool isolatePriorModifier(
++offset;
}
auto kloc = unit_string.find_first_not_of(' ', offset);
if (unit_string[kloc] == check1 || unit_string[kloc] == check2) {
if(kloc!=std::string::npos && (unit_string[kloc] == check1 || unit_string[kloc] == check2)) {
// this handles a misinterpretation of square+d to squared when in
// middle of a unit
unit_string[kloc - 1] = '_';
Expand Down

0 comments on commit 1118dd8

Please sign in to comment.