Skip to content

Commit

Permalink
Fix protect stack imbalance
Browse files Browse the repository at this point in the history
Identified by Tomas Kalibera's rchk tool.
  • Loading branch information
joshuaulrich committed Oct 11, 2022
1 parent 4b93da7 commit 9f2b9c1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/tryXts.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,20 @@
SEXP tryXts (SEXP x)
{
if( !Rf_asInteger(isXts(x)) ) {
int P = 0;
SEXP s, t, result, env, str_xts;
PROTECT(s = t = allocList(2));
PROTECT(s = t = allocList(2)); P++;
SET_TYPEOF(s, LANGSXP);
SETCAR(t, install("try.xts")); t = CDR(t);
SETCAR(t, x); t=CDR(t);
PROTECT(str_xts = mkString("xts"));
PROTECT(env = R_FindNamespace(str_xts));
PROTECT(result = eval(s, env));
PROTECT(str_xts = mkString("xts")); P++;
PROTECT(env = R_FindNamespace(str_xts)); P++;
PROTECT(result = eval(s, env)); P++;
if( !Rf_asInteger(isXts(result)) ) {
UNPROTECT(2);
UNPROTECT(P);
error("rbind.xts requires xtsible data");
}
UNPROTECT(2);
UNPROTECT(P);
return result;
}
return x;
Expand Down

0 comments on commit 9f2b9c1

Please sign in to comment.