mirror of https://github.com/ecmwf/eccodes.git
Error messages
This commit is contained in:
parent
31cbc3be24
commit
354a14dbc3
|
@ -157,6 +157,7 @@ static int unpack_string(grib_accessor* a, char* buffer, size_t* len)
|
|||
|
||||
if (*len < l) {
|
||||
*len = l;
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Wrong size (%zu) for %s", __func__, *len, a->name);
|
||||
return GRIB_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
|
|
|
@ -117,9 +117,10 @@ typedef struct grib_accessor_codetable
|
|||
static void init(grib_accessor* a, const long len, grib_arguments* params)
|
||||
{
|
||||
grib_accessor_codetable_units* self = (grib_accessor_codetable_units*)a;
|
||||
int n = 0;
|
||||
self->codetable = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++);
|
||||
a->length = 0;
|
||||
|
||||
int n = 0;
|
||||
self->codetable = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++);
|
||||
a->length = 0;
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
}
|
||||
|
||||
|
@ -131,13 +132,13 @@ static int get_native_type(grib_accessor* a)
|
|||
static int unpack_string(grib_accessor* a, char* buffer, size_t* len)
|
||||
{
|
||||
grib_accessor_codetable_units* self = (grib_accessor_codetable_units*)a;
|
||||
grib_codetable* table = NULL;
|
||||
grib_codetable* table = NULL;
|
||||
|
||||
size_t size = 1;
|
||||
long value;
|
||||
int err = GRIB_SUCCESS;
|
||||
char tmp[1024];
|
||||
size_t l = 1024;
|
||||
size_t l = sizeof(tmp);
|
||||
grib_accessor_codetable* ca = (grib_accessor_codetable*)grib_find_accessor(grib_handle_of_accessor(a), self->codetable);
|
||||
|
||||
if ((err = grib_unpack_long((grib_accessor*)ca, &value, &size)) != GRIB_SUCCESS)
|
||||
|
@ -156,6 +157,7 @@ static int unpack_string(grib_accessor* a, char* buffer, size_t* len)
|
|||
|
||||
if (*len < l) {
|
||||
*len = l;
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Wrong size (%zu) for %s", __func__, *len, a->name);
|
||||
return GRIB_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
|
|
|
@ -295,7 +295,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
|||
#endif
|
||||
if (grib_get_nearest_smaller_value(hand, self->reference_value, val[0], &reference_value) != GRIB_SUCCESS) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
"%s %s: unable to find nearest_smaller_value of %g for %s", cclass_name, __func__, min, self->reference_value);
|
||||
"%s %s: Unable to find nearest_smaller_value of %g for %s", cclass_name, __func__, min, self->reference_value);
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
if ((err = grib_set_double_internal(hand, self->reference_value, reference_value)) != GRIB_SUCCESS)
|
||||
|
@ -322,7 +322,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
|||
|
||||
if (grib_get_nearest_smaller_value(hand, self->reference_value, min, &reference_value) != GRIB_SUCCESS) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
"%s %s: unable to find nearest_smaller_value of %g for %s", cclass_name, __func__, min, self->reference_value);
|
||||
"%s %s: Unable to find nearest_smaller_value of %g for %s", cclass_name, __func__, min, self->reference_value);
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
|
@ -367,7 +367,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
|||
|
||||
if (grib_get_nearest_smaller_value(hand, self->reference_value, min, &reference_value) != GRIB_SUCCESS) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
"%s %s: unable to find nearest_smaller_value of %g for %s", cclass_name, __func__, min, self->reference_value);
|
||||
"%s %s: Unable to find nearest_smaller_value of %g for %s", cclass_name, __func__, min, self->reference_value);
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
d = codes_power<double>(decimal_scale_factor, 10);
|
||||
|
|
|
@ -536,7 +536,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
|||
&reference_value);
|
||||
if (ret != GRIB_SUCCESS) {
|
||||
grib_context_log(gh->context, GRIB_LOG_ERROR,
|
||||
"%s: unable to find nearest_smaller_value of %g for %s", cclass_name, min, self->reference_value);
|
||||
"%s: Unable to find nearest_smaller_value of %g for %s", cclass_name, min, self->reference_value);
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
d = codes_power<double>(+decimal_scale_factor, 10);
|
||||
|
@ -545,7 +545,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
|||
d = codes_power<double>(+decimal_scale_factor, 10);
|
||||
if (grib_get_nearest_smaller_value(gh, self->reference_value, d * min, &reference_value) != GRIB_SUCCESS) {
|
||||
grib_context_log(gh->context, GRIB_LOG_ERROR,
|
||||
"%s: unable to find nearest_smaller_value of %g for %s", cclass_name, d * min, self->reference_value);
|
||||
"%s: Unable to find nearest_smaller_value of %g for %s", cclass_name, d * min, self->reference_value);
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
binary_scale_factor = grib_get_binary_scale_fact(d * max, reference_value, bits_per_value, &ret);
|
||||
|
|
|
@ -805,7 +805,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
|||
|
||||
if (grib_get_nearest_smaller_value(handle, self->reference_value, min, &reference_value) != GRIB_SUCCESS) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
"unable to find nearest_smaller_value of %g for %s", min, self->reference_value);
|
||||
"Unable to find nearest_smaller_value of %g for %s", min, self->reference_value);
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
binary_scale_factor = grib_get_binary_scale_fact(max, reference_value, bits_per_value, &ret);
|
||||
|
|
|
@ -508,7 +508,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
|||
|
||||
if (grib_get_nearest_smaller_value(grib_handle_of_accessor(a), self->reference_value, min, &reference_value) != GRIB_SUCCESS) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
"unable to find nearest_smaller_value of %g for %s", min, self->reference_value);
|
||||
"Unable to find nearest_smaller_value of %g for %s", min, self->reference_value);
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
|
|
|
@ -113,6 +113,7 @@ static int unpack_string(grib_accessor* a, char* v, size_t* len)
|
|||
char repres[1024];
|
||||
char format[32] = "%g";
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
const char* cclass_name = a->cclass->name;
|
||||
|
||||
grib_unpack_double(a, &val, &l);
|
||||
|
||||
|
@ -127,8 +128,9 @@ static int unpack_string(grib_accessor* a, char* v, size_t* len)
|
|||
l = strlen(repres) + 1;
|
||||
|
||||
if (l > *len) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_long : unpack_string : Buffer too small for %s ", a->name);
|
||||
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
"%s: Buffer too small for %s. It is %zu bytes long (len=%zu)",
|
||||
cclass_name, a->name, l, *len);
|
||||
*len = l;
|
||||
return GRIB_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
|
|
@ -158,6 +158,7 @@ static int unpack_string(grib_accessor* a, char* v, size_t* len)
|
|||
|
||||
if (*len < length) {
|
||||
*len = length;
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Wrong size (%zu) for %s", __func__, *len, a->name);
|
||||
return GRIB_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
|
|
|
@ -122,6 +122,7 @@ static int unpack_string(grib_accessor* a, char* v, size_t* len)
|
|||
char repres[1024];
|
||||
char format[32] = "%ld";
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
const char* cclass_name = a->cclass->name;
|
||||
|
||||
err = grib_unpack_long(a, &val, &l);
|
||||
/* TODO: We should catch all errors but in this case the test ERA_Gen.sh will fail
|
||||
|
@ -140,7 +141,9 @@ static int unpack_string(grib_accessor* a, char* v, size_t* len)
|
|||
l = strlen(repres) + 1;
|
||||
|
||||
if (l > *len) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_long : unpack_string : Buffer too small for %s ", a->name);
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
"%s: Buffer too small for %s. It is %zu bytes long (len=%zu)",
|
||||
cclass_name, a->name, l, *len);
|
||||
*len = l;
|
||||
return GRIB_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
|
|
@ -151,9 +151,10 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len)
|
|||
size_t buflen = 100;
|
||||
long step;
|
||||
grib_accessor* stepRangeAcc = grib_find_accessor(grib_handle_of_accessor(a), self->stepRange);
|
||||
const char* cclass_name = a->cclass->name;
|
||||
|
||||
if (!stepRangeAcc) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s not found", self->stepRange);
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s: %s not found", cclass_name, self->stepRange);
|
||||
return GRIB_NOT_FOUND;
|
||||
}
|
||||
|
||||
|
@ -162,8 +163,8 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len)
|
|||
|
||||
if (*len < buflen) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
"grib_accessor_class_mars_step: Buffer too small for %s. It is %ld bytes long (len=%ld)\n",
|
||||
a->name, buflen, *len);
|
||||
"%s: Buffer too small for %s. It is %zu bytes long (len=%zu)",
|
||||
cclass_name, a->name, buflen, *len);
|
||||
*len = buflen;
|
||||
return GRIB_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
|
|
@ -181,9 +181,8 @@ static int unpack_string(grib_accessor* a, char* v, size_t* len)
|
|||
struct grib_md5_state md5c;
|
||||
|
||||
if (*len < 32) {
|
||||
// grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_class_md5 unpack_string: Array too small");
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Wrong size (%zu) for %s", __func__, *len, a->name);
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
return GRIB_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offset, &offset)) != GRIB_SUCCESS)
|
||||
|
|
|
@ -7,10 +7,6 @@
|
|||
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
|
||||
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
|
||||
*/
|
||||
/**************************************
|
||||
* Enrico Fucile
|
||||
**************************************/
|
||||
|
||||
|
||||
#include "grib_api_internal.h"
|
||||
/*
|
||||
|
@ -121,21 +117,22 @@ static int unpack_string(grib_accessor* a, char* v, size_t* len)
|
|||
size_t l = 1;
|
||||
char repres[1024] = {0,};
|
||||
int err = 0;
|
||||
const char* cclass_name = a->cclass->name;
|
||||
|
||||
err = grib_unpack_double(a, &val, &l);
|
||||
if (err)
|
||||
return err;
|
||||
if (err) return err;
|
||||
|
||||
snprintf(repres, sizeof(repres), "%.0f", val);
|
||||
|
||||
l = strlen(repres) + 1;
|
||||
if (l > *len) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_offset: unpack_string: Buffer too small for %s",
|
||||
a->name);
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
"%s: Buffer too small for %s. It is %zu bytes long (len=%zu)",
|
||||
cclass_name, a->name, l, *len);
|
||||
*len = l;
|
||||
return GRIB_BUFFER_TOO_SMALL;
|
||||
}
|
||||
grib_context_log(a->context, GRIB_LOG_DEBUG, "grib_accessor_offset: Casting double %s to string", a->name);
|
||||
grib_context_log(a->context, GRIB_LOG_DEBUG, "%s: Casting double %s to string", __func__, a->name);
|
||||
|
||||
*len = l;
|
||||
|
||||
|
|
|
@ -304,6 +304,11 @@ static int unpack_string(grib_accessor* a, char* v, size_t* len)
|
|||
|
||||
Assert(self->endpoint == ENDPOINT_SOURCE || self->endpoint == ENDPOINT_TARGET);
|
||||
|
||||
if (*len < 100) { // Safe bet
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Wrong size (%zu) for %s", __func__, *len, a->name);
|
||||
return GRIB_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
err = grib_get_string(h, self->grid_type, grid_type, &size);
|
||||
if (err) return err;
|
||||
|
||||
|
|
|
@ -191,20 +191,22 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len)
|
|||
|
||||
static int unpack_string(grib_accessor* a, char* val, size_t* len)
|
||||
{
|
||||
long v = 0;
|
||||
size_t lsize = 1;
|
||||
long v = 0;
|
||||
size_t lsize = 1, lmin = 5;
|
||||
|
||||
unpack_long(a, &v, &lsize);
|
||||
|
||||
if (*len < 5) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "Key %s (unpack_string): Buffer too small", a->name);
|
||||
|
||||
*len = 5;
|
||||
if (*len < lmin) {
|
||||
const char* cclass_name = a->cclass->name;
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
"%s: Buffer too small for %s. It is %zu bytes long (len=%zu)",
|
||||
cclass_name, a->name, lmin, *len);
|
||||
*len = lmin;
|
||||
return GRIB_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
snprintf(val, 64, "%04ld", v);
|
||||
|
||||
len[0] = 5;
|
||||
len[0] = lmin;
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -234,19 +234,22 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len)
|
|||
{
|
||||
int err = 0;
|
||||
long v = 0;
|
||||
size_t lsize = 1;
|
||||
size_t lsize = 1, lmin = 5;
|
||||
|
||||
err = unpack_long(a, &v, &lsize);
|
||||
if (err) return err;
|
||||
|
||||
if (*len < 5) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "Key %s (unpack_string): Buffer too small", a->name);
|
||||
*len = 5;
|
||||
if (*len < lmin) {
|
||||
const char* cclass_name = a->cclass->name;
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
"%s: Buffer too small for %s. It is %zu bytes long (len=%zu)",
|
||||
cclass_name, a->name, lmin, *len);
|
||||
*len = lmin;
|
||||
return GRIB_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
snprintf(val, 64, "%04ld", v);
|
||||
|
||||
len[0] = 5;
|
||||
len[0] = lmin;
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -148,7 +148,7 @@ int grib_optimize_decimal_factor(grib_accessor* a, const char* reference_value,
|
|||
long vmin, vmax;
|
||||
if (grib_get_nearest_smaller_value(gh, reference_value, min, ref) != GRIB_SUCCESS) {
|
||||
grib_context_log(gh->context, GRIB_LOG_ERROR,
|
||||
"unable to find nearest_smaller_value of %g for %s", min, reference_value);
|
||||
"Unable to find nearest_smaller_value of %g for %s", min, reference_value);
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
|
@ -191,7 +191,7 @@ int grib_optimize_decimal_factor(grib_accessor* a, const char* reference_value,
|
|||
|
||||
if (grib_get_nearest_smaller_value(gh, reference_value, min, ref) != GRIB_SUCCESS) {
|
||||
grib_context_log(gh->context, GRIB_LOG_ERROR,
|
||||
"unable to find nearest_smaller_value of %g for %s", min, reference_value);
|
||||
"Unable to find nearest_smaller_value of %g for %s", min, reference_value);
|
||||
return GRIB_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue