From 2139172191d9efeb1d60bcc53d2c96fb3eff5b6d Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Sun, 21 Apr 2024 23:59:20 -0700 Subject: [PATCH] error in scan() for string NA when na.strings is empty --- src/main/scan.c | 4 ++-- tests/reg-tests-1e.R | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/scan.c b/src/main/scan.c index f78ea1b0723..c5a9686bdc7 100644 --- a/src/main/scan.c +++ b/src/main/scan.c @@ -522,8 +522,8 @@ static void extractItem(char *buffer, SEXP ans, R_xlen_t i, LocalData *d) if (isNAstring(buffer, 0, d)) REAL(ans)[i] = NA_REAL; else { - REAL(ans)[i] = Strtod(buffer, &endp, TRUE, d); - if (!isBlankString(endp)) + REAL(ans)[i] = Strtod(buffer, &endp, FALSE, d); + if (!isBlankString(endp) || REAL(ans)[i] == NA_REAL) expected("a real", buffer, d); } break; diff --git a/tests/reg-tests-1e.R b/tests/reg-tests-1e.R index 8723e0a8faa..76d116ae200 100644 --- a/tests/reg-tests-1e.R +++ b/tests/reg-tests-1e.R @@ -1332,7 +1332,8 @@ stopifnot(exprs = { }) ## as.raw(rl) and as.integer(rl) failed in R <= 4.4.x - +stopifnot("'NA' shouldn't parse as NA if it's missing from na.strings in scan()" = + tryCatch(scan(text="NA", what=double(), na.strings=character(), quiet=TRUE), error = \(c) TRUE)) ## keep at end rbind(last = proc.time() - .pt,