Skip to content

Commit

Permalink
more sanity checking of arguments using asRbool
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@87783 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
ripley committed Feb 21, 2025
1 parent 3471722 commit 4555d50
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/main/apply.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* R : A Computer Language for Statistical Data Analysis
* Copyright (C) 2000-2024 The R Core Team
* Copyright (C) 2000-2025 The R Core Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -398,7 +398,7 @@ attribute_hidden SEXP do_islistfactor(SEXP call, SEXP op, SEXP args, SEXP rho)
{
checkArity(op, args);
SEXP X = CAR(args);
Rboolean recursive = asLogical(CADR(args));
Rboolean recursive = asRbool(CADR(args), call);
int n = length(X);
if(n == 0 || !isVectorList(X))
return ScalarLogical(FALSE);
Expand Down
6 changes: 3 additions & 3 deletions src/main/bind.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* R : A Computer Language for Statistical Data Analysis
* Copyright (C) 1997--2024 The R Core Team
* Copyright (C) 1997--2025 The R Core Team
* Copyright (C) 2002--2020 The R Foundation
* Copyright (C) 1995, 1996 Robert Gentleman and Ross Ihaka
*
Expand Down Expand Up @@ -916,8 +916,8 @@ attribute_hidden SEXP do_unlist(SEXP call, SEXP op, SEXP args, SEXP env)
/* by an optional "recursive" argument. */

PROTECT(args = CAR(ans));
Rboolean recurse = asLogical(CADR(ans));
Rboolean usenames = asLogical(CADDR(ans));
Rboolean recurse = asRbool(CADR(ans), call);
Rboolean usenames = asRbool(CADDR(ans), call);
Rboolean lenient = TRUE; // was (implicitly!) FALSE up to R 3.0.1

/* Determine the type of the returned value. */
Expand Down
2 changes: 1 addition & 1 deletion src/main/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ attribute_hidden SEXP do_traceOnOff(SEXP call, SEXP op, SEXP args, SEXP rho)
prev = trace ? GET_TRACE_STATE : GET_DEBUG_STATE;

if(length(onOff) > 0) {
Rboolean _new = asLogical(onOff);
int _new = asLogical(onOff);
if(_new == TRUE || _new == FALSE)
if(trace) SET_TRACE_STATE(_new);
else SET_DEBUG_STATE(_new);
Expand Down
2 changes: 1 addition & 1 deletion src/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ attribute_hidden SEXP do_browser(SEXP call, SEXP op, SEXP args, SEXP rho)
if (TYPEOF(expr) == ENVSXP)
rho = expr;

Rboolean ignoreHook = asLogical(CAR(CDR(CDDDR(argList))));
Rboolean ignoreHook = asRbool(CAR(CDR(CDDDR(argList))), call);
if (ignoreHook) {
R_browserRepl(rho);
UNPROTECT(1); /* argList */
Expand Down
5 changes: 3 additions & 2 deletions src/main/memory.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* R : A Computer Language for Statistical Data Analysis
* Copyright (C) 1998--2024 The R Core Team.
* Copyright (C) 1998--2025 The R Core Team.
* Copyright (C) 1995, 1996 Robert Gentleman and Ross Ihaka
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -2040,7 +2040,7 @@ attribute_hidden SEXP do_gctorture(SEXP call, SEXP op, SEXP args, SEXP rho)
checkArity(op, args);

if (isLogical(CAR(args))) {
Rboolean on = asLogical(CAR(args));
Rboolean on = asRbool(CAR(args), call);
if (on == NA_LOGICAL) gap = NA_INTEGER;
else if (on) gap = 1;
else gap = 0;
Expand Down Expand Up @@ -2358,6 +2358,7 @@ long double *R_allocLD(size_t nelem)
#elif __GNUC__
// This is C99, but do not rely on it.
// Apple clang warns this is gnu extension.
# pragma clang diagnostic ignored "-Wgnu-offsetof-extensions"
size_t ld_align = offsetof(struct { char __a; long double __b; }, __b);
#else
size_t ld_align = 0x0F; // value of x86_64, known others are 4 or 8
Expand Down
4 changes: 2 additions & 2 deletions src/main/objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ static SEXP inherits3(SEXP x, SEXP what, SEXP which)

if( !isLogical(which) || (LENGTH(which) != 1) )
error(_("'which' must be a length 1 logical vector"));
Rboolean isvec = asLogical(which);
Rboolean isvec = asRbool(which, R_NilValue);

if(isvec)
PROTECT(rval = allocVector(INTSXP, nwhat));
Expand Down Expand Up @@ -1231,7 +1231,7 @@ static SEXP R_isMethodsDispatchOn(SEXP onOff)
R_stdGen_ptr_t old = R_get_standardGeneric_ptr();
int ival = !NOT_METHODS_DISPATCH_PTR(old);
if(length(onOff) > 0) {
Rboolean onOffValue = asLogical(onOff);
Rboolean onOffValue = asRbool(onOff, R_NilValue);
if(onOffValue == NA_INTEGER)
error(_("'onOff' must be TRUE or FALSE"));
else if(onOffValue == FALSE)
Expand Down
4 changes: 2 additions & 2 deletions src/main/platform.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* R : A Computer Language for Statistical Data Analysis
* Copyright (C) 1998--2024 The R Core Team
* Copyright (C) 1998--2025 The R Core Team
* Copyright (C) 1995, 1996 Robert Gentleman and Ross Ihaka
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -318,7 +318,7 @@ attribute_hidden SEXP do_fileshow(SEXP call, SEXP op, SEXP args, SEXP rho)
fn = CAR(args); args = CDR(args);
hd = CAR(args); args = CDR(args);
tl = CAR(args); args = CDR(args);
dl = (Rboolean) asLogical(CAR(args)); args = CDR(args);
dl = asRbool(CAR(args), call); args = CDR(args);
pg = CAR(args);
n = 0; /* -Wall */
if (!isString(fn) || (n = LENGTH(fn)) < 1)
Expand Down
4 changes: 2 additions & 2 deletions src/main/sysutils.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* R : A Computer Language for Statistical Data Analysis
* Copyright (C) 1997-2024 The R Core Team
* Copyright (C) 1997-2025 The R Core Team
* Copyright (C) 1995-1996 Robert Gentleman and Ross Ihaka
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -242,7 +242,7 @@ attribute_hidden SEXP do_interactive(SEXP call, SEXP op, SEXP args, SEXP rho)
attribute_hidden SEXP do_tempdir(SEXP call, SEXP op, SEXP args, SEXP env)
{
checkArity(op, args);
Rboolean check = asLogical(CAR(args));
Rboolean check = asRbool(CAR(args), call);
if(check && !R_isWriteableDir(R_TempDir)) {
R_TempDir = NULL;
R_reInitTempDir(/* die_on_fail = */ FALSE);
Expand Down

0 comments on commit 4555d50

Please sign in to comment.