From b26d806ea265985719e84ed80995c242c3482e12 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Sun, 19 Sep 2021 13:16:52 +0100 Subject: [PATCH] Add guards for grib_is_missing_string --- src/grib_accessor_class_bufr_data_element.c | 2 +- src/grib_parse_utils.c | 1 + src/grib_value.c | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/grib_accessor_class_bufr_data_element.c b/src/grib_accessor_class_bufr_data_element.c index 937ab1192..19d5c646d 100644 --- a/src/grib_accessor_class_bufr_data_element.c +++ b/src/grib_accessor_class_bufr_data_element.c @@ -603,7 +603,7 @@ static int get_native_type(grib_accessor* a) { grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; int ret = GRIB_TYPE_DOUBLE; - + DebugAssert(self); switch (self->type) { case BUFR_DESCRIPTOR_TYPE_STRING: ret = GRIB_TYPE_STRING; diff --git a/src/grib_parse_utils.c b/src/grib_parse_utils.c index 230d68e32..f74fd1eb6 100644 --- a/src/grib_parse_utils.c +++ b/src/grib_parse_utils.c @@ -314,6 +314,7 @@ int grib_accessors_list_print(grib_handle* h, grib_accessors_list* al, const cha char long_format[] = "%ld"; /* default format for printing integer keys */ char default_separator[] = " "; grib_accessor* a = al->accessor; + DebugAssert(a); /* Number of columns specified as 0 means print on ONE line i.e. num cols = infinity */ if (maxcols == 0) diff --git a/src/grib_value.c b/src/grib_value.c index 59a75c6b6..9f27282e2 100644 --- a/src/grib_value.c +++ b/src/grib_value.c @@ -599,7 +599,9 @@ int grib_is_missing_string(grib_accessor* a, unsigned char* x, size_t len) } } - ret = (a == NULL || ((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) && ret == 1)) ? 1 : 0; + if (!a) return ret; + + ret = ( ((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) && ret == 1) ) ? 1 : 0; return ret; }