brodieG / vetr
Showing 2 of 17 files from the diff.

@@ -221,20 +221,19 @@
Loading
221 221
  char * str_new = R_alloc(len + 1, sizeof(char));
222 222
223 223
  // should we use memcpy?
224 -
  if(!strncpy(str_new, str, len)) {
225 -
    // nocov start
226 -
    error("%s%s",
227 -
      "Internal Error (CSR_strncopy): failed making copy of string for  ",
228 -
      "truncation; contact maintainer."
229 -
    );
230 -
    // nocov end
224 +
  if(len) {
225 +
    if(!strncpy(str_new, str, len)) {
226 +
      // nocov start
227 +
      error("%s%s",
228 +
        "Internal Error (CSR_strncopy): failed making copy of string for  ",
229 +
        "truncation; contact maintainer."
230 +
      );
231 +
      // nocov end
232 +
    }
231 233
  }
232 -
  // Ensure null terminated if last character is not NULL; this happens when
233 -
  // truncating to `maxlen`, also if zero len make sure that is a NULL
234 +
  // Ensure null terminated.
234 235
235 -
  if(!len) {
236 -
    str_new[0] = '\0';
237 -
  } else str_new[len] = '\0';
236 +
  str_new[len] = '\0';
238 237
239 238
  return str_new;
240 239
}
@@ -264,20 +263,20 @@
Loading
264 263
    if(len == maxlen && str[len])
265 264
      warning("CSR_strmcopy: truncated string longer than %d", maxlen);
266 265
267 -
    if(!strncpy(target, str, len)) {
268 -
      // nocov start
269 -
      error("%s%s",
270 -
        "Internal Error (CSR_strappend): failed making copy of string for  ",
271 -
        "truncation; contact maintainer."
272 -
      );
273 -
      // nocov end
266 +
    if(len) {
267 +
      if(!strncpy(target, str, len)) {
268 +
        // nocov start
269 +
        error("%s%s",
270 +
          "Internal Error (CSR_strappend): failed making copy of string for  ",
271 +
          "truncation; contact maintainer."
272 +
        );
273 +
        // nocov end
274 +
      }
274 275
    }
275 276
    // Ensure null terminated if last character is not NULL; this happens when
276 277
    // truncating to `maxlen`, also if zero len make sure that is a NULL
277 278
278 -
    if(!len) {
279 -
      target[0] = '\0';
280 -
    } else if(target[len - 1]) target[len] = '\0';
279 +
    target[len] = '\0';
281 280
  }
282 281
}
283 282
/*
@@ -484,18 +483,28 @@
Loading
484 483
        size_all = CSR_add_szt(size_all, sep_len);
485 484
      }
486 485
    }
486 +
    max_len = size_all;
487 487
    // Allocate and generate string
488 488
489 -
    char * str_new = R_alloc(size_all + 1, sizeof(char));
489 +
    char * str_new = R_alloc(max_len + 1, sizeof(char));
490 490
    char * str_cpy = str_new;
491 491
492 492
    for(i = 0; i < str_len; i++) {
493 493
      const char * to_copy = CHAR(STRING_ELT(str, i));
494 494
      CSR_strappend(str_cpy, to_copy, max_len);
495 -
      str_cpy += CSR_strmlen_x(to_copy, max_len);
495 +
      size_t copy_len = CSR_strmlen_x(to_copy, max_len);
496 +
      str_cpy += copy_len;
497 +
      // nocov start
498 +
      if(max_len < copy_len) error("Internal error: exhaused copy buffer.");
499 +
      // nocov end
500 +
      max_len -= copy_len;
496 501
      if(i < str_len - 1) {
497 502
        CSR_strappend(str_cpy, sep, max_len);
498 503
        str_cpy += sep_len;
504 +
        // nocov start
505 +
        if(max_len < sep_len) error("Internal error: exhaused copy buffer 2.");
506 +
        // nocov end
507 +
        max_len -= sep_len;
499 508
      }
500 509
    }
501 510
    *str_cpy = '\0';

@@ -108,9 +108,35 @@
Loading
108 108
109 109
### Testing C stuff; should be deleted eventually
110 110
##
111 -
###' @export
111 +
## @export
112 112
##test1 <- function(a) .Call(VALC_test1, a)
113 -
###' @export
113 +
## @export
114 114
##test2 <- function(a, b) .Call(VALC_test2, a, b)
115 -
###' @export
115 +
## @export
116 116
##test3 <- function(a, b, c) .Call(VALC_test3, a, b, c)
117 +
118 +
# Used for tests.  We can't really create them test time as `where` is not
119 +
# allowed, and even if it where, it only works becaue it seems topenv doesn't
120 +
# anticipate the possibility globalenv will not be on the search path.
121 +
122 +
#' Test Objects
123 +
#'
124 +
#' Objects used for testing purposes only.
125 +
#'
126 +
#' @rdname vetr-internal
127 +
#' @name vetr-interal
128 +
#' @keywords internal
129 +
130 +
setClass("vetr_foo", representation(a = "character", b = "numeric"))
131 +
132 +
#' @rdname vetr-internal
133 +
134 +
setClass("vetr_bar", representation(d = "numeric", c = "numeric"))
135 +
136 +
#' @rdname vetr-internal
137 +
138 +
setClass("vetr_baz", contains="vetr_foo", list(c="character"))
139 +
140 +
Foo <- setRefClass("Foo")
141 +
Bar <- setRefClass("Bar")
142 +
Files Coverage
R 100.00%
src 96.07%
Project Totals (35 files) 96.34%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading