Skip to content

Commit 41a7b3b

Browse files
authored
rchk fixes (#571)
* Avoid the "multiple allocating arguments" pattern * PROTECT()/UNPROTECT() `val` * Protect `cli_warn` too
1 parent f480f36 commit 41a7b3b

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/vroom_chr.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ cpp11::strings read_chr(vroom_vec_info* info) {
2626
for (auto b = col->begin(), e = col->end(); b != e; ++b) {
2727
auto str = *b;
2828
auto val = info->locale->encoder_.makeSEXP(str.begin(), str.end(), true);
29+
PROTECT(val);
2930
if (Rf_xlength(val) < str.end() - str.begin()) {
3031
info->errors->add_error(
3132
b.index(), col->get_index(), "", "embedded null", b.filename());
3233
}
3334

3435
SET_STRING_ELT(out, i++, check_na(nas, val));
36+
UNPROTECT(1);
3537
}
3638
});
3739

src/vroom_errors.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ class vroom_errors {
8787
have_warned_ = true;
8888
// it is intentional that we aren't using cpp11::package
8989
// https://github.com/tidyverse/vroom/commit/984a3e5e37e124feacfec3d184dbeb02eb1145c4
90-
static auto cli_warn = Rf_findFun(
91-
Rf_install("cli_warn"),
92-
Rf_findVarInFrame(R_NamespaceRegistry, Rf_install("cli")));
90+
SEXP cli_ns = Rf_findVarInFrame(R_NamespaceRegistry, Rf_install("cli"));
91+
PROTECT(cli_ns);
92+
SEXP cli_warn = Rf_findFun(Rf_install("cli_warn"), cli_ns);
93+
PROTECT(cli_warn);
9394
cpp11::strings bullets({
9495
"w"_nm = "One or more parsing issues, call {.fun problems} on your data frame for details, e.g.:",
9596
" "_nm = "dat <- vroom(...)",
@@ -99,6 +100,7 @@ class vroom_errors {
99100
bullets,
100101
Rf_mkString("vroom_parse_issue"));
101102
Rf_eval(cli_warn_call, R_EmptyEnv);
103+
UNPROTECT(2);
102104
}
103105
}
104106

0 commit comments

Comments
 (0)