From 8b86f16f25a052b395ccefbb5a220bf4e0551274 Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Sat, 12 Jun 2021 15:05:32 -0400 Subject: [PATCH] Variant: Do not use implicit fall-through The code handling the comparison between the date and string types would convert the variants to correct types, but only through multi-level fall-through in the switch statement, which is always a bit of a dangerous construct. Added explicit return for the non-trivial case, preventing the need for the fall-through. Closes #2502. --- src/Variant.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Variant.cpp b/src/Variant.cpp index 08dbb17aa..6a2819697 100644 --- a/src/Variant.cpp +++ b/src/Variant.cpp @@ -1098,8 +1098,15 @@ bool Variant::operator_partial (const Variant& other) const { // Same-day comparison. case type_string: - if (left.trivial () || right.trivial ()) - return false; + { + if (left.trivial () || right.trivial ()) + return false; + + right.cast (type_date); + Datetime left_date (left._date); + Datetime right_date (right._date); + return left_date.sameDay (right_date); + } case type_boolean: case type_integer: