From e53dd8b0e5d9653422afa968ce55e17401203015 Mon Sep 17 00:00:00 2001 From: David Sisson Date: Wed, 16 Aug 2023 13:55:48 -0700 Subject: [PATCH] feat: enable address and leak detection on all debug builds (#82) --- CMakeLists.txt | 6 ++++++ src/substrait/textplan/parser/SubstraitPlanTypeVisitor.cpp | 6 +++++- src/substrait/type/Type.cpp | 7 ++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bd7fe7e6..d4f78ef9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,12 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +add_compile_options($<$:-fsanitize=undefined>) +add_link_options($<$:-fsanitize=undefined>) + +add_compile_options($<$:-fsanitize=address>) +add_link_options($<$:-fsanitize=address>) + option( SUBSTRAIT_CPP_BUILD_TESTING "Enable substrait-cpp tests. This will enable all other build options automatically." diff --git a/src/substrait/textplan/parser/SubstraitPlanTypeVisitor.cpp b/src/substrait/textplan/parser/SubstraitPlanTypeVisitor.cpp index 403caa22..5b42d817 100644 --- a/src/substrait/textplan/parser/SubstraitPlanTypeVisitor.cpp +++ b/src/substrait/textplan/parser/SubstraitPlanTypeVisitor.cpp @@ -109,11 +109,15 @@ ::substrait::proto::Type SubstraitPlanTypeVisitor::typeToProto( } case TypeKind::kVarchar: { auto varChar = - reinterpret_cast(&decodedType); + reinterpret_cast(&decodedType); if (varChar == nullptr) { break; } try { + if (!varChar->length()->isInteger()) { + errorListener_->addError(ctx->getStart(), "Missing varchar length."); + break; + } int32_t length = std::stoi(varChar->length()->value()); type.mutable_varchar()->set_length(length); } catch (...) { diff --git a/src/substrait/type/Type.cpp b/src/substrait/type/Type.cpp index 1fa21115..5a0e3cff 100644 --- a/src/substrait/type/Type.cpp +++ b/src/substrait/type/Type.cpp @@ -197,7 +197,12 @@ ParameterizedTypePtr ParameterizedType::decode( const auto& leftAngleBracketPos = matchingType.find('<'); if (leftAngleBracketPos == std::string::npos) { - bool nullable = matchingType.back() == '?'; + bool nullable; + if (matchingType.empty()) { + nullable = false; + } else { + nullable = matchingType.back() == '?'; + } // deal with type and with a question mask like "i32?". const auto& baseType = nullable ? matchingType = matchingType.substr(0, questionMaskPos)