From 86549f88e4f26211a10279a5ca0c9e45a9a68ae0 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 10 Feb 2020 17:48:41 +0000 Subject: [PATCH] Testing: GTS header --- src/grib_handle.c | 9 ++++++--- tests/grib_copy.sh | 25 ++++++++++++++++++++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/grib_handle.c b/src/grib_handle.c index 165b2f8ab..b9762c09c 100644 --- a/src/grib_handle.c +++ b/src/grib_handle.c @@ -779,7 +779,8 @@ static grib_handle* grib_handle_new_from_file_multi(grib_context* c, FILE* f, in if (c->gts_header_on && gtslen >= 8) { gl->gts_header = (char*)grib_context_malloc_clear(c, sizeof(unsigned char) * gtslen); - memcpy(gl->gts_header, gts_header, gtslen); + DebugAssert(gts_header); + if (gts_header) memcpy(gl->gts_header, gts_header, gtslen); gl->gts_header_len = gtslen; grib_context_free(c, save_gts_header); gtslen = 0; @@ -1012,7 +1013,8 @@ grib_handle* bufr_new_from_file(grib_context* c, FILE* f, int* error) if (c->gts_header_on && gtslen >= 8) { gl->gts_header = (char*)grib_context_malloc(c, sizeof(unsigned char) * gtslen); - memcpy(gl->gts_header, gts_header, gtslen); + DebugAssert(gts_header); + if (gts_header) memcpy(gl->gts_header, gts_header, gtslen); gl->gts_header_len = gtslen; grib_context_free(c, save_gts_header); gtslen = 0; @@ -1135,7 +1137,8 @@ static grib_handle* grib_handle_new_from_file_no_multi(grib_context* c, FILE* f, if (c->gts_header_on && gtslen >= 8) { gl->gts_header = (char*)grib_context_malloc(c, sizeof(unsigned char) * gtslen); - memcpy(gl->gts_header, gts_header, gtslen); + DebugAssert(gts_header); + if (gts_header) memcpy(gl->gts_header, gts_header, gtslen); gl->gts_header_len = gtslen; grib_context_free(c, save_gts_header); gtslen = 0; diff --git a/tests/grib_copy.sh b/tests/grib_copy.sh index b01511fd7..525a94a79 100755 --- a/tests/grib_copy.sh +++ b/tests/grib_copy.sh @@ -10,8 +10,6 @@ . ./include.sh -#set -x - #Enter data dir cd ${data_dir} @@ -19,9 +17,26 @@ cd ${data_dir} label="grib_copy_test" temp=${label}".grib.tmp" -#------------------------------------------------------------------- -# Test: The -X option -#------------------------------------------------------------------- + +echo "Test: The -g option..." +# ----------------------------------- +input=gts.grib +${tools_dir}/grib_copy -w count=1 -g $input $temp +val1=`${tools_dir}/gts_get -wcount=1 -p AA $input` +val2=`${tools_dir}/gts_get -p AA $temp` +[ "$val1" = "$val2" ] +[ "$val1" = "XK" ] + +${tools_dir}/grib_copy -w count=1 $input $temp +set +e +${tools_dir}/gts_get -p AA $temp +status=$? +set -e +[ $status -ne 0 ] + + +echo "Test: The -X option..." +# ------------------------------- echo "Test: use of -X option" input=tigge_pf_ecmwf.grib2 ${tools_dir}/grib_copy -w count=1 -X 0 $input $temp #First msg