From e774b10e179f8f7b70051f83f5e7785061507932 Mon Sep 17 00:00:00 2001 From: Jianling Zhong Date: Wed, 18 Dec 2024 11:24:04 -0800 Subject: [PATCH] Fix clang tidy errors --- compiler+runtime/src/cpp/jank/c_api.cpp | 8 ++++---- compiler+runtime/src/cpp/jank/read/lex.cpp | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/compiler+runtime/src/cpp/jank/c_api.cpp b/compiler+runtime/src/cpp/jank/c_api.cpp index d0c19181..210fc1cb 100644 --- a/compiler+runtime/src/cpp/jank/c_api.cpp +++ b/compiler+runtime/src/cpp/jank/c_api.cpp @@ -394,7 +394,7 @@ extern "C" jank_object_ptr jank_list_create(uint64_t const size, ...) { /* NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) */ - va_list args; + va_list args{}; va_start(args, size); native_vector v; @@ -414,7 +414,7 @@ extern "C" jank_object_ptr jank_vector_create(uint64_t const size, ...) { /* NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) */ - va_list args; + va_list args{}; va_start(args, size); obj::transient_vector trans; @@ -433,7 +433,7 @@ extern "C" jank_object_ptr jank_map_create(uint64_t const pairs, ...) { /* NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) */ - va_list args; + va_list args{}; va_start(args, pairs); /* TODO: Could optimize to build an array map, if it's small enough. */ @@ -454,7 +454,7 @@ extern "C" jank_object_ptr jank_set_create(uint64_t const size, ...) { /* NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) */ - va_list args; + va_list args{}; va_start(args, size); obj::transient_hash_set trans; diff --git a/compiler+runtime/src/cpp/jank/read/lex.cpp b/compiler+runtime/src/cpp/jank/read/lex.cpp index 3a9224ac..458a1a90 100644 --- a/compiler+runtime/src/cpp/jank/read/lex.cpp +++ b/compiler+runtime/src/cpp/jank/read/lex.cpp @@ -266,6 +266,18 @@ namespace jank::read return none; } + static int cast_char32_t_as_int(char32_t const c) + { + if(c > static_cast(INT_MAX)) + { + throw std::runtime_error("Value out of range for wint_t"); + } + + // Perform the safe conversion + auto const safe_char = static_cast(c); + return safe_char; + } + static result convert_to_codepoint(native_persistent_string_view const sv, size_t const pos) { @@ -315,7 +327,7 @@ namespace jank::read static native_bool is_symbol_char(char32_t const c) { - return !std::iswspace(c) && !is_special_char(c) + return !std::iswspace(cast_char32_t_as_int(c)) && !is_special_char(c) && (std::iswalnum(static_cast(c)) != 0 || c == '_' || c == '-' || c == '/' || c == '?' || c == '!' || c == '+' || c == '*' || c == '=' || c == '.' || c == '&' || c == '<' || c == '>' || c == '#' || c == '%' || is_utf8_char(c)); @@ -379,7 +391,7 @@ namespace jank::read auto const ch(peek()); pos++; - if(ch.is_err() || std::iswspace(ch.expect_ok().character)) + if(ch.is_err() || std::iswspace(cast_char32_t_as_int(ch.expect_ok().character))) { return err(error{ token_start, "Expecting a valid character literal after \\" }); } @@ -516,7 +528,7 @@ namespace jank::read return err( error{ token_start, pos, "invalid ratio: expecting an integer denominator" }); } - else if(std::iswdigit(c) == 0) + else if(std::iswdigit(cast_char32_t_as_int(c)) == 0) { if(expecting_exponent) { @@ -633,7 +645,7 @@ namespace jank::read auto const oc(peek()); auto const c(oc.expect_ok().character); - if(oc.is_err() || std::iswspace(c)) + if(oc.is_err() || std::iswspace(cast_char32_t_as_int(c))) { ++pos; return err(