Add test for invalid input to grib_util_set_spec
#include "grib_api_internal.h"
#include "eccodes.h"
#include <assert.h>
+#include <float.h>
#define STR_EQUAL(s1, s2) (strcmp((s1), (s2)) == 0)
@@ -102,6 +103,21 @@ static void test_reduced_gg(int remove_local_def, int edition, const char* packi
assert(finalh);
assert(err == 0);
+ /* Try some invalid inputs and check it is handled */
+ {
+ codes_handle *h2 = 0;
+ packing_spec.accuracy=999;
+ h2 = grib_util_set_spec(handle, &spec, &packing_spec, set_spec_flags, values, outlen, &err);
+ assert(err == GRIB_INTERNAL_ERROR);
+ assert(!h2);
+
+ packing_spec.accuracy=GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES;
+ values[0] = INFINITY;
+ h2 = grib_util_set_spec(handle, &spec, &packing_spec, set_spec_flags, values, outlen, &err);
+ assert(err == GRIB_ENCODING_ERROR);
+ assert(!h2);
+ }
+
/* Write out the message to the output file */
CODES_CHECK(grib_get_message(finalh, &buffer, &size),0);
if(fwrite(buffer,1,size,out) != size) {
