Skip to content

Commit

Permalink
get_option returns null terminator for test driver
Browse files Browse the repository at this point in the history
  • Loading branch information
paleolimbot committed Nov 6, 2023
1 parent 313245b commit f911777
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions r/adbcdrivermanager/src/driver_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ class Option {
switch (type_) {
case TYPE_STRING: {
const std::string& value = GetStringUnsafe();
if (*length < value.size()) {
*length = value.size();
size_t value_size_with_terminator = value.size() + 1;
if (*length < value_size_with_terminator) {
*length = value_size_with_terminator;
} else {
memcpy(out, value.data(), value.size());
memcpy(out, value.data(), value_size_with_terminator);
}

return ADBC_STATUS_OK;
Expand Down
2 changes: 1 addition & 1 deletion r/adbcdrivermanager/src/options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ static inline SEXP adbc_get_option(SEXP obj_xptr, SEXP key_sexp, SEXP error_xptr
PROTECT(bytes_sexp);

char* result = reinterpret_cast<char*>(RAW(bytes_sexp));
SEXP result_char = PROTECT(Rf_mkCharLenCE(result, Rf_length(bytes_sexp), CE_UTF8));
SEXP result_char = PROTECT(Rf_mkCharLenCE(result, Rf_length(bytes_sexp) - 1, CE_UTF8));
SEXP result_string = PROTECT(Rf_ScalarString(result_char));
UNPROTECT(3);
return result_string;
Expand Down

0 comments on commit f911777

Please sign in to comment.