Skip to content

Commit 82ff87f

Browse files
authored
fix some issues identified by cppcheck (#334)
1 parent 8d44fdf commit 82ff87f

9 files changed

Lines changed: 200 additions & 196 deletions

File tree

heclib/hecdss/hecdss.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,15 @@ HECDSS_API int hec_dss_open(const char* filename, dss_file** dss)
130130
log_handle = stdout;
131131

132132
int status = hec_dss_zopen(f->ifltab,filename);
133-
if (status != 0)
133+
if (status != 0) {
134+
free(f);
134135
return status;
136+
}
135137
int version = zgetVersion(f->ifltab);
136138
if (version != 7) {
137139
hec_dss_log_error("version is not supported.\nOnly version 7 DSS files are supported");
138140
zclose(f->ifltab);
141+
free(f);
139142
return -700;
140143
}
141144
*dss = f;

heclib/heclib_c/src/Internal/copyFile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
int copyFile(long long *ifltab, int handleTo)
4242
{
4343

44-
int istat;
44+
int istat = 0;
4545
int ihandle;
4646
int numberReads;
4747
int numberInts;
Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
/* only under gcc (Linux)*/
2-
#if defined(__GNUC__) && (__linux__)
3-
4-
/* for glibc version */
5-
#include <features.h>
6-
#include <math.h> /* powf call */
7-
/* glibc redefined powf in 2.27, breaks compatibility with prior versions */
8-
#if (defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 27)) || (defined(__GNUC__) && (__GNUC__ <= 10))
9-
10-
/* 64 bit glibc powf was defined in 2.2.5 */
11-
#if __LP64__
12-
# define SYMVER "GLIBC_2.2.5"
13-
14-
/* 32-bit glibc powf was defined in 2.0 */
15-
#else
16-
# define SYMVER "GLIBC_2.0"
17-
18-
/* endif Architecture check */
19-
#endif
20-
21-
/* to replace the function with the old call */
22-
#define USE_OLD_SYM(F,V) __asm__(".symver " #F ", " #F "@" V)
23-
24-
/* force powf to be from earlier compatible glibc */
25-
USE_OLD_SYM(powf,SYMVER);
26-
27-
/* endif GLIBC >= 2.27 */
28-
#endif
29-
30-
/* wrap the function requires gcc -Wl,--wrap=powf when linking */
31-
float __wrap_powf( float base, float exponent ) {
32-
/* call into the supported version of powf */
33-
return powf(base, exponent);
34-
}
35-
36-
/* so gets reloaded if necessary */
37-
#undef _FEATURES_H
38-
39-
/* endif gcc & linux */
40-
#endif
1+
/* only under gcc (Linux)*/
2+
#if defined(__GNUC__) && (__linux__)
3+
4+
/* for glibc version */
5+
#include <features.h>
6+
#include <math.h> /* powf call */
7+
/* glibc redefined powf in 2.27, breaks compatibility with prior versions */
8+
#if (defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 27)) || (defined(__GNUC__) && (__GNUC__ <= 10))
9+
10+
/* 64 bit glibc powf was defined in 2.2.5 */
11+
#if __LP64__
12+
# define SYMVER "GLIBC_2.2.5"
13+
14+
/* 32-bit glibc powf was defined in 2.0 */
15+
#else
16+
# define SYMVER "GLIBC_2.0"
17+
18+
/* endif Architecture check */
19+
#endif
20+
21+
/* to replace the function with the old call */
22+
#define USE_OLD_SYM(F,V) __asm__(".symver " #F ", " #F "@" V)
23+
24+
/* force powf to be from earlier compatible glibc */
25+
USE_OLD_SYM(powf,SYMVER);
26+
27+
/* endif GLIBC >= 2.27 */
28+
#endif
29+
30+
/* wrap the function requires gcc -Wl,--wrap=powf when linking */
31+
float __wrap_powf( float base, float exponent ) {
32+
/* call into the supported version of powf */
33+
return powf(base, exponent);
34+
}
35+
36+
/* so gets reloaded if necessary */
37+
#undef _FEATURES_H
38+
39+
/* endif gcc & linux */
40+
#endif

heclib/heclib_c/src/Internal/zopenInternal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
{
9494
int ihandle;
9595
int status;
96-
int status2;
96+
int status2 = 0;
9797
int fileExists;
9898
int permission;
9999
int size;

heclib/heclib_c/src/Internal/ztsStoreIrreg7.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int ztsStoreIrreg7(long long *ifltab, zStructTimeSeries *tss, int storageFlag)
6161
{
6262
int status;
6363
int *values;
64-
int valueSize;
64+
int valueSize = 0;
6565
int *profileDepths;
6666
int profileDepthsSize;
6767

@@ -77,7 +77,7 @@ int ztsStoreIrreg7(long long *ifltab, zStructTimeSeries *tss, int storageFlag)
7777
int timeBaseToEnd;
7878
int time;
7979
int dataType;
80-
int valueElementSize;
80+
int valueElementSize = 0;
8181
int profileDepthsNumber;
8282
int timeGranularity;
8383

heclib/heclib_c/src/Internal/ztsStoreReg7.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int ztsStoreReg7(long long *ifltab, zStructTimeSeries *tss, int storageFlag)
5959
{
6060
int status;
6161
int *values;
62-
int valueSize;
62+
int valueSize = 0;
6363
int *profileDepths;
6464
int profileDepthsSize;
6565
int julianBlockDate;
@@ -85,7 +85,7 @@ int ztsStoreReg7(long long *ifltab, zStructTimeSeries *tss, int storageFlag)
8585

8686
int internalHeader[INT_HEAD_SIZE];
8787
int internalHeaderArraySize = INT_HEAD_SIZE;
88-
int valueElementSize;
88+
int valueElementSize = 0;
8989
int profileDepthsNumber;
9090
int boolReadBlock;
9191

heclib/heclib_c/src/Public/zanalyzeFile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int zanalyzeFile(long long *ifltab)
6262
int countTotal;
6363
int numberValid;
6464
int numberDeleted;
65-
int numberZeros;
65+
int numberZeros = 0;
6666
long long binAddress;
6767
long long *pathnameBin;
6868
long long infoAddress;

heclib/heclib_c/src/Public/ztextRetrieveToFile.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ int ztextRetrieveToFile(long long *ifltab, const char *pathname, const char *fil
8989
}
9090
#endif
9191
if (status != 0) {
92+
fclose(textFileFP);
9293
return zerrorProcessing(ifltab, DSS_FUNCTION_ztextRetrieve_ID,
9394
zdssErrorCodes.UNABLE_TO_WRITE_FILE, status, 0,
9495
zdssErrorSeverity.WARNING, pathname, filename);

0 commit comments

Comments
 (0)