Skip to content

Commit

Permalink
- Fix problem surfaced by R-2.5.0. Namely, check for a R_NilValue return
Browse files Browse the repository at this point in the history
  from R_Parsevector() before trying to feed the result to VECTOR_ELT().
  This happens, for example, when a parse error is caught. Reported by
  Steve Singer.
  • Loading branch information
jconway committed Jun 7, 2007
1 parent f7a3640 commit 07f8448
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions plr.c
Expand Up @@ -1236,15 +1236,21 @@ plr_parse_func_body(const char *body)
{
SEXP rbody;
SEXP fun;
SEXP tmp;
int status;

PROTECT(rbody = NEW_CHARACTER(1));
SET_STRING_ELT(rbody, 0, COPY_TO_USER_STRING(body));

PROTECT(fun = VECTOR_ELT(R_PARSEVECTOR(rbody, -1, &status), 0));
tmp = PROTECT(R_PARSEVECTOR(rbody, -1, &status));
if (tmp != R_NilValue)
PROTECT(fun = VECTOR_ELT(tmp, 0));
else
PROTECT(fun = R_NilValue);

if (status != PARSE_OK)
{
UNPROTECT(2);
UNPROTECT(3);
if (last_R_error_msg)
ereport(ERROR,
(errcode(ERRCODE_DATA_EXCEPTION),
Expand All @@ -1258,7 +1264,7 @@ plr_parse_func_body(const char *body)
"in \"%s\".", body)));
}

UNPROTECT(2);
UNPROTECT(3);
return(fun);
}

Expand Down

0 comments on commit 07f8448

Please sign in to comment.