Skip to content

Commit 7aca15e

Browse files
False negatives in alloc check linter
1 parent aa58fd6 commit 7aca15e

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

.ci/linters/c/alloc_linter.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ alloc_linter = function(c_obj) {
66
lines = c_obj$lines
77
# Be a bit more precise to avoid mentions in comments, and allow
88
# malloc(0) to be used for convenience (e.g. #6757)
9-
alloc_lines = grep(R"{=\s*([(]\w+\s*[*][)])?[mc]alloc[(][^0]}", lines)
9+
alloc_lines = grep(R"{=\s*([(]\w+\s*[*][)])?\s*[mc]alloc[(][^0]}", lines)
1010
if (!length(alloc_lines)) return()
1111
# int *tmp=(int*)malloc(...); or just int tmp=malloc(...);
1212
alloc_keys = lines[alloc_lines] |>
@@ -31,7 +31,7 @@ alloc_linter = function(c_obj) {
3131
cat("FILE: ", c_obj$path, "; LINES: ", head(bad_lines_idx, 1L), "-", tail(bad_lines_idx, 1L), "\n", sep="")
3232
writeLines(lines[bad_lines_idx])
3333
cat(strrep("-", max(nchar(lines[bad_lines_idx]))), "\n", sep="")
34-
stop("Expected the malloc()/calloc() usage above to be followed immediately by error checking.", call.=FALSE)
34+
stop("Expected the malloc()/calloc() usage above to be followed immediately by error checking (using '!', not '==NULL').", call.=FALSE)
3535
}
3636
})
3737
}

src/assign.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ SEXP assign(SEXP dt, SEXP rows, SEXP cols, SEXP newcolnames, SEXP values)
647647
// check the position of the first appearance of an assigned column in the index.
648648
// the new index will be truncated to this position.
649649
char *s4 = (char*) malloc(strlen(c1) + 3);
650-
if(s4 == NULL){
650+
if (!s4) {
651651
internal_error(__func__, "Couldn't allocate memory for s4"); // # nocov
652652
}
653653
memcpy(s4, c1, strlen(c1));
@@ -657,7 +657,7 @@ SEXP assign(SEXP dt, SEXP rows, SEXP cols, SEXP newcolnames, SEXP values)
657657
for(int i = 0; i < xlength(assignedNames); i++){
658658
tc2 = CHAR(STRING_ELT(assignedNames, i));
659659
char *s5 = (char*) malloc(strlen(tc2) + 5); //4 * '_' + \0
660-
if(s5 == NULL){
660+
if (!s5) {
661661
free(s4); // # nocov
662662
internal_error(__func__, "Couldn't allocate memory for s5"); // # nocov
663663
}

0 commit comments

Comments
 (0)