Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce verbosity with modern idioms #2

Merged
merged 6 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is okay - I wanted to get rid of the plural for the project. Other non-chain suggestions for library and namespace names?

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