Skip to content

Commit 0f6d152

Browse files
authored
Revamp .clang-tidy (#65)
* Revamps .clang-tidy to be a (small) exclusion list instead of (large) inclusion list, with updates to code * Changes [[clang::suppress]] to NOLINT for portability * Fixes unused param warning * Updates formatting for clang-format
1 parent f96935f commit 0f6d152

11 files changed

Lines changed: 79 additions & 172 deletions

File tree

.clang-tidy

Lines changed: 4 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,7 @@
11
# Generated from CLion Inspection settings
22
---
3-
Checks: '-*,
4-
bugprone-argument-comment,
5-
bugprone-assert-side-effect,
6-
bugprone-bad-signal-to-kill-thread,
7-
bugprone-branch-clone,
8-
bugprone-copy-constructor-init,
9-
bugprone-dangling-handle,
10-
bugprone-dynamic-static-initializers,
11-
bugprone-fold-init-type,
12-
bugprone-forward-declaration-namespace,
13-
bugprone-forwarding-reference-overload,
14-
bugprone-inaccurate-erase,
15-
bugprone-incorrect-roundings,
16-
bugprone-integer-division,
17-
bugprone-lambda-function-name,
18-
bugprone-macro-parentheses,
19-
bugprone-macro-repeated-side-effects,
20-
bugprone-misplaced-operator-in-strlen-in-alloc,
21-
bugprone-misplaced-pointer-arithmetic-in-alloc,
22-
bugprone-misplaced-widening-cast,
23-
bugprone-move-forwarding-reference,
24-
bugprone-multiple-statement-macro,
25-
bugprone-no-escape,
26-
bugprone-parent-virtual-call,
27-
bugprone-posix-return,
28-
bugprone-reserved-identifier,
29-
bugprone-sizeof-container,
30-
bugprone-sizeof-expression,
31-
bugprone-spuriously-wake-up-functions,
32-
bugprone-string-constructor,
33-
bugprone-string-integer-assignment,
34-
bugprone-string-literal-with-embedded-nul,
35-
bugprone-suspicious-enum-usage,
36-
bugprone-suspicious-include,
37-
bugprone-suspicious-memset-usage,
38-
bugprone-suspicious-missing-comma,
39-
bugprone-suspicious-semicolon,
40-
bugprone-suspicious-string-compare,
41-
bugprone-suspicious-memory-comparison,
42-
bugprone-suspicious-realloc-usage,
43-
bugprone-swapped-arguments,
44-
bugprone-terminating-continue,
45-
bugprone-throw-keyword-missing,
46-
bugprone-too-small-loop-variable,
47-
bugprone-undefined-memory-manipulation,
48-
bugprone-undelegated-constructor,
49-
bugprone-unhandled-self-assignment,
50-
bugprone-unused-raii,
51-
bugprone-unused-return-value,
52-
bugprone-use-after-move,
53-
bugprone-virtual-near-miss,
54-
cert-dcl21-cpp,
55-
cert-dcl58-cpp,
56-
#cert-err34-c,
57-
cert-err52-cpp,
58-
cert-err60-cpp,
59-
cert-flp30-c,
60-
#cert-msc50-cpp,
61-
#cert-msc51-cpp,
62-
cert-str34-c,
63-
cppcoreguidelines-avoid-shadowing,
64-
cppcoreguidelines-interfaces-global-init,
65-
cppcoreguidelines-pro-type-member-init,
66-
cppcoreguidelines-pro-type-static-cast-downcast,
67-
cppcoreguidelines-slicing,
68-
google-default-arguments,
69-
google-explicit-constructor,
70-
google-runtime-operator,
71-
hicpp-exception-baseclass,
72-
hicpp-multiway-paths-covered,
73-
misc-misplaced-const,
74-
misc-new-delete-overloads,
75-
misc-no-recursion,
76-
misc-non-copyable-objects,
77-
misc-throw-by-value-catch-by-reference,
78-
misc-unconventional-assign-operator,
79-
misc-uniqueptr-reset-release,
80-
modernize-avoid-bind,
81-
modernize-concat-nested-namespaces,
82-
modernize-deprecated-headers,
83-
modernize-deprecated-ios-base-aliases,
84-
modernize-loop-convert,
85-
modernize-make-shared,
86-
modernize-make-unique,
87-
modernize-pass-by-value,
88-
modernize-raw-string-literal,
89-
modernize-redundant-void-arg,
90-
modernize-replace-auto-ptr,
91-
modernize-replace-disallow-copy-and-assign-macro,
92-
modernize-replace-random-shuffle,
93-
modernize-return-braced-init-list,
94-
modernize-shrink-to-fit,
95-
modernize-unary-static-assert,
96-
modernize-use-auto,
97-
modernize-use-bool-literals,
98-
modernize-use-emplace,
99-
modernize-use-equals-default,
100-
modernize-use-equals-delete,
101-
modernize-use-nodiscard,
102-
modernize-use-noexcept,
103-
modernize-use-nullptr,
104-
modernize-use-override,
105-
modernize-use-transparent-functors,
106-
modernize-use-uncaught-exceptions,
107-
mpi-buffer-deref,
108-
mpi-type-mismatch,
109-
openmp-use-default-none,
110-
performance-faster-string-find,
111-
performance-for-range-copy,
112-
performance-implicit-conversion-in-loop,
113-
performance-inefficient-algorithm,
114-
performance-inefficient-string-concatenation,
115-
performance-inefficient-vector-operation,
116-
performance-move-const-arg,
117-
performance-move-constructor-init,
118-
performance-no-automatic-move,
119-
performance-noexcept-move-constructor,
120-
performance-trivially-destructible,
121-
performance-type-promotion-in-math-fn,
122-
performance-unnecessary-copy-initialization,
123-
performance-unnecessary-value-param,
124-
portability-simd-intrinsics,
125-
readability-avoid-const-params-in-decls,
126-
readability-braces-around-statements,
127-
readability-const-return-type,
128-
readability-container-size-empty,
129-
readability-convert-member-functions-to-static,
130-
readability-delete-null-pointer,
131-
readability-deleted-default,
132-
readability-inconsistent-declaration-parameter-name,
133-
#readability-magic-numbers,
134-
readability-make-member-function-const,
135-
#readability-math-missing-parentheses,
136-
readability-misleading-indentation,
137-
readability-misplaced-array-index,
138-
readability-redundant-control-flow,
139-
readability-redundant-declaration,
140-
readability-redundant-function-ptr-dereference,
141-
readability-redundant-smartptr-get,
142-
readability-redundant-string-cstr,
143-
readability-redundant-string-init,
144-
readability-simplify-subscript-expr,
145-
readability-static-accessed-through-instance,
146-
readability-static-definition-in-anonymous-namespace,
147-
readability-string-compare,
148-
readability-uniqueptr-delete-release,
149-
readability-use-anyofallof'
3+
Checks: '
4+
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
5+
-clang-analyzer-unix.Errno,
6+
-clang-analyzer-security.insecureAPI.rand'
1507
WarningsAsErrors: '*'

src/common/exitCodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ typedef enum {
2020
EXIT_CODE_BAD_PARAMETER_VALUE = 3,
2121
EXIT_CODE_UNKNOWN_EVENT_TYPE_OR_PARAM = 4,
2222
EXIT_CODE_INPUT_FILE_ERROR = 5,
23-
EXIT_CODE_FILE_OPEN_ERROR = 6,
23+
EXIT_CODE_FILE_OPEN_OR_READ_ERROR = 6,
2424
} exit_code_t;
2525

2626
#endif

src/common/paramchange.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ static double **aggedModel = NULL; /* aggregated model (intitialized to NULL b/c
4545
we may never malloc this array) made global so don't have to
4646
re-allocate memory all the time only holds model output between
4747
startOpt and endOpt */
48-
static double unaggedWeight = 0.0; /* if aggregation is done, weight of
49-
unaggregated data in optimization (0 -> only use aggregated data)
50-
*/
48+
// Commenting out as all uses are commented out
49+
// static double unaggedWeight = 0.0; /* if aggregation is done, weight of
50+
// unaggregated data in optimization (0 -> only use aggregated
51+
// data)
52+
// */
5153

5254
typedef struct AggregateInfoStruct { // set at beginning of program
5355
int startPt, endPt; // indices of data point to start and stop at
@@ -398,9 +400,13 @@ void computeAggedData(double **theAggedData, double **origArray,
398400
above]
399401
*/
400402

403+
// Apr-25-2025: clang-tidy asserts that there are issues with this function,
404+
// and it is not currently being used. Disabling for now, not worth
405+
// spending time on.
401406
// 6/9/11: For now we don't do anything with the cost function or data Type
402407
// weights - we just want to make it consistent with the difference function
403408
// above so we don't get an error.
409+
#if 0
404410
double aggedDifference(double *sigma, OutputInfo *outputInfo, int loc,
405411
SpatialParams *spatialParams, double paramWeight,
406412
void (*modelF)(double **, int, int *, SpatialParams *,
@@ -492,6 +498,7 @@ double aggedDifference(double *sigma, OutputInfo *outputInfo, int loc,
492498

493499
return logLike;
494500
}
501+
#endif
495502

496503
/* Take array of model output, compare output with measured data - for given
497504
dataNum (i.e. perform comparisons between model[*][dataNum] and
@@ -679,6 +686,9 @@ void readIndicesFile(char *fileName, int *startIndices, int *endIndices,
679686
}
680687
}
681688

689+
// Apr-25-2025: clang-tidy asserts that there are issues with this function,
690+
// and it is not currently being used. Disabling for now, not worth
691+
// spending time on.
682692
/* Read measured data (from fileName.dat) and valid fractions (from
683693
fileName.valid) into arrays (used to also read sigmas) and set values in
684694
valid array (based on validFrac) Each line in data (and valid) file has
@@ -707,6 +717,7 @@ void readIndicesFile(char *fileName, int *startIndices, int *endIndices,
707717
708718
This function also allocates space for model array
709719
*/
720+
#if 0
710721
void readData(char *fileName, int dataTypeIndices[], int numDataTypes,
711722
int totNumDataTypes, int myNumLocs, int *steps, double validFrac,
712723
char *optIndicesFile, char *compareIndicesFile, FILE *outFile) {
@@ -993,7 +1004,11 @@ void readData(char *fileName, int dataTypeIndices[], int numDataTypes,
9931004

9941005
fclose(in1);
9951006
}
1007+
#endif
9961008

1009+
// Apr-25-2025: clang-tidy asserts that there are issues with this function,
1010+
// and it is not currently being used. Disabling for now, not worth
1011+
// spending time on.
9971012
/* pre: readData has been called (to set global startOpt, endOpt and numLocs
9981013
appropriately)
9991014
@@ -1012,6 +1027,7 @@ void readData(char *fileName, int dataTypeIndices[], int numDataTypes,
10121027
and unaggedWeight appropriately also compute aggedData array (of size numLocs
10131028
x numAggSteps x numDataTypes)
10141029
*/
1030+
#if 0
10151031
void readFileForAgg(char *fileForAgg, int numDataTypes,
10161032
double myUnaggedWeight) {
10171033
FILE *f;
@@ -1071,6 +1087,7 @@ void readFileForAgg(char *fileForAgg, int numDataTypes,
10711087
aggedModel = make2DArray(maxCount, numDataTypes);
10721088
unaggedWeight = myUnaggedWeight;
10731089
}
1090+
#endif
10741091

10751092
// malloc space for outputInfo array[0..numDataTypes-1], and outputInfo[*].years
10761093
// arrays for a single location, loc make years arrays large enough to hold data

src/common/paramchange.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ typedef struct OutputInfoStruct {
3838
NOTE: this is actually the NEGATIVE log likelihood, discarding constant terms
3939
to get true log likelihood, add n*log(sqrt(2*pi)), then multiply by -1
4040
*/
41+
// Function is disabled, SHOULD comment out here as well, but that breaks
42+
// compilation of estimate/ml-metrorun.c - which we don't care about and should
43+
// remove, but that's something for another day...
4144
double difference(double *sigma, OutputInfo *outputInfo, int loc,
4245
SpatialParams *spatialParams, double paramWeight,
4346
void (*modelF)(double **, int, int *, SpatialParams *, int),
@@ -81,6 +84,9 @@ double difference(double *sigma, OutputInfo *outputInfo, int loc,
8184
// weights - we just want to make it consistent with the difference function
8285
// above so we don't get an error.
8386

87+
// Function is disabled, SHOULD comment out here as well, but that breaks
88+
// compilation of estimate/ml-metrorun.c - which we don't care about and should
89+
// remove, but that's something for another day...
8490
double aggedDifference(double *sigma, OutputInfo *outputInfo, int loc,
8591
SpatialParams *spatialParams, double paramWeight,
8692
void (*modelF)(double **, int, int *, SpatialParams *,
@@ -128,6 +134,9 @@ void aggregates(OutputInfo *outputInfo, double **localModel, int loc,
128134
129135
This function also allocates space for model array
130136
*/
137+
// Function is disabled, SHOULD comment out here as well, but that breaks
138+
// compilation of estimate/ml-metrorun.c - which we don't care about and should
139+
// remove, but that's something for another day...
131140
void readData(char *fileName, int dataTypeIndices[], int numDataTypes,
132141
int totNumDataTypes, int myNumLocs, int *steps, double validFrac,
133142
char *optIndicesFile, char *compareIndicesFile, FILE *outFile);
@@ -150,6 +159,9 @@ void readData(char *fileName, int dataTypeIndices[], int numDataTypes,
150159
and unaggedWeight appropriately also compute aggedData array (of size numLocs
151160
x numAggSteps x numDataTypes)
152161
*/
162+
// Function is disabled, SHOULD comment out here as well, but that breaks
163+
// compilation of estimate/ml-metrorun.c - which we don't care about and should
164+
// remove, but that's something for another day...
153165
void readFileForAgg(char *fileForAgg, int numDataTypes, double myUnaggedWeight);
154166

155167
// malloc space for outputInfo array[0..numDataTypes-1], and outputInfo[*].years

src/common/util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ FILE *openFile(const char *name, const char *mode) {
2828

2929
if ((f = fopen(name, mode)) == NULL) {
3030
printf("Error opening %s for %s\n", name, mode);
31-
exit(EXIT_CODE_FILE_OPEN_ERROR);
31+
exit(EXIT_CODE_FILE_OPEN_OR_READ_ERROR);
3232
}
3333

3434
return f;

src/estimate/ml-metrorun.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ int main(int argc, char *argv[]) {
204204
int i;
205205

206206
// initialize array to [0,1,...,MAX_DATA_TYPES-1] (default)
207-
numDataTypes = initDataTypeIndices(dataTypeIndices);
207+
initDataTypeIndices(dataTypeIndices); // return value not used
208208

209209
// get command-line arguments:
210210
while ((option = getopt(argc, argv, "hi:")) != -1) {

src/sipnet/modelStructures.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// Read in and process agronomic events. SIPNET expects a file named
2020
// events.in to exist, though unit tests may use other names.
2121
// Note: requires ROOTS to be activated.
22-
#define EVENT_HANDLER 0 && ROOTS
22+
#define EVENT_HANDLER 1 && ROOTS
2323

2424
// have extra litter pool, in addition to soil c pool
2525
#define LITTER_POOL 0

src/sipnet/sipnet.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,8 @@ void moisture(double *trans, double *dWater, double potGrossPsn, double vpd,
14391439
int pastLeafGrowth(void) {
14401440

14411441
#if GDD
1442-
return (climate->gdd >= params.gddLeafOn); // growing degree days threshold
1442+
// null pointer dereference warning suppressed on the next line
1443+
return (climate->gdd >= params.gddLeafOn); // NOLINT
14431444
#elif SOIL_PHENOL
14441445
return (climate->tsoil >= params.soilTempLeafOn); // soil temperature
14451446
// threshold

src/utilities/transpose.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ void readFile(FILE *f, char **lines, int maxLength) {
6262
int i;
6363

6464
i = 0;
65-
while (fgets(lines[i], maxLength, f) != NULL) { // while not EOF or error
65+
// clang-tidy finds this sketchy, but it does seem to work, so ignore
66+
while (fgets(lines[i], maxLength, f) != NULL) { // NOLINT
67+
// while not EOF or error
6668
i++;
6769
}
6870
}
@@ -155,6 +157,10 @@ int main(int argc, char *argv[]) {
155157
f = openFile(filename, "r");
156158

157159
nl = numlines(f, &longestLine);
160+
if (nl < 1) {
161+
printf("Error: input file must contain at least one line\n");
162+
exit(1);
163+
}
158164
rewind(f);
159165

160166
// Allocate space to hold the file, line by line:
@@ -168,6 +174,10 @@ int main(int argc, char *argv[]) {
168174

169175
// Allocate space to hold the individual items:
170176
numItems = countItems(lines[0]);
177+
if (numItems < 1) {
178+
printf("Error in input file, first line has no items\n");
179+
exit(1);
180+
}
171181
items = (char ***)malloc(nl * sizeof(char **));
172182
for (i = 0; i < nl; i++) {
173183
items[i] = (char **)malloc(numItems * sizeof(char *));
@@ -192,6 +202,7 @@ int main(int argc, char *argv[]) {
192202
}
193203
free(items);
194204
free(lines);
205+
free(tmpName);
195206

196207
return 0;
197208
}

0 commit comments

Comments
 (0)