Skip to content

Commit 558084e

Browse files
authored
switched to memset (#7231)
* switched to memset * segfault fixed (hopefully) * improved constness
1 parent 8dff81f commit 558084e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/nqrecreateindices.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
#include "data.table.h"
2+
#include <string.h>
23

34
// TODO: Add oxygen style comments and cleanup var names.
45
// See other TODOs inside the function.
56
SEXP nqRecreateIndices(SEXP xo, SEXP len, SEXP indices, SEXP nArg, SEXP nomatch)
67
{
7-
R_len_t n = INTEGER(nArg)[0], xn = length(xo);
8+
const R_len_t n = INTEGER_RO(nArg)[0], xn = length(xo);
89
SEXP ans, newstarts, newlen;
910
ans = PROTECT(allocVector(VECSXP, 2));
1011
SET_VECTOR_ELT(ans, 0, (newstarts = allocVector(INTSXP, n)));
1112
SET_VECTOR_ELT(ans, 1, (newlen = allocVector(INTSXP, n)));
1213

1314
int *inewlen = INTEGER(newlen);
14-
const int *iindices = INTEGER(indices);
15-
const int *ilen = INTEGER(len);
16-
const int *ixo = INTEGER(xo);
17-
const int inomatch = isNull(nomatch) ? 0 : INTEGER(nomatch)[0];
15+
const int *iindices = INTEGER_RO(indices);
16+
const int *ilen = INTEGER_RO(len);
17+
const int *ixo = INTEGER_RO(xo);
18+
const int inomatch = isNull(nomatch) ? 0 : INTEGER_RO(nomatch)[0];
1819
int *inewstarts = INTEGER(newstarts);
1920

20-
for (int i = 0; i < n; i++) inewlen[i] = 0;
21+
memset(inewlen, 0, n * sizeof(int));
2122

2223
// simplifying logic ... also fixes #2275
2324
for (int i = 0; i < length(indices); i++) {

0 commit comments

Comments
 (0)