Skip to content

Commit 89a3e99

Browse files
committed
Fix sprintf use for CRAN
1 parent 6305043 commit 89a3e99

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/collapse_pretty.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ SEXP C_collapse_array_pretty_inner(SEXP x) {
8181
error("x must character vector.");
8282

8383
//calculate required space
84-
int len = length(x);
84+
size_t len = Rf_length(x);
8585
size_t nchar_total = 0;
8686
for (int i=0; i<len; i++) {
8787
nchar_total += strlen(translateCharUTF8(STRING_ELT(x, i)));

src/escape_chars.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ SEXP C_escape_chars_one(SEXP x) {
8787
default:
8888
//control characters need explicit \u00xx escaping
8989
if (*cur >= 0x00 && *cur <= 0x1f){
90-
sprintf(outcur, "\\u%04x", *cur);
90+
snprintf(outcur, 7, "\\u%04x", *cur);
9191
outcur += 5; //extra length
9292
break;
9393
}

src/modp_numtoa.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ size_t modp_dtoa(double value, char* str, int prec)
161161
which can be 100s of characters overflowing your buffers == bad
162162
*/
163163
if (value > thres_max) {
164-
sprintf(str, "%e", neg ? -value : value);
164+
snprintf(str, 13, "%e", neg ? -value : value);
165165
return strlen(str);
166166
}
167167

@@ -265,7 +265,7 @@ size_t modp_dtoa2(double value, char* str, int prec)
265265
which can be 100s of characters overflowing your buffers == bad
266266
*/
267267
if (value > thres_max) {
268-
sprintf(str, "%e", neg ? -value : value);
268+
snprintf(str, 13, "%e", neg ? -value : value);
269269
return strlen(str);
270270
}
271271

0 commit comments

Comments
 (0)