Fixed many hardening issues

This commit is contained in:
saundersp
2025-08-24 18:53:28 +02:00
parent ef60a9553e
commit 7836efb637
3 changed files with 32 additions and 33 deletions

View File

@@ -52,8 +52,8 @@ static void test_argsort(const std::array<int32_t, N>& gaps, const asp::Array<T>
}
template<typename T>
static asp::Array<T> create_random_array(const size_t& n) noexcept {
asp::Array<T> original(n);
static inline asp::Array<T> create_random_array(const int64_t n) noexcept {
asp::Array<T> original((size_t(n)));
std::random_device rd;
std::default_random_engine gen(rd());
std::uniform_int_distribution<T> distribution(std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
@@ -64,22 +64,20 @@ int32_t main(int32_t argc, char** argv) {
asp::toolbox_unit_test();
using array_type = uint16_t;
size_t N = (static_cast<size_t>(1)<<15) - 1;
// size_t N = std::numeric_limits<array_type>::max();
int64_t N = (static_cast<int64_t>(1)<<15) - 1;
// int64_t N = std::numeric_limits<array_type>::max();
if (argc > 2) {
fprintf(stderr, "Too many arguments\nUsage: ./data <ARRAY_SIZE>\n");
return EXIT_FAILURE;
} else if (argc == 2)
N = std::strtoul(argv[1], argv + strlen(argv[1]) + 1, 10);
N = std::strtol(argv[1], argv + strlen(argv[1]) + 1, 10);
char title[64];
sprintf(title, "Sorting %s elements of %s", asp::thousand_sep(N).c_str(), asp::format_byte_size(2 * N * sizeof(array_type)).c_str());
const std::array<int32_t, 3> gaps = { 48, -17, 25 };
sprintf(title, "Sorting %s elements of %s", asp::thousand_sep(N).c_str(), asp::format_byte_size(2 * uint64_t(N) * sizeof(array_type)).c_str());
constexpr std::array<int32_t, 3> gaps = { 48, -17, 25 };
asp::header(gaps, { title, "Time spent (ns)", "Formatted time spent" });
const asp::Array<array_type> original = asp::measure_time<asp::Array<array_type>>(gaps, "Creating random array", create_random_array<array_type>, N);
// const asp::Array<array_type> original = { 2, 5, 3, 0, 2, 3, 0, 3 };
// asp::print(original);
test_sort(gaps, original, asp::bubble_sort<array_type>, "Bubble sort");
test_argsort(gaps, original, asp::bubble_sort_arg<array_type>, "Bubble sort (arg)");