Add test for invalid input to grib_util_set_spec

This commit is contained in:
Shahram Najm 2018-06-06 15:50:47 +01:00
parent 0ecb2746cb
commit 1cfc572fb5
1 changed files with 16 additions and 0 deletions

View File

@ -11,6 +11,7 @@
#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) {