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

Fixed compilation errors #100

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ CMakeUserPresets.json
_ReSharper*
*.log

# Clangd files
.cache/

# OS Generated Files
.DS_Store
.AppleDouble
Expand Down
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.21)
# manual dependency management

# Only set the cxx_standard if it is not set by someone else
if (NOT DEFINED CMAKE_CXX_STANDARD)
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 20)
endif()

Expand All @@ -25,7 +25,6 @@ project(
include(cmake/PreventInSourceBuilds.cmake)
include(ProjectOptions.cmake)


myproject_setup_options()

myproject_global_options()
Expand Down Expand Up @@ -73,10 +72,9 @@ if(BUILD_TESTING)
add_subdirectory(test)
endif()


if(myproject_BUILD_FUZZ_TESTS)
message(AUTHOR_WARNING "Building Fuzz Tests, using fuzzing sanitizer https://www.llvm.org/docs/LibFuzzer.html")
if (NOT myproject_ENABLE_ADDRESS_SANITIZER AND NOT myproject_ENABLE_THREAD_SANITIZER)
if(NOT myproject_ENABLE_ADDRESS_SANITIZER AND NOT myproject_ENABLE_THREAD_SANITIZER)
message(WARNING "You need asan or tsan enabled for meaningful fuzz testing")
endif()
add_subdirectory(fuzz_test)
Expand Down
18 changes: 11 additions & 7 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
set(CPM_DOWNLOAD_VERSION 0.38.1)
# SPDX-License-Identifier: MIT
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors

set(CPM_DOWNLOAD_VERSION 0.40.5)
set(CPM_HASH_SUM "c46b876ae3b9f994b4f05a4c15553e0485636862064f1fcc9d8b4f832086bc5d")

if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
Expand All @@ -11,14 +16,14 @@ endif()
# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)

file(DOWNLOAD https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM})

function(download_cpm)
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION}
)
file(DOWNLOAD https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION})
endfunction()

if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
download_cpm()
else()
Expand All @@ -29,5 +34,4 @@ else()
endif()
unset(check)
endif()

include(${CPM_DOWNLOAD_LOCATION})
6 changes: 4 additions & 2 deletions cmake/Hardening.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ macro(
set(NEW_CXX_DEFINITIONS "${NEW_CXX_DEFINITIONS} -D_GLIBCXX_ASSERTIONS")
message(STATUS "*** GLIBC++ Assertions (vector[], string[], ...) enabled")

set(NEW_COMPILE_OPTIONS "${NEW_COMPILE_OPTIONS} -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3")
message(STATUS "*** g++/clang _FORTIFY_SOURCE=3 enabled")
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_CXX_FLAGS MATCHES "-O[123]")
set(NEW_COMPILE_OPTIONS "${NEW_COMPILE_OPTIONS} -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3")
message(STATUS "*** g++/clang _FORTIFY_SOURCE=3 enabled")
endif()

# check_cxx_compiler_flag(-fpie PIE)
#if(PIE)
Expand Down
4 changes: 1 addition & 3 deletions cmake/PackageProject.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ function(myproject_package_project)
# download ycm
FetchContent_Declare(_ycm URL https://github.com/robotology/ycm/archive/refs/tags/v0.13.0.zip)
FetchContent_GetProperties(_ycm)
if(NOT _ycm_POPULATED)
FetchContent_Populate(_ycm)
endif()
FetchContent_MakeAvailable(_ycm)
include("${_ycm_SOURCE_DIR}/modules/InstallBasicPackageFiles.cmake")

install_basic_package_files(${_PackageProject_NAME} "${_FARGS_LIST}")
Expand Down
2 changes: 2 additions & 0 deletions cmake/StaticAnalyzers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ macro(myproject_enable_cppcheck WARNINGS_AS_ERRORS CPPCHECK_OPTIONS)
--suppress=syntaxError
--suppress=preprocessorErrorDirective
--inconclusive
# Ignores static asserts that are true
--suppress=knownConditionTrueFalse
--suppress=${SUPPRESS_DIR})
else()
# if the user provides a CPPCHECK_OPTIONS with a template specified, it will override this template
Expand Down
10 changes: 8 additions & 2 deletions fuzz_test/fuzz_tester.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include <fmt/format.h>
#include <cstddef>
#include <cstdint>
#include <fmt/core.h>//NOLINT
#include <iterator>
#include <utility>

namespace {

[[nodiscard]] auto sum_values(const uint8_t *Data, size_t Size)
{
Expand All @@ -12,11 +15,14 @@
}
return value;
}
}// namespace

// Fuzzer that attempts to invoke undefined behavior for signed integer overflow
// cppcheck-suppress unusedFunction symbolName=LLVMFuzzerTestOneInput
namespace {
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
{
fmt::print("Value sum: {}, len{}\n", sum_values(Data, Size), Size);
return 0;
}
}// namespace
33 changes: 26 additions & 7 deletions src/ftxui_sample/main.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
#include <CLI/App.hpp>
#include <array>
#include <functional>
#include <iostream>
#include <atomic>
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <exception>
#include <ftxui/screen/screen.hpp>
#include <optional>
#include <utility>
#include <vector>

#include <fmt/core.h>
#include <random>

#include <CLI/CLI.hpp>
#include <ftxui/component/captured_mouse.hpp>// for ftxui
#include <CLI/CLI.hpp>//NOLINT
#include <ftxui/component/component.hpp>// for Slider
#include <ftxui/component/screen_interactive.hpp>// for ScreenInteractive
#include <ftxui/dom/elements.hpp>
#include <spdlog/spdlog.h>
#include <string>
#include <thread>

#include <lefticus/tools/non_promoting_ints.hpp>

Expand Down Expand Up @@ -90,6 +101,8 @@ template<std::size_t Width, std::size_t Height> struct GameBoard
};


namespace {

void consequence_game()
{
auto screen = ftxui::ScreenInteractive::TerminalOutput();
Expand Down Expand Up @@ -162,6 +175,7 @@ void consequence_game()

screen.Loop(renderer);
}
}// namespace

struct Color
{
Expand All @@ -177,12 +191,12 @@ struct Bitmap : ftxui::Node
: width_(width), height_(height)
{}

Color &at(std::size_t cur_x, std::size_t cur_y) { return pixels.at(width_ * cur_y + cur_x); }
Color &at(std::size_t cur_x, std::size_t cur_y) { return pixels.at((width_ * cur_y) + cur_x); }

void ComputeRequirement() override
{
requirement_ = ftxui::Requirement{
.min_x = static_cast<int>(width_), .min_y = static_cast<int>(height_ / 2), .selected_box{ 0, 0, 0, 0 }
.min_x = static_cast<int>(width_), .min_y = static_cast<int>(height_ / 2), .selected_box{ 0, 0, 0, 0 }// NOLINT
};
}

Expand All @@ -193,7 +207,7 @@ struct Bitmap : ftxui::Node
auto &pixel = screen.PixelAt(box_.x_min + static_cast<int>(cur_x), box_.y_min + static_cast<int>(cur_y));
pixel.character = "▄";
const auto &top_color = at(cur_x, cur_y * 2);
const auto &bottom_color = at(cur_x, cur_y * 2 + 1);
const auto &bottom_color = at(cur_x, (cur_y * 2) + 1);
pixel.background_color = ftxui::Color{ top_color.R.get(), top_color.G.get(), top_color.B.get() };
pixel.foreground_color = ftxui::Color{ bottom_color.R.get(), bottom_color.G.get(), bottom_color.B.get() };
}
Expand All @@ -213,6 +227,8 @@ struct Bitmap : ftxui::Node
std::vector<Color> pixels = std::vector<Color>(width_ * height_, Color{});
};

namespace {

void game_iteration_canvas()
{
// this should probably have a `bitmap` helper function that does what cur_you expect
Expand Down Expand Up @@ -257,6 +273,8 @@ void game_iteration_canvas()
case 2:
small_bm_pixel.B += 11;// NOLINT Magic Number
break;
default:
break;
}


Expand Down Expand Up @@ -308,6 +326,7 @@ void game_iteration_canvas()
refresh_ui_continue = false;
refresh_ui.join();
}
}// namespace

// NOLINTNEXTLINE(bugprone-exception-escape)
int main(int argc, const char **argv)
Expand Down
10 changes: 5 additions & 5 deletions test/constexpr_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

TEST_CASE("Factorials are computed with constexpr", "[factorial]")
{
STATIC_REQUIRE(factorial_constexpr(0) == 1);
STATIC_REQUIRE(factorial_constexpr(1) == 1);
STATIC_REQUIRE(factorial_constexpr(2) == 2);
STATIC_REQUIRE(factorial_constexpr(3) == 6);
STATIC_REQUIRE(factorial_constexpr(10) == 3628800);
STATIC_REQUIRE((factorial_constexpr(0) == 1));
STATIC_REQUIRE((factorial_constexpr(1) == 1));
STATIC_REQUIRE((factorial_constexpr(2) == 2));
STATIC_REQUIRE((factorial_constexpr(3) == 6));
STATIC_REQUIRE((factorial_constexpr(10) == 3628800));
}
10 changes: 5 additions & 5 deletions test/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

TEST_CASE("Factorials are computed", "[factorial]")
{
REQUIRE(factorial(0) == 1);
REQUIRE(factorial(1) == 1);
REQUIRE(factorial(2) == 2);
REQUIRE(factorial(3) == 6);
REQUIRE(factorial(10) == 3628800);
REQUIRE((factorial(0) == 1));
REQUIRE((factorial(1) == 1));
REQUIRE((factorial(2) == 2));
REQUIRE((factorial(3) == 6));
REQUIRE((factorial(10) == 3628800));
}