Skip to content

Commit

Permalink
Reduce verbosity with modern idioms (#2)
Browse files Browse the repository at this point in the history
* Use CTAD and deduction guides to reduce verbosity of some constructions. Rename namespace chain to chains

* 🎨 Committing clang-format changes

* Use recursive lambda pattern to improve result_type_helper and expand

* 🎨 Committing clang-format changes

* Variadic result type

* 🎨 Committing clang-format changes

---------

Co-authored-by: Clang Robot <[email protected]>
  • Loading branch information
nickpdemarco and Clang Robot authored Feb 22, 2024
1 parent 06baff8 commit ff26876
Show file tree
Hide file tree
Showing 7 changed files with 375 additions and 343 deletions.
22 changes: 10 additions & 12 deletions fuzz_test/fuzz_tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@
#include <iterator>
#include <utility>

[[nodiscard]] auto sum_values(const uint8_t *Data, size_t Size)
{
constexpr auto scale = 1000;
[[nodiscard]] auto sum_values(const uint8_t* Data, size_t Size) {
constexpr auto scale = 1000;

int value = 0;
for (std::size_t offset = 0; offset < Size; ++offset) {
value += static_cast<int>(*std::next(Data, static_cast<long>(offset))) * scale;
}
return value;
int value = 0;
for (std::size_t offset = 0; offset < Size; ++offset) {
value += static_cast<int>(*std::next(Data, static_cast<long>(offset))) * scale;
}
return value;
}

// Fuzzer that attempts to invoke undefined behavior for signed integer overflow
// cppcheck-suppress unusedFunction symbolName=LLVMFuzzerTestOneInput
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
{
fmt::print("Value sum: {}, len{}\n", sum_values(Data, Size), Size);
return 0;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) {
fmt::print("Value sum: {}, len{}\n", sum_values(Data, Size), Size);
return 0;
}
9 changes: 5 additions & 4 deletions include/chains/sample_library.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

[[nodiscard]] SAMPLE_LIBRARY_EXPORT int factorial(int) noexcept;

[[nodiscard]] constexpr int factorial_constexpr(int input) noexcept
{
if (input == 0) { return 1; }
[[nodiscard]] constexpr int factorial_constexpr(int input) noexcept {
if (input == 0) {
return 1;
}

return input * factorial_constexpr(input - 1);
return input * factorial_constexpr(input - 1);
}

#endif
4 changes: 2 additions & 2 deletions include/chains/tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef CHAIN_TUPLE_HPP
#define CHAIN_TUPLE_HPP

namespace chain::inline v0 {
namespace chains::inline v0 {

namespace detail {

Expand Down Expand Up @@ -58,7 +58,7 @@ auto tuple_compose(std::tuple<Fs...>&& sequence) {

//--------------------------------------------------------------------------------------------------

} // namespace chain::inline v0
} // namespace chains::inline v0

//--------------------------------------------------------------------------------------------------

Expand Down
Loading

0 comments on commit ff26876

Please sign in to comment.