From a6a927f70d7db1120f275c8d6531b524f1293d34 Mon Sep 17 00:00:00 2001 From: LittleCube Date: Thu, 26 Dec 2024 19:38:55 -0500 Subject: [PATCH] preserve error checking from old get_func_sizes --- src/config.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index e5bedf1..8c48b69 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -135,12 +135,17 @@ std::vector get_func_sizes(const toml::array* func_size func_sizes_array->for_each([&func_sizes](auto&& el) { if constexpr (toml::is_table) { std::optional func_name = el["name"].template value(); - std::optional size = el["size"].template value(); + std::optional func_size = el["size"].template value(); - if (func_name.has_value() && size.has_value()) { - func_sizes.emplace_back(func_name.value(), size.value()); + if (func_name.has_value() && func_size.has_value()) { + // Make sure the size is divisible by 4 + if (func_size.value() & (4 - 1)) { + // It's not, so throw an error (and make it look like a normal toml one). + throw toml::parse_error("Function size is not divisible by 4", el.source()); + } + func_sizes.emplace_back(func_name.value(), func_size.value()); } else { - throw toml::parse_error("Missing required value in function_sizes array", el.source()); + throw toml::parse_error("Manually size function is missing required value(s)", el.source()); } } else {