Skip to content

Commit

Permalink
fix(r/adbcdrivermanager): Ensure test driver includes null terminator…
Browse files Browse the repository at this point in the history
… when fetching string option (#1258)

Closes #1256; closes #1129.
  • Loading branch information
paleolimbot authored Nov 6, 2023
1 parent 89c19c3 commit 248003f
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 248003f

Please sign in to comment.