Skip to content

Commit 07f2802

Browse files
author
ripley
committed
follow up to r87432
git-svn-id: https://svn.r-project.org/R/trunk@87462 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent ade1453 commit 07f2802

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/main/qsort.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,14 @@ attribute_hidden SEXP do_qsort(SEXP call, SEXP op, SEXP args, SEXP rho)
100100
setAttrib(ans, R_NamesSymbol, ansnames);
101101
UNPROTECT(4);
102102
return ans;
103-
} else {
104-
if(x_int)
105-
R_qsort_int(ivx, 1, n);
106-
else
107-
R_qsort(vx, 1, n);
103+
} else { // not indx_ret
104+
// do not need to sort 0-length array
105+
if( n > 0) {
106+
if(x_int)
107+
R_qsort_int(ivx, 1, n);
108+
else
109+
R_qsort(vx, 1, n);
110+
}
108111

109112
UNPROTECT(1);
110113
return sx;

tests/reg-tests-1e.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,14 @@ stopifnot(identical(gen, isGeneric("+", getName = TRUE)), # the latter always wo
16691669
identical(gen, structure("+", package = "base")),
16701670
isGeneric("+"), isGeneric("+", fdef = `+`))
16711671

1672+
## These gave array-accss errors and perhaps segfaults in R <= 4.4.2
1673+
ix <- integer(0)
1674+
sort.int(ix, method = "quick")
1675+
sort.int(ix, method = "quick", index.return = TRUE)
1676+
x <- double(0)
1677+
sort.int(x, method = "quick")
1678+
sort.int(x, method = "quick", index.return = TRUE)
1679+
16721680

16731681

16741682
## keep at end

0 commit comments

Comments
 (0)