Skip to content

Commit

Permalink
Merge pull request #2875 from seanm/clang-tidy-fixes
Browse files Browse the repository at this point in the history
Misc clang-tidy fixes, and added a .clang-tidy config file
  • Loading branch information
WardF authored Apr 5, 2024
2 parents b1d4b41 + 38d3831 commit 9639ba4
Show file tree
Hide file tree
Showing 57 changed files with 214 additions and 177 deletions.
88 changes: 88 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
Checks: "-*,\
bugprone-*,\
-bugprone-easily-swappable-parameters,\
-bugprone-assignment-in-if-condition,\
-bugprone-signed-char-misuse,\
-bugprone-branch-clone,\
-bugprone-narrowing-conversions,\
-bugprone-macro-parentheses,\
-bugprone-switch-missing-default-case,\
-bugprone-suspicious-include,\
-bugprone-reserved-identifier,\
-bugprone-misplaced-widening-cast,\
-bugprone-implicit-widening-of-multiplication-result,\
-bugprone-suspicious-realloc-usage,\
-bugprone-sizeof-expression,\
cert*,\
-cert-err33-c,\
-cert-err34-c,\
-cert-str34-c,\
-cert-dcl03-c,\
-cert-msc30-c,\
-cert-msc50-cpp,\
-cert-dcl37-c,\
-cert-dcl51-cpp,\
clang-analyzer-*,\
-clang-analyzer-core.CallAndMessage,\
-clang-analyzer-core.DivideZero,\
-clang-analyzer-core.NonNullParamChecker,\
-clang-analyzer-core.NullDereference,\
-clang-analyzer-core.UndefinedBinaryOperatorResult,\
-clang-analyzer-core.VLASize,\
-clang-analyzer-core.uninitialized.ArraySubscript,\
-clang-analyzer-core.uninitialized.Assign,\
-clang-analyzer-core.uninitialized.Branch,\
-clang-analyzer-cplusplus.Move,\
-clang-analyzer-cplusplus.NewDelete,\
-clang-analyzer-cplusplus.NewDeleteLeaks,\
-clang-analyzer-cplusplus.PlacementNew,\
-clang-analyzer-deadcode.DeadStores,\
-clang-analyzer-optin.cplusplus.UninitializedObject,\
-clang-analyzer-optin.cplusplus.VirtualCall,\
-clang-analyzer-optin.mpi.MPI-Checker,\
-clang-analyzer-optin.performance.Padding,\
-clang-analyzer-optin.portability.UnixAPI,\
-clang-analyzer-security.FloatLoopCounter,\
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,\
-clang-analyzer-security.insecureAPI.rand,\
-clang-analyzer-security.insecureAPI.strcpy,\
-clang-analyzer-unix.Malloc,\
-clang-analyzer-unix.MallocSizeof,\
-clang-analyzer-unix.MismatchedDeallocator,\
-clang-analyzer-unix.cstring.NullArg,\
-clang-analyzer-valist.Unterminated,\
misc-*,\
-misc-header-include-cycle,\
-misc-include-cleaner,\
-misc-no-recursion,\
-misc-unused-parameters,\
-misc-static-assert,\
-misc-redundant-expression,\
modernize-*,\
-modernize-macro-to-enum,\
mpi-*,\
openmp-*,\
performance-*,\
-performance-no-int-to-ptr,\
portability-*,\
readability-*,\
-readability-identifier-length,\
-readability-isolate-declaration,\
-readability-braces-around-statements,\
-readability-magic-numbers,\
-readability-else-after-return,\
-readability-function-cognitive-complexity,\
-readability-function-size,\
-readability-non-const-parameter,\
-readability-inconsistent-declaration-parameter-name,\
-readability-avoid-unconditional-preprocessor-if,\
-readability-named-parameter,\
-readability-duplicate-include,\
-readability-misleading-indentation,\
-readability-avoid-const-params-in-decls,\
-readability-redundant-declaration,\
-readability-redundant-preprocessor,\
"
#WarningsAsErrors: "*"
...
2 changes: 1 addition & 1 deletion examples/C/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ main()
/* Create a bunch of phoney data so we have something to write in
the example file. */
for (fp=(float *)temp, i=0; i<LAT_LEN*LON_LEN; i++)
*fp++ = 10.f + (float)i/10.f;
*fp++ = 10.F + (float)i/10.F;

/* Now create the file in both formats with the same code. */
for (i=0; i<2; i++)
Expand Down
4 changes: 2 additions & 2 deletions examples/C/pres_temp_4D_wr.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ main()
* would have some real data to write, for example, model
* output. */
for (lat = 0; lat < NLAT; lat++)
lats[lat] = START_LAT + 5.f*(float)lat;
lats[lat] = START_LAT + 5.F*(float)lat;
for (lon = 0; lon < NLON; lon++)
lons[lon] = START_LON + 5.f*(float)lon;
lons[lon] = START_LON + 5.F*(float)lon;

for (lvl = 0; lvl < NLVL; lvl++)
for (lat = 0; lat < NLAT; lat++)
Expand Down
8 changes: 4 additions & 4 deletions examples/C/sfc_pres_temp_rd.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,22 @@ main()
them and check them. */
if ((retval = nc_get_att_text(ncid, lat_varid, UNITS, lat_units_in)))
ERR(retval);
if (strncmp(lat_units_in, LAT_UNITS, strlen(LAT_UNITS)))
if (strncmp(lat_units_in, LAT_UNITS, strlen(LAT_UNITS)) != 0)
return 2;

if ((retval = nc_get_att_text(ncid, lon_varid, UNITS, lon_units_in)))
ERR(retval);
if (strncmp(lon_units_in, LON_UNITS, strlen(LON_UNITS)))
if (strncmp(lon_units_in, LON_UNITS, strlen(LON_UNITS)) != 0)
return 2;

if ((retval = nc_get_att_text(ncid, pres_varid, UNITS, pres_units_in)))
ERR(retval);
if (strncmp(pres_units_in, PRES_UNITS, strlen(PRES_UNITS)))
if (strncmp(pres_units_in, PRES_UNITS, strlen(PRES_UNITS)) != 0)
return 2;

if ((retval = nc_get_att_text(ncid, temp_varid, UNITS, temp_units_in)))
ERR(retval);
if (strncmp(temp_units_in, TEMP_UNITS, strlen(TEMP_UNITS))) return 2;
if (strncmp(temp_units_in, TEMP_UNITS, strlen(TEMP_UNITS)) != 0) return 2;

/* Close the file. */
if ((retval = nc_close(ncid)))
Expand Down
4 changes: 2 additions & 2 deletions examples/C/sfc_pres_temp_wr.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ main()
* would have some real data to write, for example, model
* output. */
for (lat = 0; lat < NLAT; lat++)
lats[lat] = START_LAT + 5.f*(float)lat;
lats[lat] = START_LAT + 5.F*(float)lat;
for (lon = 0; lon < NLON; lon++)
lons[lon] = START_LON + 5.f*(float)lon;
lons[lon] = START_LON + 5.F*(float)lon;

for (lat = 0; lat < NLAT; lat++)
for (lon = 0; lon < NLON; lon++)
Expand Down
1 change: 0 additions & 1 deletion libdap2/constraints.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
static void completesegments(NClist* fullpath, NClist* segments);
static NCerror qualifyprojectionnames(DCEprojection* proj);
static NCerror qualifyprojectionsizes(DCEprojection* proj);
static NCerror qualifyprojectionnames(DCEprojection* proj);
static NCerror matchpartialname(NClist* nodes, NClist* segments, CDFnode** nodep);
static int matchsuffix(NClist* matchpath, NClist* segments);
static int iscontainer(CDFnode* node);
Expand Down
1 change: 0 additions & 1 deletion libdap2/daputil.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,6 @@ normal: *s++ = *t++;
}
}
*s = '\0';
return;
}


Expand Down
2 changes: 0 additions & 2 deletions libdap4/d4util.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#include <io.h>
#endif

extern int mkstemp(char *template);

#define LBRACKET '['
#define RBRACKET ']'

Expand Down
2 changes: 1 addition & 1 deletion libdispatch/daux.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ computefieldinfo(struct NCAUX_CMPD* cmpd)
#define LBRACK '['
#define RBRACK ']'

static int gettype(const int q0, const int q1, int* unsignedp);
static int gettype(int q0, int q1, int* unsignedp);

/* Look at q0 and q1) to determine type */
static int
Expand Down
4 changes: 2 additions & 2 deletions libdispatch/dcopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ NC_compare_nc_types(int ncid1, int typeid1, int ncid2, int typeid2, int *equalp)
return ret;

/* Check the obvious. */
if(size1 != size2 || class1 != class2 || strcmp(name1,name2))
if(size1 != size2 || class1 != class2 || strcmp(name1,name2) != 0)
return NC_NOERR;

/* Check user-defined types in detail. */
Expand Down Expand Up @@ -109,7 +109,7 @@ NC_compare_nc_types(int ncid1, int typeid1, int ncid2, int typeid2, int *equalp)
value1)) ||
(ret = nc_inq_enum_member(ncid2, typeid2, i, name2,
value2)) ||
strcmp(name1, name2) || memcmp(value1, value2, size1))
strcmp(name1, name2) != 0 || memcmp(value1, value2, size1) != 0)
{
free(value1);
free(value2);
Expand Down
2 changes: 0 additions & 2 deletions libdispatch/dfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
#endif


extern int NC_initialized; /**< True when dispatch table is initialized. */

/* User-defined formats. */
NC_Dispatch *UDF0_dispatch_table = NULL;
char UDF0_magic_number[NC_MAX_MAGIC_NUMBER_LEN + 1] = "";
Expand Down
1 change: 0 additions & 1 deletion libdispatch/dhttp.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,6 @@ trim(char* s)
/* Ok, overwrite any leading whitespace */
for(q=s;*p;) {*q++ = *p++;}
*q = '\0';
return;
}

static size_t
Expand Down
4 changes: 3 additions & 1 deletion libdispatch/dinfermodel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,9 @@ openmagic(struct MagicFile* file)
file->filelen = (long long)size;
#endif
}
rewind(file->fp);
int retval2 = fseek(file->fp, 0L, SEEK_SET);
if(retval2 != 0)
{status = errno; goto done;}
}
done:
return check(status);
Expand Down
2 changes: 1 addition & 1 deletion libdispatch/dinstance.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ nc_copy_data_all(int ncid, nc_type xtype, const void* memory, size_t count, void

/* allocate the top-level */
if(count > 0) {
if((copy = calloc(xsize,count))==NULL)
if((copy = calloc(count,xsize))==NULL)
{stat = NC_ENOMEM; goto done;}
}
stat = nc_copy_data(ncid,xtype,memory,count,copy);
Expand Down
4 changes: 2 additions & 2 deletions libdispatch/dinstance_intern.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ NC_copy_data_all(NC* nc, nc_type xtype, const void* memory, size_t count, void**

if(xtype <= NC_STRING && count > 0) {
xsize = NC_atomictypelen(xtype);
if((copy = calloc(xsize,count))==NULL) {stat = NC_ENOMEM; goto done;}
if((copy = calloc(count,xsize))==NULL) {stat = NC_ENOMEM; goto done;}
if(xtype < NC_STRING) /* fixed-size atomic type */
memcpy(copy,memory,xsize*count);
else { /* string type */
Expand All @@ -589,7 +589,7 @@ NC_copy_data_all(NC* nc, nc_type xtype, const void* memory, size_t count, void**
xsize = utype->size;
/* allocate the top-level */
if(count > 0) {
if((copy = calloc(xsize,count))==NULL) {stat = NC_ENOMEM; goto done;}
if((copy = calloc(count,xsize))==NULL) {stat = NC_ENOMEM; goto done;}
}
if((stat = NC_copy_data(nc,xtype,memory,count,copy)))
(void)NC_reclaim_data_all(nc,xtype,copy,count);
Expand Down
2 changes: 1 addition & 1 deletion libdispatch/ncjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static int NCJcloneDict(const NCjson* dict, NCjson** clonep);
static int NCJunparseR(const NCjson* json, NCJbuf* buf, unsigned flags);
static int bytesappendquoted(NCJbuf* buf, const char* s);
static int bytesappend(NCJbuf* buf, const char* s);
static int bytesappendc(NCJbuf* bufp, const char c);
static int bytesappendc(NCJbuf* bufp, char c);

/* Hide everything for plugins */
#ifdef NETCDF_JSON_H
Expand Down
Loading

0 comments on commit 9639ba4

Please sign in to comment.