Skip to content

Commit a095f11

Browse files
author
ripley
committed
c88134 lacked protection
git-svn-id: https://svn.r-project.org/R/trunk@88140 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent f629b66 commit a095f11

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/main/coerce.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,18 @@ attribute_hidden Rcomplex ComplexFromString(SEXP x, int *warn)
298298

299299
attribute_hidden SEXP StringFromLogical(int x, int *warn)
300300
{
301-
static SEXP TrueCh = NULL, FalseCh = NULL; /* constants, initialized when first used */
301+
static SEXP lglcache = NULL;
302302
if (x == NA_LOGICAL) return NA_STRING;
303-
else if (x)
304-
return TrueCh != NULL ? TrueCh : (TrueCh = mkChar("TRUE"));
305-
else return FalseCh!= NULL ? FalseCh : (FalseCh = mkChar("FALSE"));
303+
if (lglcache == NULL) {
304+
lglcache = allocVector(STRSXP, 2);
305+
R_PreserveObject(lglcache);
306+
SET_STRING_ELT(lglcache, 0, mkChar("FALSE"));
307+
SET_STRING_ELT(lglcache, 1, mkChar("TRUE"));
308+
}
309+
return STRING_ELT(lglcache, x ? 1 : 0);
306310
}
307311

308-
/* The conversions for small non-negative integers are saved in a chache. */
312+
/* The conversions for small non-negative integers are saved in a cache. */
309313
#define SFI_CACHE_SIZE 512
310314
static SEXP sficache = NULL;
311315

0 commit comments

Comments
 (0)