Skip to content

Commit 2ff32f6

Browse files
committed
Fix valgrind error in r_lgl_which()
1 parent 79540a2 commit 2ff32f6

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

cran-comments.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
Fixes a bug in knitted markdown documents which caused backtraces to be displayed when they shouldn't.
33

4+
Also fixes one valgrind issue (I can't reproduce the uninitialised value warning locally).
5+
46
## Test environments
57

68
* local OS X install: release

src/lib/vec-lgl.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,15 @@ sexp* r_lgl_which(sexp* x, bool na_propagate) {
4949
int* data = r_lgl_deref(x);
5050

5151
r_ssize which_n = r_lgl_sum(x, na_propagate);
52+
53+
if (which_n > INT_MAX) {
54+
r_abort("Internal error: Can't fit result of `r_lgl_which()` in an integer vector");
55+
}
56+
5257
sexp* which = KEEP(r_new_vector(r_type_integer, which_n));
5358
int* which_data = r_int_deref(which);
5459

55-
for (r_ssize i = 0; i < n; ++i, ++data) {
60+
for (int i = 0; i < n; ++i, ++data) {
5661
int elt = *data;
5762

5863
if (elt) {

0 commit comments

Comments
 (0)