Skip to content

Commit

Permalink
Ensure that prev_mask is always protected (#256)
Browse files Browse the repository at this point in the history
* Ensure that `prev_mask` is always protected

* NEWS bullet

* Update NEWS.md

Co-authored-by: Lionel Henry <[email protected]>

Co-authored-by: Lionel Henry <[email protected]>
  • Loading branch information
DavisVaughan and lionel- authored Mar 17, 2022
1 parent da4e283 commit 70d7db9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# magrittr (development version)

* Fixed a C level protection issue in `%>%` (#256).

# magrittr 2.0.2

* New eager pipe `%!>%` for sequential evaluation (#247). Consider
Expand Down
5 changes: 4 additions & 1 deletion src/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ SEXP eval_pipe(void* data) {
static
SEXP eval_pipe_lazy(SEXP exprs, SEXP env) {
SEXP prev_mask = env;
PROTECT_INDEX prev_mask_pi;
PROTECT_WITH_INDEX(prev_mask, &prev_mask_pi);

PROTECT_INDEX mask_pi;
PROTECT_WITH_INDEX(R_NilValue, &mask_pi);
Expand All @@ -169,6 +171,7 @@ SEXP eval_pipe_lazy(SEXP exprs, SEXP env) {

exprs = rest;
prev_mask = mask;
REPROTECT(prev_mask, prev_mask_pi);
}

// For compatibility, allow last expression to be `return()`.
Expand All @@ -182,7 +185,7 @@ SEXP eval_pipe_lazy(SEXP exprs, SEXP env) {
// recursive evaluation of `.` bindings in the different masks.
SEXP out = Rf_eval(last, prev_mask);

UNPROTECT(1);
UNPROTECT(2);
return out;
}

Expand Down

0 comments on commit 70d7db9

Please sign in to comment.