Skip to content
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
35 changes: 17 additions & 18 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
AccessModifierOffset: -2
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignConsecutiveAssignments: None
AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: true
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: false
AlwaysBreakTemplateDeclarations: No
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
Expand All @@ -40,7 +40,7 @@ BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakConstructorInitializersBeforeComma: false
BreakStringLiterals: true
ColumnLimit: 0
ColumnLimit: 180
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
Expand All @@ -52,19 +52,19 @@ DisableFormat: false
ExperimentalAutoDetectBinPacking: true
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeCategories:
- Priority: 2
Regex: ^"(llvm|llvm-c|clang|clang-c)/
- Priority: 3
Regex: ^(<|"(gtest|gmock|isl|json)/)
- Priority: 1
Regex: .*
- Priority: 2
Regex: ^"(llvm|llvm-c|clang|clang-c)/
- Priority: 3
Regex: ^(<|"(gtest|gmock|isl|json)/)
- Priority: 1
Regex: .*
IncludeIsMainRegex: (Test)?$
IndentCaseLabels: false
IndentWidth: 2
IndentWidth: 4
IndentWrappedFunctionNames: true
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
Expand All @@ -79,7 +79,7 @@ ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: false
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SortIncludes: CaseSensitive
SortUsingDeclarations: false
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
Expand All @@ -92,7 +92,6 @@ SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: true
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
Standard: c++20
TabWidth: 8
UseTab: Never

19 changes: 15 additions & 4 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
---
Checks: '*,-fuchsia-*,-google-*,-zircon-*,-abseil-*,-modernize-use-trailing-return-type,-llvm*'
WarningsAsErrors: '*'
Checks: "*,
-abseil-*,
-altera-*,
-android-*,
-fuchsia-*,
-google-*,
-llvm*,
-modernize-use-trailing-return-type,
-zircon-*,
-readability-else-after-return,
-readability-static-accessed-through-instance,
-readability-avoid-const-params-in-decls,
-cppcoreguidelines-non-private-member-variables-in-classes,
-misc-non-private-member-variables-in-classes,
"
HeaderFilterRegex: ''
FormatStyle: none


109 changes: 54 additions & 55 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,91 +1,90 @@
cmake_minimum_required(VERSION 3.15)
CMAKE_MINIMUM_REQUIRED(VERSION 3.15)
Comment thread
arnemertz marked this conversation as resolved.

# Set the project name to your project name, my project isn't very descriptive
project(myproject
PROJECT(myproject
LANGUAGES CXX
VERSION 0.0.1)

include(cmake/StandardProjectSettings.cmake)
include(cmake/PreventInSourceBuilds.cmake)
include(cmake/CodeFormat.cmake)
INCLUDE(cmake/StandardProjectSettings.cmake)
INCLUDE(cmake/PreventInSourceBuilds.cmake)
INCLUDE(cmake/CodeFormat.cmake)

execute_process(
EXECUTE_PROCESS(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

configure_file("templates/version.hpp.in" "${CMAKE_BINARY_DIR}/generated/include/version.hpp" ESCAPE_QUOTES)
CONFIGURE_FILE("templates/version.hpp.in" "${CMAKE_BINARY_DIR}/generated/include/version.hpp" ESCAPE_QUOTES)

# Link this 'library' to set the c++ standard / compile-time options requested
add_library(project_options INTERFACE)
target_compile_features(project_options INTERFACE cxx_std_17)
ADD_LIBRARY(project_options INTERFACE)
TARGET_COMPILE_FEATURES(project_options INTERFACE cxx_std_17)

if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
option(ENABLE_BUILD_WITH_TIME_TRACE "Enable -ftime-trace to generate time tracing .json files on clang" OFF)
if(ENABLE_BUILD_WITH_TIME_TRACE)
target_compile_options(project_options INTERFACE -ftime-trace)
endif()
endif()
IF(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
OPTION(ENABLE_BUILD_WITH_TIME_TRACE "Enable -ftime-trace to generate time tracing .json files on clang" OFF)
IF(ENABLE_BUILD_WITH_TIME_TRACE)
TARGET_COMPILE_OPTIONS(project_options INTERFACE -ftime-trace)
ENDIF()
ENDIF()

# Link this 'library' to use the warnings specified in CompilerWarnings.cmake
add_library(project_warnings INTERFACE)
ADD_LIBRARY(project_warnings INTERFACE)

# enable cache system
include(cmake/Cache.cmake)
INCLUDE(cmake/Cache.cmake)

# standard compiler warnings
include(cmake/CompilerWarnings.cmake)
set_project_warnings(project_warnings)
INCLUDE(cmake/CompilerWarnings.cmake)
SET_PROJECT_WARNINGS(project_warnings)

# sanitizer options if supported by compiler
include(cmake/Sanitizers.cmake)
enable_sanitizers(project_options)
INCLUDE(cmake/Sanitizers.cmake)
ENABLE_SANITIZERS(project_options)

# enable doxygen
include(cmake/Doxygen.cmake)
enable_doxygen()
INCLUDE(cmake/Doxygen.cmake)
ENABLE_DOXYGEN()

# allow for static analysis options
include(cmake/StaticAnalyzers.cmake)
INCLUDE(cmake/StaticAnalyzers.cmake)

option(BUILD_SHARED_LIBS "Enable compilation of shared libraries" OFF)
option(ENABLE_TESTING "Enable Test Builds" ON)
option(ENABLE_FUZZING "Enable Fuzzing Builds" OFF)
OPTION(BUILD_SHARED_LIBS "Enable compilation of shared libraries" OFF)
OPTION(ENABLE_TESTING "Enable Test Builds" ON)
OPTION(ENABLE_FUZZING "Enable Fuzzing Builds" OFF)

# Very basic PCH example
option(ENABLE_PCH "Enable Precompiled Headers" OFF)
if(ENABLE_PCH)
# This sets a global PCH parameter, each project will build its own PCH, which is a good idea if any #define's change
#
# consider breaking this out per project as necessary
target_precompile_headers(
project_options
INTERFACE
<vector>
<string>
<map>
<utility>)
endif()
OPTION(ENABLE_PCH "Enable Precompiled Headers" OFF)
IF(ENABLE_PCH)
# This sets a global PCH parameter, each project will build its own PCH, which is a good idea if any #define's change
#
# consider breaking this out per project as necessary
TARGET_PRECOMPILE_HEADERS(
project_options
INTERFACE
<vector>
<string>
<map>
<utility>)
ENDIF()

# Set up some extra Conan dependencies based on our needs before loading Conan
set(CONAN_EXTRA_REQUIRES "")
set(CONAN_EXTRA_OPTIONS "")
SET(CONAN_EXTRA_REQUIRES "")
SET(CONAN_EXTRA_OPTIONS "")

include(cmake/Conan.cmake)
run_conan()
INCLUDE(cmake/Conan.cmake)
RUN_CONAN()

if(ENABLE_TESTING)
enable_testing()
message("Building Tests. Be sure to check out test/constexpr_tests for constexpr testing")
add_subdirectory(test)
endif()
IF(ENABLE_TESTING)
ENABLE_TESTING()
MESSAGE("Building Tests. Be sure to check out test/constexpr_tests for constexpr testing")
ADD_SUBDIRECTORY(test)
ENDIF()

if(ENABLE_FUZZING)
message("Building Fuzz Tests, using fuzzing sanitizer https://www.llvm.org/docs/LibFuzzer.html")
add_subdirectory(fuzz_test)
endif()

add_subdirectory(src)
IF(ENABLE_FUZZING)
MESSAGE("Building Fuzz Tests, using fuzzing sanitizer https://www.llvm.org/docs/LibFuzzer.html")
ADD_SUBDIRECTORY(fuzz_test)
ENDIF()

ADD_SUBDIRECTORY(src)
22 changes: 11 additions & 11 deletions fuzz_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# A fuzz test runs until it finds an error. This particular one is going to rely on libFuzzer.
#

add_executable(fuzz_tester fuzz_tester.cpp)
target_link_libraries(
fuzz_tester
PRIVATE project_options
project_warnings
CONAN_PKG::fmt
-coverage
-fsanitize=fuzzer,undefined,address)
target_compile_options(fuzz_tester PRIVATE -fsanitize=fuzzer,undefined,address)
ADD_EXECUTABLE(fuzz_tester fuzz_tester.cpp)
TARGET_LINK_LIBRARIES(
fuzz_tester
PRIVATE project_options
project_warnings
CONAN_PKG::fmt
-coverage
-fsanitize=fuzzer,undefined,address)
TARGET_COMPILE_OPTIONS(fuzz_tester PRIVATE -fsanitize=fuzzer,undefined,address)

# Allow short runs during automated testing to see if something new breaks
set(FUZZ_RUNTIME
SET(FUZZ_RUNTIME
10
CACHE STRING "Number of seconds to run fuzz tests during ctest run") # Default of 10 seconds

add_test(NAME fuzz_tester_run COMMAND fuzz_tester -max_total_time=${FUZZ_RUNTIME})
ADD_TEST(NAME fuzz_tester_run COMMAND fuzz_tester -max_total_time=${FUZZ_RUNTIME})
16 changes: 7 additions & 9 deletions fuzz_test/fuzz_tester.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
#include <fmt/format.h>
#include <iterator>
#include <utility>
#include <fmt/format.h>

[[nodiscard]] auto sum_values(const uint8_t *Data, size_t Size)
{
constexpr auto scale = 1000;
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;
fmt::print("Value sum: {}, len{}\n", sum_values(Data, Size), Size);
return 0;
}
4 changes: 2 additions & 2 deletions src/boost.beast/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ struct person
{
std::string name;
std::string address;
int age = {0};
int id = {0};
int age = { 0 };
int id = { 0 };
};

inline void to_json(nlohmann::json &j, const person &p) { j = nlohmann::json{ { "name", p.name }, { "address", p.address }, { "age", p.age }, { "id", p.id } }; }
Expand Down
4 changes: 2 additions & 2 deletions src/boost.beast/error_handling.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once
#include <boost/asio/dispatch.hpp>
#include <boost/asio/strand.hpp>
#include <boost/beast/core.hpp>
#include <boost/beast/http.hpp>
#include <boost/beast/version.hpp>
#include <boost/asio/dispatch.hpp>
#include <boost/asio/strand.hpp>
#include <fmt/format.h>

// from <boost/beast.hpp>
Expand Down
21 changes: 7 additions & 14 deletions src/boost.beast/listener.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "error_handling.h"
#include "data.h"
#include "error_handling.h"
#include "session.h"

// Accepts incoming connections and launches the sessions
Expand All @@ -13,32 +13,28 @@ class Listener : public std::enable_shared_from_this<Listener>

// Open the acceptor
m_acceptor.open(endpoint.protocol(), ec);
if (ec)
{
if (ec) {
fail(ec, "open");
return;
}

// Allow address reuse
m_acceptor.set_option(asio::socket_base::reuse_address(true), ec);
if (ec)
{
if (ec) {
fail(ec, "set_option");
return;
}

// Bind to the server address
m_acceptor.bind(endpoint, ec);
if (ec)
{
if (ec) {
fail(ec, "bind");
return;
}

// Start listening for connections
m_acceptor.listen(asio::socket_base::max_listen_connections, ec);
if (ec)
{
if (ec) {
fail(ec, "listen");
return;
}
Expand All @@ -56,12 +52,9 @@ class Listener : public std::enable_shared_from_this<Listener>

void onAccept(beast::error_code ec, tcp::socket socket)
{
if (ec)
{
if (ec) {
fail(ec, "accept");
}
else
{
} else {
// Create the session and run it
std::make_shared<Session>(std::move(socket), m_persons)->run();
}
Expand Down
Loading