From 8882cd72a36f88d300406533f0634171a5886120 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 13 Dec 2025 08:34:24 +0100 Subject: [PATCH] Bugfixes for compile errors in optimized tests (#1235) * Fix optimized tests by suppressing warning from STL * Fix uninitialized buffer in hash for month_weekday * Fix overlapping memcpy with memmove * Fix random out of bounds index in __builtin_memmove Suppressing compiler warning * Fix array bounds warnings from static casts in message_router In compiled code, casting to wrong message types is generated, even though the code paths are supposed to be never taken due to runtime msg id checks. Therefore, the warnings can be suppressed. * Fix syntax errors in base64 decoder tests * Fix test failure in test_rounded_integral_division.cpp when optimized When building tests optimized, test_round_to_half_even_signed_limits fails due to the fact that etl::absolute(std::numeric_limits::min()) < 0 --- include/etl/basic_string.h | 2 +- .../etl/generators/message_router_generator.h | 18 ++++ include/etl/memory.h | 4 + include/etl/message_router.h | 102 ++++++++++++++++++ include/etl/private/chrono/month_weekday.h | 6 +- .../diagnostic_stringop_overflow_push.h | 43 ++++++++ include/etl/rounded_integral_division.h | 34 ++++-- test/test_base64_RFC2152_decoder.cpp | 26 ++++- test/test_base64_RFC3501_decoder.cpp | 26 ++++- ...64_RFC4648_URL_decoder_with_no_padding.cpp | 26 ++++- ...ase64_RFC4648_URL_decoder_with_padding.cpp | 26 ++++- ...base64_RFC4648_decoder_with_no_padding.cpp | 26 ++++- ...st_base64_RFC4648_decoder_with_padding.cpp | 26 ++++- test/test_multi_span.cpp | 4 + test/test_rounded_integral_division.cpp | 3 +- test/test_string_char.cpp | 2 + test/unit_test_framework.h | 2 + 17 files changed, 355 insertions(+), 21 deletions(-) create mode 100644 include/etl/private/diagnostic_stringop_overflow_push.h diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 9a39b078..cb5cffb9 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -2601,7 +2601,7 @@ namespace etl etl::mem_copy(s, insert_length, &p_buffer[remove_index]); // Move tail left. - etl::mem_copy(&p_buffer[tail_index], tail_length, &p_buffer[remove_index + insert_length]); + etl::mem_move(&p_buffer[tail_index], tail_length, &p_buffer[remove_index + insert_length]); } current_size = remove_index + insert_length + tail_length; diff --git a/include/etl/generators/message_router_generator.h b/include/etl/generators/message_router_generator.h index a1c38d78..868a51ab 100644 --- a/include/etl/generators/message_router_generator.h +++ b/include/etl/generators/message_router_generator.h @@ -465,7 +465,9 @@ namespace etl } else { +#include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive_unknown(msg); +#include "etl/private/diagnostic_pop.h" } } } @@ -473,6 +475,7 @@ namespace etl template ::value, int>::type = 0> void receive(const TMessage& msg) { +#include "etl/private/diagnostic_array_bounds_push.h" if constexpr (etl::is_one_of::value) { static_cast(this)->on_receive(msg); @@ -488,6 +491,7 @@ namespace etl static_cast(this)->on_receive_unknown(msg); } } +#include "etl/private/diagnostic_pop.h" } //********************************************** @@ -524,7 +528,9 @@ namespace etl { if (TMessage::ID == msg.get_message_id()) { +#include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive(static_cast(msg)); +#include "etl/private/diagnostic_pop.h" return true; } else @@ -618,6 +624,7 @@ namespace etl cog.outl(" {") cog.outl(" const etl::message_id_t id = msg.get_message_id();") cog.outl("") + cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"") cog.outl(" switch (id)") cog.outl(" {") for n in range(1, int(Handlers) + 1): @@ -637,6 +644,7 @@ namespace etl cog.outl(" break;") cog.outl(" }") cog.outl(" }") + cog.outl("#include \"etl/private/diagnostic_pop.h\"") cog.outl(" }") cog.outl("") cog.outl(" template ") @@ -646,7 +654,9 @@ namespace etl cog.outl("T%s>::value, void>::type" % int(Handlers)) cog.outl(" receive(const TMessage& msg)") cog.outl(" {") + cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"") cog.outl(" static_cast(this)->on_receive(msg);") + cog.outl("#include \"etl/private/diagnostic_pop.h\"") cog.outl(" }") cog.outl("") cog.outl(" template ") @@ -662,7 +672,9 @@ namespace etl cog.outl(" }") cog.outl(" else") cog.outl(" {") + cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"") cog.outl(" static_cast(this)->on_receive_unknown(msg);") + cog.outl("#include \"etl/private/diagnostic_pop.h\"") cog.outl(" }") cog.outl(" }") cog.outl("") @@ -786,6 +798,7 @@ namespace etl cog.outl(" {") cog.outl(" const size_t id = msg.get_message_id();") cog.outl("") + cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"") cog.outl(" switch (id)") cog.outl(" {") for t in range(1, n + 1): @@ -805,6 +818,7 @@ namespace etl cog.outl(" break;") cog.outl(" }") cog.outl(" }") + cog.outl("#include \"etl/private/diagnostic_pop.h\"") cog.outl(" }") cog.outl("") cog.outl(" template ") @@ -814,7 +828,9 @@ namespace etl cog.outl("T%s>::value, void>::type" % n) cog.outl(" receive(const TMessage& msg)") cog.outl(" {") + cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"") cog.outl(" static_cast(this)->on_receive(msg);") + cog.outl("#include \"etl/private/diagnostic_pop.h\"") cog.outl(" }") cog.outl("") cog.outl(" template ") @@ -830,7 +846,9 @@ namespace etl cog.outl(" }") cog.outl(" else") cog.outl(" {") + cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"") cog.outl(" static_cast(this)->on_receive_unknown(msg);") + cog.outl("#include \"etl/private/diagnostic_pop.h\"") cog.outl(" }") cog.outl(" }") cog.outl("") diff --git a/include/etl/memory.h b/include/etl/memory.h index ffe7b7ef..57b89879 100644 --- a/include/etl/memory.h +++ b/include/etl/memory.h @@ -2366,9 +2366,13 @@ namespace etl ETL_STATIC_ASSERT(etl::is_trivially_copyable::value, "Cannot mem_move a non trivially copyable type"); #if ETL_USING_BUILTIN_MEMMOVE +#include "etl/private/diagnostic_array_bounds_push.h" +#include "etl/private/diagnostic_stringop_overread_push.h" __builtin_memmove(reinterpret_cast(db), reinterpret_cast(sb), sizeof(T) * n); +#include "etl/private/diagnostic_pop.h" +#include "etl/private/diagnostic_pop.h" #else ::memmove(reinterpret_cast(db), reinterpret_cast(sb), diff --git a/include/etl/message_router.h b/include/etl/message_router.h index d3c1053f..cc6ea40c 100644 --- a/include/etl/message_router.h +++ b/include/etl/message_router.h @@ -453,7 +453,9 @@ namespace etl } else { +#include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive_unknown(msg); +#include "etl/private/diagnostic_pop.h" } } } @@ -461,6 +463,7 @@ namespace etl template ::value, int>::type = 0> void receive(const TMessage& msg) { +#include "etl/private/diagnostic_array_bounds_push.h" if constexpr (etl::is_one_of::value) { static_cast(this)->on_receive(msg); @@ -476,6 +479,7 @@ namespace etl static_cast(this)->on_receive_unknown(msg); } } +#include "etl/private/diagnostic_pop.h" } //********************************************** @@ -512,7 +516,9 @@ namespace etl { if (TMessage::ID == msg.get_message_id()) { +#include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive(static_cast(msg)); +#include "etl/private/diagnostic_pop.h" return true; } else @@ -593,6 +599,7 @@ namespace etl { const etl::message_id_t id = msg.get_message_id(); + #include "etl/private/diagnostic_array_bounds_push.h" switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; @@ -624,13 +631,16 @@ namespace etl break; } } + #include "etl/private/diagnostic_pop.h" } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive(msg); + #include "etl/private/diagnostic_pop.h" } template @@ -643,7 +653,9 @@ namespace etl } else { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive_unknown(msg); + #include "etl/private/diagnostic_pop.h" } } @@ -738,6 +750,7 @@ namespace etl { const size_t id = msg.get_message_id(); + #include "etl/private/diagnostic_array_bounds_push.h" switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; @@ -768,13 +781,16 @@ namespace etl break; } } + #include "etl/private/diagnostic_pop.h" } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive(msg); + #include "etl/private/diagnostic_pop.h" } template @@ -787,7 +803,9 @@ namespace etl } else { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive_unknown(msg); + #include "etl/private/diagnostic_pop.h" } } @@ -883,6 +901,7 @@ namespace etl { const size_t id = msg.get_message_id(); + #include "etl/private/diagnostic_array_bounds_push.h" switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; @@ -912,13 +931,16 @@ namespace etl break; } } + #include "etl/private/diagnostic_pop.h" } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive(msg); + #include "etl/private/diagnostic_pop.h" } template @@ -931,7 +953,9 @@ namespace etl } else { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive_unknown(msg); + #include "etl/private/diagnostic_pop.h" } } @@ -1027,6 +1051,7 @@ namespace etl { const size_t id = msg.get_message_id(); + #include "etl/private/diagnostic_array_bounds_push.h" switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; @@ -1055,13 +1080,16 @@ namespace etl break; } } + #include "etl/private/diagnostic_pop.h" } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive(msg); + #include "etl/private/diagnostic_pop.h" } template @@ -1074,7 +1102,9 @@ namespace etl } else { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive_unknown(msg); + #include "etl/private/diagnostic_pop.h" } } @@ -1169,6 +1199,7 @@ namespace etl { const size_t id = msg.get_message_id(); + #include "etl/private/diagnostic_array_bounds_push.h" switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; @@ -1196,13 +1227,16 @@ namespace etl break; } } + #include "etl/private/diagnostic_pop.h" } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive(msg); + #include "etl/private/diagnostic_pop.h" } template @@ -1215,7 +1249,9 @@ namespace etl } else { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive_unknown(msg); + #include "etl/private/diagnostic_pop.h" } } @@ -1310,6 +1346,7 @@ namespace etl { const size_t id = msg.get_message_id(); + #include "etl/private/diagnostic_array_bounds_push.h" switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; @@ -1336,13 +1373,16 @@ namespace etl break; } } + #include "etl/private/diagnostic_pop.h" } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive(msg); + #include "etl/private/diagnostic_pop.h" } template @@ -1355,7 +1395,9 @@ namespace etl } else { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive_unknown(msg); + #include "etl/private/diagnostic_pop.h" } } @@ -1450,6 +1492,7 @@ namespace etl { const size_t id = msg.get_message_id(); + #include "etl/private/diagnostic_array_bounds_push.h" switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; @@ -1475,13 +1518,16 @@ namespace etl break; } } + #include "etl/private/diagnostic_pop.h" } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive(msg); + #include "etl/private/diagnostic_pop.h" } template @@ -1494,7 +1540,9 @@ namespace etl } else { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive_unknown(msg); + #include "etl/private/diagnostic_pop.h" } } @@ -1589,6 +1637,7 @@ namespace etl { const size_t id = msg.get_message_id(); + #include "etl/private/diagnostic_array_bounds_push.h" switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; @@ -1613,13 +1662,16 @@ namespace etl break; } } + #include "etl/private/diagnostic_pop.h" } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive(msg); + #include "etl/private/diagnostic_pop.h" } template @@ -1632,7 +1684,9 @@ namespace etl } else { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive_unknown(msg); + #include "etl/private/diagnostic_pop.h" } } @@ -1726,6 +1780,7 @@ namespace etl { const size_t id = msg.get_message_id(); + #include "etl/private/diagnostic_array_bounds_push.h" switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; @@ -1749,13 +1804,16 @@ namespace etl break; } } + #include "etl/private/diagnostic_pop.h" } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive(msg); + #include "etl/private/diagnostic_pop.h" } template @@ -1768,7 +1826,9 @@ namespace etl } else { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive_unknown(msg); + #include "etl/private/diagnostic_pop.h" } } @@ -1862,6 +1922,7 @@ namespace etl { const size_t id = msg.get_message_id(); + #include "etl/private/diagnostic_array_bounds_push.h" switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; @@ -1884,13 +1945,16 @@ namespace etl break; } } + #include "etl/private/diagnostic_pop.h" } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive(msg); + #include "etl/private/diagnostic_pop.h" } template @@ -1903,7 +1967,9 @@ namespace etl } else { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive_unknown(msg); + #include "etl/private/diagnostic_pop.h" } } @@ -1996,6 +2062,7 @@ namespace etl { const size_t id = msg.get_message_id(); + #include "etl/private/diagnostic_array_bounds_push.h" switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; @@ -2017,13 +2084,16 @@ namespace etl break; } } + #include "etl/private/diagnostic_pop.h" } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive(msg); + #include "etl/private/diagnostic_pop.h" } template @@ -2036,7 +2106,9 @@ namespace etl } else { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive_unknown(msg); + #include "etl/private/diagnostic_pop.h" } } @@ -2129,6 +2201,7 @@ namespace etl { const size_t id = msg.get_message_id(); + #include "etl/private/diagnostic_array_bounds_push.h" switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; @@ -2149,13 +2222,16 @@ namespace etl break; } } + #include "etl/private/diagnostic_pop.h" } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive(msg); + #include "etl/private/diagnostic_pop.h" } template @@ -2168,7 +2244,9 @@ namespace etl } else { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive_unknown(msg); + #include "etl/private/diagnostic_pop.h" } } @@ -2260,6 +2338,7 @@ namespace etl { const size_t id = msg.get_message_id(); + #include "etl/private/diagnostic_array_bounds_push.h" switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; @@ -2279,13 +2358,16 @@ namespace etl break; } } + #include "etl/private/diagnostic_pop.h" } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive(msg); + #include "etl/private/diagnostic_pop.h" } template @@ -2298,7 +2380,9 @@ namespace etl } else { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive_unknown(msg); + #include "etl/private/diagnostic_pop.h" } } @@ -2390,6 +2474,7 @@ namespace etl { const size_t id = msg.get_message_id(); + #include "etl/private/diagnostic_array_bounds_push.h" switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; @@ -2408,13 +2493,16 @@ namespace etl break; } } + #include "etl/private/diagnostic_pop.h" } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive(msg); + #include "etl/private/diagnostic_pop.h" } template @@ -2427,7 +2515,9 @@ namespace etl } else { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive_unknown(msg); + #include "etl/private/diagnostic_pop.h" } } @@ -2519,6 +2609,7 @@ namespace etl { const size_t id = msg.get_message_id(); + #include "etl/private/diagnostic_array_bounds_push.h" switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; @@ -2536,13 +2627,16 @@ namespace etl break; } } + #include "etl/private/diagnostic_pop.h" } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive(msg); + #include "etl/private/diagnostic_pop.h" } template @@ -2555,7 +2649,9 @@ namespace etl } else { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive_unknown(msg); + #include "etl/private/diagnostic_pop.h" } } @@ -2647,6 +2743,7 @@ namespace etl { const size_t id = msg.get_message_id(); + #include "etl/private/diagnostic_array_bounds_push.h" switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; @@ -2663,13 +2760,16 @@ namespace etl break; } } + #include "etl/private/diagnostic_pop.h" } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive(msg); + #include "etl/private/diagnostic_pop.h" } template @@ -2682,7 +2782,9 @@ namespace etl } else { + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive_unknown(msg); + #include "etl/private/diagnostic_pop.h" } } diff --git a/include/etl/private/chrono/month_weekday.h b/include/etl/private/chrono/month_weekday.h index 9e05692d..89ac6566 100644 --- a/include/etl/private/chrono/month_weekday.h +++ b/include/etl/private/chrono/month_weekday.h @@ -186,9 +186,9 @@ namespace etl uint8_t buffer[sizeof(a) + sizeof(b) + sizeof(c)]; - memcpy(buffer, &a, sizeof(a)); - memcpy(buffer + sizeof(a), &b, sizeof(b)); - memcpy(buffer + sizeof(b), &b, sizeof(c)); + memcpy(buffer, &a, sizeof(a)); + memcpy(buffer + sizeof(a), &b, sizeof(b)); + memcpy(buffer + sizeof(a) + sizeof(b), &c, sizeof(c)); return etl::private_hash::generic_hash(buffer, buffer + sizeof(a) + sizeof(b) + sizeof(c)); } diff --git a/include/etl/private/diagnostic_stringop_overflow_push.h b/include/etl/private/diagnostic_stringop_overflow_push.h new file mode 100644 index 00000000..ee258eef --- /dev/null +++ b/include/etl/private/diagnostic_stringop_overflow_push.h @@ -0,0 +1,43 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2023 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +/* + * The header include guard has been intentionally omitted. + * This file is intended to evaluated multiple times by design. + */ + +#if defined(__GNUC__) && (__GNUC__ >= 11) && !defined(__clang__) && !defined(__llvm__) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstringop-overflow" +#endif + +#if defined(__clang__) || defined(__llvm__) + #pragma clang diagnostic push +#endif diff --git a/include/etl/rounded_integral_division.h b/include/etl/rounded_integral_division.h index 417b3143..4547fc01 100644 --- a/include/etl/rounded_integral_division.h +++ b/include/etl/rounded_integral_division.h @@ -615,22 +615,36 @@ namespace etl { const T quotient = numerator / denominator; const T remainder = numerator % denominator; - const T abs_denominator = etl::absolute(denominator); - const T abs_remainderainder = etl::absolute(remainder); const T direction = ((numerator >= 0) == (denominator >= 0)) ? 1 : -1; - if ((abs_remainderainder * 2) < abs_denominator) + // Work with magnitudes in unsigned form (avoids abs() overflow for T::min()). + typedef typename std::make_unsigned::type utype; + const utype abs_denominator = (denominator < 0) ? (utype(0) - utype(denominator)) : utype(denominator); + const utype abs_remainder = (remainder < 0) ? (utype(0) - utype(remainder)) : utype(remainder); + const utype half_denominator = abs_denominator / 2U; + + // Compare without `* 2` to avoid unsigned overflow. + if ((abs_denominator & 1U) == 0U) { - return quotient; - } - else if ((abs_remainderainder * 2) > abs_denominator) - { - return quotient + direction; + // Even denominator: can be exactly half. + if (abs_remainder < half_denominator) + { + return quotient; + } + else if (abs_remainder > half_denominator) + { + return quotient + direction; + } + else + { + // Exactly halfway, round to even + return (quotient & 1) == 0 ? quotient : quotient + direction; + } } else { - // Exactly halfway, round to even - return (quotient & 1) == 0 ? quotient : quotient + direction; + // Odd denominator: no exact half case. + return (abs_remainder <= half_denominator) ? quotient : (quotient + direction); } } diff --git a/test/test_base64_RFC2152_decoder.cpp b/test/test_base64_RFC2152_decoder.cpp index 64cc11ca..53c3e9f6 100644 --- a/test/test_base64_RFC2152_decoder.cpp +++ b/test/test_base64_RFC2152_decoder.cpp @@ -386,8 +386,10 @@ namespace b64.decode_final(encoded[i].data(), encoded[i].size()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -408,8 +410,10 @@ namespace b64.decode_final(encoded[i].data(), encoded[i].size()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -447,8 +451,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -486,8 +492,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -508,8 +516,10 @@ namespace b64.decode_final(encoded[i].begin(), encoded[i].end()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -530,8 +540,10 @@ namespace b64.decode_final(encoded[i].begin(), encoded[i].end()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -569,8 +581,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -608,8 +622,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -640,8 +656,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -672,8 +690,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -708,8 +728,10 @@ namespace b64.flush(); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(b64.begin(), b64.end()); +#include "etl/private/diagnostic_pop.h" CHECK_EQUAL(expected.size(), actual.size()); CHECK_TRUE(std::equal(expected.begin(), expected.end(), actual.begin())); @@ -739,8 +761,10 @@ namespace constexpr auto output{ GetConstexprBase64(input) }; +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; std::vector actual(output.begin(), output.end()); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(std::equal(expected.begin(), expected.end(), actual.begin())); CHECK_TRUE(codec::safe_output_buffer_size(14) >= output.size()); @@ -755,7 +779,7 @@ namespace #if ETL_USING_EXCEPTIONS CHECK_THROW((b64.decode(encoded[10].data(), encoded[10].size())), etl::base64_overflow); #else - CHECK_FALSE(b64.decode(encoded[10].data(), encoded[10].size()); + CHECK_FALSE(b64.decode(encoded[10].data(), encoded[10].size())); CHECK_TRUE(b64.error()); #endif } diff --git a/test/test_base64_RFC3501_decoder.cpp b/test/test_base64_RFC3501_decoder.cpp index 2e3c2faf..dd46a17d 100644 --- a/test/test_base64_RFC3501_decoder.cpp +++ b/test/test_base64_RFC3501_decoder.cpp @@ -383,8 +383,10 @@ namespace b64.decode_final(encoded[i].data(), encoded[i].size()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -405,8 +407,10 @@ namespace b64.decode_final(encoded[i].data(), encoded[i].size()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -444,8 +448,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -483,8 +489,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -505,8 +513,10 @@ namespace b64.decode_final(encoded[i].begin(), encoded[i].end()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -527,8 +537,10 @@ namespace b64.decode_final(encoded[i].begin(), encoded[i].end()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -566,8 +578,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -605,8 +619,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -637,8 +653,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -669,8 +687,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -705,8 +725,10 @@ namespace b64.flush(); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(b64.begin(), b64.end()); +#include "etl/private/diagnostic_pop.h" CHECK_EQUAL(expected.size(), actual.size()); CHECK_TRUE(std::equal(expected.begin(), expected.end(), actual.begin())); @@ -736,8 +758,10 @@ namespace constexpr auto output{ GetConstexprBase64(input) }; +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; std::vector actual(output.begin(), output.end()); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(std::equal(expected.begin(), expected.end(), actual.begin())); CHECK_TRUE(codec::safe_output_buffer_size(14) >= output.size()); @@ -752,7 +776,7 @@ namespace #if ETL_USING_EXCEPTIONS CHECK_THROW((b64.decode(encoded[10].data(), encoded[10].size())), etl::base64_overflow); #else - CHECK_FALSE(b64.decode(encoded[10].data(), encoded[10].size()); + CHECK_FALSE(b64.decode(encoded[10].data(), encoded[10].size())); CHECK_TRUE(b64.error()); #endif } diff --git a/test/test_base64_RFC4648_URL_decoder_with_no_padding.cpp b/test/test_base64_RFC4648_URL_decoder_with_no_padding.cpp index c1c9280d..e4dcad59 100644 --- a/test/test_base64_RFC4648_URL_decoder_with_no_padding.cpp +++ b/test/test_base64_RFC4648_URL_decoder_with_no_padding.cpp @@ -383,8 +383,10 @@ namespace b64.decode_final(encoded[i].data(), encoded[i].size()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -405,8 +407,10 @@ namespace b64.decode_final(encoded[i].data(), encoded[i].size()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -444,8 +448,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -483,8 +489,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -505,8 +513,10 @@ namespace b64.decode_final(encoded[i].begin(), encoded[i].end()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -527,8 +537,10 @@ namespace b64.decode_final(encoded[i].begin(), encoded[i].end()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -566,8 +578,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -605,8 +619,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -637,8 +653,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -669,8 +687,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -705,8 +725,10 @@ namespace b64.flush(); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(b64.begin(), b64.end()); +#include "etl/private/diagnostic_pop.h" CHECK_EQUAL(expected.size(), actual.size()); CHECK_TRUE(std::equal(expected.begin(), expected.end(), actual.begin())); @@ -736,8 +758,10 @@ namespace constexpr auto output{ GetConstexprBase64(input) }; +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; std::vector actual(output.begin(), output.end()); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(std::equal(expected.begin(), expected.end(), actual.begin())); CHECK_TRUE(codec::safe_output_buffer_size(14) >= output.size()); @@ -752,7 +776,7 @@ namespace #if ETL_USING_EXCEPTIONS CHECK_THROW((b64.decode(encoded[10].data(), encoded[10].size())), etl::base64_overflow); #else - CHECK_FALSE(b64.decode(encoded[10].data(), encoded[10].size()); + CHECK_FALSE(b64.decode(encoded[10].data(), encoded[10].size())); CHECK_TRUE(b64.error()); #endif } diff --git a/test/test_base64_RFC4648_URL_decoder_with_padding.cpp b/test/test_base64_RFC4648_URL_decoder_with_padding.cpp index ab75c182..c9a340ce 100644 --- a/test/test_base64_RFC4648_URL_decoder_with_padding.cpp +++ b/test/test_base64_RFC4648_URL_decoder_with_padding.cpp @@ -383,8 +383,10 @@ namespace b64.decode_final(encoded[i].data(), encoded[i].size()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -405,8 +407,10 @@ namespace b64.decode_final(encoded[i].data(), encoded[i].size()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -444,8 +448,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -483,8 +489,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -505,8 +513,10 @@ namespace b64.decode_final(encoded[i].begin(), encoded[i].end()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -527,8 +537,10 @@ namespace b64.decode_final(encoded[i].begin(), encoded[i].end()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -566,8 +578,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -605,8 +619,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -637,8 +653,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -669,8 +687,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -705,8 +725,10 @@ namespace b64.flush(); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(b64.begin(), b64.end()); +#include "etl/private/diagnostic_pop.h" CHECK_EQUAL(expected.size(), actual.size()); CHECK_TRUE(std::equal(expected.begin(), expected.end(), actual.begin())); @@ -736,8 +758,10 @@ namespace constexpr auto output{ GetConstexprBase64(input) }; +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; std::vector actual(output.begin(), output.end()); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(std::equal(expected.begin(), expected.end(), actual.begin())); CHECK_TRUE(codec::safe_output_buffer_size(14) >= output.size()); @@ -752,7 +776,7 @@ namespace #if ETL_USING_EXCEPTIONS CHECK_THROW((b64.decode(encoded[10].data(), encoded[10].size())), etl::base64_overflow); #else - CHECK_FALSE(b64.decode(encoded[10].data(), encoded[10].size()); + CHECK_FALSE(b64.decode(encoded[10].data(), encoded[10].size())); CHECK_TRUE(b64.error()); #endif } diff --git a/test/test_base64_RFC4648_decoder_with_no_padding.cpp b/test/test_base64_RFC4648_decoder_with_no_padding.cpp index 8fbde338..a34abde1 100644 --- a/test/test_base64_RFC4648_decoder_with_no_padding.cpp +++ b/test/test_base64_RFC4648_decoder_with_no_padding.cpp @@ -383,8 +383,10 @@ namespace b64.decode_final(encoded[i].data(), encoded[i].size()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -405,8 +407,10 @@ namespace b64.decode_final(encoded[i].data(), encoded[i].size()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -444,8 +448,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -483,8 +489,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -505,8 +513,10 @@ namespace b64.decode_final(encoded[i].begin(), encoded[i].end()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -527,8 +537,10 @@ namespace b64.decode_final(encoded[i].begin(), encoded[i].end()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -566,8 +578,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -605,8 +619,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -637,8 +653,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -669,8 +687,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -705,8 +725,10 @@ namespace b64.flush(); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(b64.begin(), b64.end()); +#include "etl/private/diagnostic_pop.h" CHECK_EQUAL(expected.size(), actual.size()); CHECK_TRUE(std::equal(expected.begin(), expected.end(), actual.begin())); @@ -736,8 +758,10 @@ namespace constexpr auto output{ GetConstexprBase64(input) }; +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; std::vector actual(output.begin(), output.end()); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(std::equal(expected.begin(), expected.end(), actual.begin())); CHECK_TRUE(codec::safe_output_buffer_size(14) >= output.size()); @@ -752,7 +776,7 @@ namespace #if ETL_USING_EXCEPTIONS CHECK_THROW((b64.decode(encoded[10].data(), encoded[10].size())), etl::base64_overflow); #else - CHECK_FALSE(b64.decode(encoded[10].data(), encoded[10].size()); + CHECK_FALSE(b64.decode(encoded[10].data(), encoded[10].size())); CHECK_TRUE(b64.error()); #endif } diff --git a/test/test_base64_RFC4648_decoder_with_padding.cpp b/test/test_base64_RFC4648_decoder_with_padding.cpp index fef5112a..7c078545 100644 --- a/test/test_base64_RFC4648_decoder_with_padding.cpp +++ b/test/test_base64_RFC4648_decoder_with_padding.cpp @@ -383,8 +383,10 @@ namespace b64.decode_final(encoded[i].data(), encoded[i].size()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -405,8 +407,10 @@ namespace b64.decode_final(encoded[i].data(), encoded[i].size()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -444,8 +448,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -483,8 +489,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -505,8 +513,10 @@ namespace b64.decode_final(encoded[i].begin(), encoded[i].end()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -527,8 +537,10 @@ namespace b64.decode_final(encoded[i].begin(), encoded[i].end()); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -566,8 +578,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -605,8 +619,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -637,8 +653,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -669,8 +687,10 @@ namespace b64.flush(); CHECK_TRUE(received_final_block); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(received_final_block); CHECK_EQUAL(expected.size(), actual.size()); @@ -705,8 +725,10 @@ namespace b64.flush(); +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(b64.begin(), b64.end()); +#include "etl/private/diagnostic_pop.h" CHECK_EQUAL(expected.size(), actual.size()); CHECK_TRUE(std::equal(expected.begin(), expected.end(), actual.begin())); @@ -736,8 +758,10 @@ namespace constexpr auto output{ GetConstexprBase64(input) }; +#include "etl/private/diagnostic_null_dereference_push.h" std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; std::vector actual(output.begin(), output.end()); +#include "etl/private/diagnostic_pop.h" CHECK_TRUE(std::equal(expected.begin(), expected.end(), actual.begin())); CHECK_TRUE(codec::safe_output_buffer_size(14) >= output.size()); @@ -752,7 +776,7 @@ namespace #if ETL_USING_EXCEPTIONS CHECK_THROW((b64.decode(encoded[10].data(), encoded[10].size())), etl::base64_overflow); #else - CHECK_FALSE(b64.decode(encoded[10].data(), encoded[10].size()); + CHECK_FALSE(b64.decode(encoded[10].data(), encoded[10].size())); CHECK_TRUE(b64.error()); #endif } diff --git a/test/test_multi_span.cpp b/test/test_multi_span.cpp index 19fbee95..67dab266 100644 --- a/test/test_multi_span.cpp +++ b/test/test_multi_span.cpp @@ -557,7 +557,9 @@ namespace while (ms_itr != ms_end_itr) { // Fill the multi span +#include "etl/private/diagnostic_null_dereference_push.h" *ms_itr++ = *exp_itr++; +#include "etl/private/diagnostic_pop.h" } while (ms_itr != ms_end_itr) @@ -625,7 +627,9 @@ namespace for (size_t i = 0; i < expected.size(); ++i) { +#include "etl/private/diagnostic_null_dereference_push.h" *ms_itr = *exp_itr; +#include "etl/private/diagnostic_pop.h" if (i < expected.size() - 1) { diff --git a/test/test_rounded_integral_division.cpp b/test/test_rounded_integral_division.cpp index dc91390b..c4fc64da 100644 --- a/test/test_rounded_integral_division.cpp +++ b/test/test_rounded_integral_division.cpp @@ -732,7 +732,8 @@ namespace CHECK_EQUAL(std::numeric_limits::max(), etl::divide_round_half_even(std::numeric_limits::max(), int32_t(1))); CHECK_EQUAL(int32_t(0), etl::divide_round_half_even(int32_t(1), std::numeric_limits::max())); CHECK_EQUAL(std::numeric_limits::min(), etl::divide_round_half_even(std::numeric_limits::min(), int32_t(1))); - CHECK_EQUAL(int32_t(-1), etl::divide_round_half_even(int32_t(1), std::numeric_limits::min())); + CHECK_EQUAL(int32_t(0), etl::divide_round_half_even(int32_t(1), std::numeric_limits::min())); + CHECK_EQUAL(int32_t(1), etl::divide_round_half_even(std::numeric_limits::min(), std::numeric_limits::min())); } //************************************************************************* diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index 6cf70b28..7824f993 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -1556,7 +1556,9 @@ namespace Text text2; +#include "etl/private/diagnostic_stringop_overflow_push.h" CHECK_THROW(text.insert(text2.cbegin(), insert_text.cbegin(), insert_text.cend()), etl::string_out_of_bounds); +#include "etl/private/diagnostic_pop.h" } //************************************************************************* diff --git a/test/unit_test_framework.h b/test/unit_test_framework.h index 798a6eae..f5d33b92 100644 --- a/test/unit_test_framework.h +++ b/test/unit_test_framework.h @@ -29,6 +29,8 @@ SOFTWARE. #ifndef ETL_UNIT_TEST_FRAMEWORK_INCLUDED #define ETL_UNIT_TEST_FRAMEWORK_INCLUDED +#include "etl/private/diagnostic_null_dereference_push.h" #include "UnitTest++/UnitTest++.h" +#include "etl/private/diagnostic_pop.h" #endif