Skip to content

Commit 6d66b81

Browse files
Fix issues mixing 'const'-ness of STRING_PTR_RO
1 parent a599557 commit 6d66b81

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/chmatch.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ static SEXP chmatchMain(SEXP x, SEXP table, int nomatch, bool chin, bool chmatch
3535
return ans;
3636
}
3737
// Since non-ASCII strings may be marked with different encodings, it only make sense to compare
38-
// the bytes under a same encoding (UTF-8) #3844 #3850
38+
// the bytes under a same encoding (UTF-8) #3844 #3850.
39+
// Not 'const' because we might SET_TRUELENGTH() below.
3940
SEXP *xd;
4041
if (isSymbol(x)) {
4142
xd = &sym;
4243
} else {
43-
xd = STRING_PTR_RO(PROTECT(coerceUtf8IfNeeded(x))); nprotect++;
44+
xd = (SEXP *)STRING_PTR_RO(PROTECT(coerceUtf8IfNeeded(x))); nprotect++;
4445
}
4546
const SEXP *td = STRING_PTR_RO(PROTECT(coerceUtf8IfNeeded(table))); nprotect++;
4647
if (xlen==1) {

src/coalesce.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ SEXP coalesce(SEXP x, SEXP inplaceArg) {
5353
first = PROTECT(copyAsPlain(first)); nprotect++;
5454
if (verbose) Rprintf(_("coalesce copied first item (inplace=FALSE)\n"));
5555
}
56-
void **valP = (void **)R_alloc(nval, sizeof(void *));
56+
const void **valP = (const void **)R_alloc(nval, sizeof(void *));
5757
switch(TYPEOF(first)) {
5858
case LGLSXP:
5959
case INTSXP: {
@@ -66,7 +66,7 @@ SEXP coalesce(SEXP x, SEXP inplaceArg) {
6666
finalVal = tt;
6767
break; // stop early on the first singleton that is not NA; minimizes deepest loop body below
6868
}
69-
valP[k++] = INTEGER(item);
69+
valP[k++] = INTEGER_RO(item);
7070
}
7171
const bool final=(finalVal!=NA_INTEGER);
7272
#pragma omp parallel for num_threads(getDTthreads(nrow, true))
@@ -89,7 +89,7 @@ SEXP coalesce(SEXP x, SEXP inplaceArg) {
8989
finalVal = tt;
9090
break;
9191
}
92-
valP[k++] = REAL(item);
92+
valP[k++] = REAL_RO(item);
9393
}
9494
const bool final = (finalVal!=NA_INTEGER64);
9595
#pragma omp parallel for num_threads(getDTthreads(nrow, true))
@@ -110,7 +110,7 @@ SEXP coalesce(SEXP x, SEXP inplaceArg) {
110110
finalVal = tt;
111111
break;
112112
}
113-
valP[k++] = REAL(item);
113+
valP[k++] = REAL_RO(item);
114114
}
115115
const bool final = !ISNAN(finalVal);
116116
#pragma omp parallel for num_threads(getDTthreads(nrow, true))
@@ -133,7 +133,7 @@ SEXP coalesce(SEXP x, SEXP inplaceArg) {
133133
finalVal = tt;
134134
break;
135135
}
136-
valP[k++] = COMPLEX(item);
136+
valP[k++] = COMPLEX_RO(item);
137137
}
138138
const bool final = !ISNAN(finalVal.r) && !ISNAN(finalVal.i);
139139
#pragma omp parallel for num_threads(getDTthreads(nrow, true))

0 commit comments

Comments
 (0)