From 1ade54ecd3c62844af36389ed1454cb37af62819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 8 Dec 2024 06:39:07 +0100 Subject: [PATCH] fix: Fix rchk errors --- NEWS.md | 6 +++--- src/statement.cpp | 10 +++++++--- src/types.cpp | 5 +++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/NEWS.md b/NEWS.md index ec12a8fe5..8b6cf03d2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -14,7 +14,7 @@ - Fix installation of extensions (#623). -- Fix rchk errors (#635). +- Fix rchk and UB errors (#635). - Avoid loading rlang during startup (#601). @@ -742,7 +742,7 @@ Major changes: - #440 Builds on Solaris & OpenBSD -*Note*: This release contains a bug in the Python API that leads to crashes when fetching strings to NumPy/Pandas #447 +*Note*: This release contains a bug in the Python API that leads to crashes when fetching strings to NumPy/Pandas #447 # duckdb 0.1.3 @@ -756,7 +756,7 @@ Major changes: * #390 Unused Column & Column Lifetime Optimizers * #402 String and compound keys in indices/primary keys * #406 Adaptive reordering of filter expressions - + # duckdb 0.1.2 diff --git a/src/statement.cpp b/src/statement.cpp index 33c94ee13..15baaa324 100644 --- a/src/statement.cpp +++ b/src/statement.cpp @@ -211,8 +211,9 @@ static cpp11::list construct_retlist(duckdb::unique_ptr stmt, stmt->parameters[param_idx] = val; } - // No protection, assigned immediately - out.push_back(rapi_execute(stmt, arrow, integer64)); + // Protection error is flagged by rchk + cpp11::sexp res = rapi_execute(stmt, arrow, integer64); + out.push_back(res); } return out; @@ -377,7 +378,10 @@ bool FetchArrowChunk(ChunkScanState &scan_state, ClientProperties options, Appen } else { D_ASSERT(generic_result->type == QueryResultType::MATERIALIZED_RESULT); auto result = (MaterializedQueryResult *)generic_result.get(); - return duckdb_execute_R_impl(result, integer64); + + // Avoid rchk warning, it sees QueryResult::~QueryResult() as an allocating function + cpp11::sexp out = duckdb_execute_R_impl(result, integer64); + return out; } } diff --git a/src/types.cpp b/src/types.cpp index 8ab208dd1..b691bfd5b 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -153,14 +153,15 @@ RType RApiTypes::DetectRType(SEXP v, bool integer64) { if (Rf_inherits(v, "data.frame")) { child_list_t child_types; R_xlen_t ncol = Rf_length(v); - SEXP names = GET_NAMES(v); + cpp11::strings names = GET_NAMES(v); for (R_xlen_t i = 0; i < ncol; ++i) { RType child = DetectRType(VECTOR_ELT(v, i), integer64); if (child == RType::UNKNOWN) { return (RType::UNKNOWN); } - child_types.push_back(std::make_pair(CHAR(STRING_ELT(names, i)), child)); + + child_types.push_back(std::make_pair(CHAR(names[i]), child)); } return RType::STRUCT(std::move(child_types));