Clang static analyser warnings

This commit is contained in:
Shahram Najm 2020-02-13 12:38:44 +00:00
parent 34c29c0e50
commit aea5aa5fa3
11 changed files with 34 additions and 43 deletions

View File

@ -383,13 +383,9 @@ static double laplam(bif_trunc_t* bt, const double val[])
int i, j, k, l, isp;
double zxmw, zymw, zwsum, zx, zy, zsum1, zsum2, zbeta1, zp;
itab1 = (int*)malloc(sizeof(int) * kmax);
itab1 = (int*)calloc(kmax, sizeof(int));
itab2 = (int*)malloc(sizeof(int) * ((1 + bt->bif_i) * (1 + bt->bif_j)));
for (k = 0; k < kmax; k++) {
itab1[k] = 0;
}
/*
* Keep record of the possible values of i**2+j**2 outside the non-packed truncation
*/
@ -419,16 +415,13 @@ static double laplam(bif_trunc_t* bt, const double val[])
* Now, itab2 contains all possible values of i*i+j*j, and itab1 contains
* the rank of all i*i+j*j
*/
znorm = (double*)malloc(sizeof(double) * lmax);
znorm = (double*)calloc(lmax, sizeof(double));
zw = (double*)malloc(sizeof(double) * lmax);
/*
* Compute norms of input field, gathered by values of i**2+j**2; we have to
* go through the unpacked truncation again
*/
for (l = 0; l < lmax; l++)
znorm[l] = 0.;
isp = 0;
for_ij()
{
@ -443,7 +436,7 @@ static double laplam(bif_trunc_t* bt, const double val[])
int m, ll = itab1[i * i + j * j];
for (m = 0; m < 4; m++, isp++) {
DebugAssertAccess(znorm, (long)ll, (long)lmax);
DebugAssertAccess(val, (long)isp, bt->n_vals_bif);
DebugAssertAccess(val, (long)isp, (long)bt->n_vals_bif);
if (ll < lmax && isp < bt->n_vals_bif) {
znorm[ll] = MAX(znorm[ll], fabs(val[isp]));
}
@ -631,6 +624,7 @@ static bif_trunc_t* new_bif_trunc(grib_accessor* a, grib_accessor_data_g2bifouri
cleanup:
free_bif_trunc(bt, a);
if (ret) fprintf(stderr, "ERROR: new_bif_trunc: %s\n", grib_get_error_message(ret));
return NULL;
}

View File

@ -37,7 +37,6 @@ grib_box* grib_box_factory(grib_handle* h, grib_arguments* args)
grib_box_class* c = *(table[i].cclass);
grib_box* it = (grib_box*)grib_context_malloc_clear(h->context, c->size);
it->cclass = c;
ret = GRIB_SUCCESS;
ret = grib_box_init(it, h, args);
if (ret == GRIB_SUCCESS)
return it;

View File

@ -218,7 +218,6 @@ static void dump_values(grib_dumper* d, grib_accessor* a)
}
if (icount > cols || i == 0) {
fprintf(self->dumper.out, "\n ");
icount = 0;
}
sval = dval_to_string(c, values[i]);
fprintf(self->dumper.out, "rvalues[%d]=%s;", i, sval);
@ -268,7 +267,7 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char*
{
grib_dumper_bufr_encode_C* self = (grib_dumper_bufr_encode_C*)d;
double value = 0;
size_t size = 0;
size_t size = 0, size2 = 0;
double* values = NULL;
int err = 0;
int i, icount;
@ -282,14 +281,16 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char*
grib_value_count(a, &count);
size = count;
size2 = size;
if (size > 1) {
values = (double*)grib_context_malloc_clear(c, sizeof(double) * size);
err = grib_unpack_double(a, values, &size);
err = grib_unpack_double(a, values, &size2);
}
else {
err = grib_unpack_double(a, &value, &size);
err = grib_unpack_double(a, &value, &size2);
}
Assert(size == size2);
self->empty = 0;
@ -522,7 +523,6 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr
}
if (icount > cols || i == 0) {
fprintf(self->dumper.out, "\n ");
icount = 0;
}
fprintf(self->dumper.out, "ivalues[%d]=%ld;", i, values[i]);

View File

@ -200,7 +200,6 @@ static void dump_values(grib_dumper* d, grib_accessor* a)
}
if (icount > cols || i == 0) {
fprintf(self->dumper.out, "\n ");
icount = 0;
}
fprintf(self->dumper.out, "%.18e", values[i]);
@ -245,7 +244,7 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char*
{
grib_dumper_bufr_encode_filter* self = (grib_dumper_bufr_encode_filter*)d;
double value = 0;
size_t size = 0;
size_t size = 0, size2 = 0;
double* values = NULL;
int err = 0;
int i, icount;
@ -258,14 +257,16 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char*
grib_value_count(a, &count);
size = count;
size2 = size;
if (size > 1) {
values = (double*)grib_context_malloc_clear(c, sizeof(double) * size);
err = grib_unpack_double(a, values, &size);
err = grib_unpack_double(a, values, &size2);
}
else {
err = grib_unpack_double(a, &value, &size);
err = grib_unpack_double(a, &value, &size2);
}
Assert(size == size2);
self->empty = 0;

View File

@ -315,7 +315,7 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char*
{
grib_dumper_bufr_encode_fortran* self = (grib_dumper_bufr_encode_fortran*)d;
double value = 0;
size_t size = 0;
size_t size = 0, size2 = 0;
double* values = NULL;
int err = 0;
int i, icount;
@ -329,14 +329,16 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char*
grib_value_count(a, &count);
size = count;
size2 = size;
if (size > 1) {
values = (double*)grib_context_malloc_clear(c, sizeof(double) * size);
err = grib_unpack_double(a, values, &size);
err = grib_unpack_double(a, values, &size2);
}
else {
err = grib_unpack_double(a, &value, &size);
err = grib_unpack_double(a, &value, &size2);
}
Assert(size == size2);
self->empty = 0;
@ -461,7 +463,6 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment)
}
if (icount > cols || i == 0) {
fprintf(self->dumper.out, " &\n ");
icount = 0;
}
fprintf(self->dumper.out, "%ld ", values[size - 1]);
@ -526,7 +527,7 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr
{
grib_dumper_bufr_encode_fortran* self = (grib_dumper_bufr_encode_fortran*)d;
long value = 0;
size_t size = 0;
size_t size = 0, size2 = 0;
long* values = NULL;
int err = 0;
int i, icount;
@ -540,14 +541,16 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr
grib_value_count(a, &count);
size = count;
size2 = size;
if (size > 1) {
values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size);
err = grib_unpack_long(a, values, &size);
err = grib_unpack_long(a, values, &size2);
}
else {
err = grib_unpack_long(a, &value, &size);
err = grib_unpack_long(a, &value, &size2);
}
Assert(size == size2);
self->empty = 0;

View File

@ -269,7 +269,7 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char*
{
grib_dumper_bufr_encode_python* self = (grib_dumper_bufr_encode_python*)d;
double value = 0;
size_t size = 0;
size_t size = 0, size2 = 0;
double* values = NULL;
int err = 0;
int i, icount;
@ -283,14 +283,16 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char*
grib_value_count(a, &count);
size = count;
size2 = size;
if (size > 1) {
values = (double*)grib_context_malloc_clear(c, sizeof(double) * size);
err = grib_unpack_double(a, values, &size);
err = grib_unpack_double(a, values, &size2);
}
else {
err = grib_unpack_double(a, &value, &size);
err = grib_unpack_double(a, &value, &size2);
}
Assert(size == size2);
self->empty = 0;
@ -310,7 +312,6 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char*
}
if (icount > cols || i == 0) {
fprintf(self->dumper.out, "\n ");
icount = 0;
}
sval = dval_to_string(c, values[i]);
fprintf(self->dumper.out, "%s", sval);
@ -414,7 +415,6 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment)
}
if (icount > cols || i == 0) {
fprintf(self->dumper.out, "\n ");
icount = 0;
}
fprintf(self->dumper.out, "%ld", values[i]);

View File

@ -282,7 +282,6 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char*
}
if (icount > cols || i == 0) {
fprintf(self->dumper.out, "\n ");
icount = 0;
}
fprintf(self->dumper.out, "%g", values[i]);
@ -343,6 +342,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment)
DebugAssert(!err);
fprintf(self->dumper.out, "%s=%ld\n", a->name, value);
DebugAssert(!grib_is_missing_long(a, value));
(void)err;
return;
}
@ -398,7 +398,6 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment)
}
if (icount > cols || i == 0) {
fprintf(self->dumper.out, "\n ");
icount = 0;
}
if (doing_unexpandedDescriptors)
fprintf(self->dumper.out, "%06ld ", values[i]);
@ -483,7 +482,6 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr
}
if (icount > cols || i == 0) {
fprintf(self->dumper.out, "\n ");
icount = 0;
}
fprintf(self->dumper.out, "%ld ", values[i]);
fprintf(self->dumper.out, "}\n");

View File

@ -281,7 +281,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
char* value = NULL;
char* p = NULL;
err = _grib_get_string_length(a, &size);
_grib_get_string_length(a, &size);
if ((size < 2) && grib_is_missing_internal(a)) {
/* GRIB-302: transients and missing keys. Need to re-adjust the size */
size = 10; /* big enough to hold the string "missing" */

View File

@ -304,7 +304,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment)
return;
}
err = _grib_get_string_length(a, &size);
_grib_get_string_length(a, &size);
value = (char*)grib_context_malloc_clear(a->context, size);
if (!value) {
grib_context_log(a->context, GRIB_LOG_FATAL, "unable to allocate %d bytes", (int)size);

View File

@ -1449,7 +1449,6 @@ grib_action* grib_action_from_filter(const char* filter)
int grib_handle_apply_action(grib_handle* h, grib_action* a)
{
int err;
grib_action* ao = a;
if (!a)
return GRIB_SUCCESS; /* TODO: return error */
@ -1461,15 +1460,12 @@ int grib_handle_apply_action(grib_handle* h, grib_action* a)
a = a->next;
}
a = ao;
return GRIB_SUCCESS;
}
int grib_handle_prepare_action(grib_handle* h, grib_action* a)
{
int err;
grib_action* ao = a;
if (!a)
return GRIB_SUCCESS; /* TODO: return error */
@ -1481,8 +1477,6 @@ int grib_handle_prepare_action(grib_handle* h, grib_action* a)
a = a->next;
}
a = ao;
return GRIB_SUCCESS;
}

View File

@ -210,6 +210,7 @@ int grib_accessor_print(grib_accessor* a, const char* name, int type, const char
else {
ret = _grib_get_size(h, a, &size);
}
if (ret) return ret;
dval = (double*)grib_context_malloc_clear(h->context, sizeof(double) * size);
if (name[0] == '/' || name[0] == '#') {
replen = size;
@ -250,6 +251,7 @@ int grib_accessor_print(grib_accessor* a, const char* name, int type, const char
else {
ret = _grib_get_size(h, a, &size);
}
if (ret) return ret;
lval = (long*)grib_context_malloc_clear(h->context, sizeof(long) * size);
if (name[0] == '/' || name[0] == '#') {
replen = size;