Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors reported by cppcheck #595

Merged
merged 4 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/common/addSuffix.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,18 @@ int main(int argc, char **argv) {
nkeywords++;
if (nkeywords >= nalloc) {
nalloc *= 2;
keywords = realloc(keywords, sizeof(char *) * nalloc);
char ** tmp = realloc(keywords, sizeof(char *) * nalloc);
if (tmp == NULL) {
// free keywords if realloc fails
// otherwise address is lost.
free(keywords);
fclose(fp);
fprintf(stderr, "Failed realloc!\n");
exit(-1);
}
else {
keywords = tmp;
}
}
}

Expand All @@ -228,6 +239,8 @@ int main(int argc, char **argv) {

fclose(fp);

free(keywords);

exit(0);
}

Expand Down
11 changes: 5 additions & 6 deletions src/gencoef/gencoef.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,12 @@ int main(int argc, char **argv)
mpfr_zinit(result[i]);
}

mpfr_t fra, frb, frc, frd, fre;
mpfr_t fra, frb, frc, frd;

mpfr_zinit(fra);
mpfr_zinit(frb);
mpfr_zinit(frc);
mpfr_zinit(frd);
mpfr_zinit(fre);
mpfr_init(fra);
mpfr_init(frb);
mpfr_init(frc);
mpfr_init(frd);

for(i=0;i<n;i++) {
double b = 1.0 - pow((double)i / (n-1), p);
Expand Down
15 changes: 8 additions & 7 deletions src/gencoef/simplexfr.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static void tableau(mpfr_t ret, int i, int j) {

if (j <= n) {
mpfr_t s;
mpfr_zinit(s);
mpfr_init(s);
mpfr_set_d(s, 0, GMP_RNDN);

mpfr_t *tab = malloc(sizeof(mpfr_t) * (m + 1));
Expand Down Expand Up @@ -190,9 +190,7 @@ static void tableau(mpfr_t ret, int i, int j) {
static void pivot(int ipivot, int jpivot) {
int i, j;
mpfr_t u;

mpfr_zinit(u);

mpfr_init(u);
mpfr_set(u, pivotcolumn[ipivot], GMP_RNDN);

for (j = 1; j <= m; j++) {
Expand Down Expand Up @@ -254,7 +252,8 @@ static int minimize() {
static int phase1() {
int i, j;
mpfr_t u;
mpfr_zinit(u);
mpfr_init(u);
mpfr_set_d(u, 0, GMP_RNDN);

jmax = n3;
for (i = 0; i <= m; i++) {
Expand Down Expand Up @@ -309,7 +308,8 @@ int solve_fr(mpfr_t *result, int n0, int m0, mpfr_t **a0, int *ineq0, mpfr_t *c0
init(n, m);

mpfr_t csum;
mpfr_zinit(csum);
mpfr_init(csum);
mpfr_set_d(csum, 0, GMP_RNDN);

for(j=0;j<n0+1;j++) {
mpfr_set(c[j], c0[j], GMP_RNDN);
Expand Down Expand Up @@ -370,7 +370,8 @@ int solve_fr(mpfr_t *result, int n0, int m0, mpfr_t **a0, int *ineq0, mpfr_t *c0
}

mpfr_t cs;
mpfr_zinit(cs);
mpfr_init(cs);
mpfr_set_d(cs, 0, GMP_RNDN);
if (row[n] != 0) tableau(cs, row[n], 0);

for (j = 1; j < n; j++) {
Expand Down
8 changes: 4 additions & 4 deletions src/libm/sleefsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ static INLINE CONST float fabsfk(float x) {
}

static INLINE CONST float mulsignf(float x, float y) {
return intBitsToFloat(floatToRawIntBits(x) ^ (floatToRawIntBits(y) & (1 << 31)));
return intBitsToFloat(floatToRawIntBits(x) ^ (floatToRawIntBits(y) & 0x80000000U));
}

static INLINE CONST float copysignfk(float x, float y) {
return intBitsToFloat((floatToRawIntBits(x) & ~(1 << 31)) ^ (floatToRawIntBits(y) & (1 << 31)));
return intBitsToFloat((floatToRawIntBits(x) & ~0x80000000U) ^ (floatToRawIntBits(y) & 0x80000000U));
}

static INLINE CONST float signf(float d) { return mulsignf(1, d); }
Expand Down Expand Up @@ -1920,11 +1920,11 @@ EXPORT CONST float xnextafterf(float x, float y) {
cxf = x == 0 ? mulsignf(0, y) : x;
memcpy(&cxi, &cxf, sizeof(cxi));
int c = (cxi < 0) == (y < x);
if (c) cxi = -(cxi ^ (1 << 31));
if (c) cxi = -(cxi ^ 0x80000000U);

if (x != y) cxi--;

if (c) cxi = -(cxi ^ (1 << 31));
if (c) cxi = -(cxi ^ 0x80000000U);

memcpy(&cxf, &cxi, sizeof(cxf));
if (cxf == 0 && x != 0) cxf = mulsignf(0, x);
Expand Down
2 changes: 2 additions & 0 deletions src/quad/sleefsimdqp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3995,6 +3995,8 @@ static int xvprintf(size_t (*consumer)(const char *ptr, size_t size, void *arg),
outlen += (*consumer)(xbuf, strlen(xbuf), arg);
}

va_end(ap2);

fmt++;
}

Expand Down
Loading