diff --git a/src/accessor/grib_accessor_class_evaluate.cc b/src/accessor/grib_accessor_class_evaluate.cc index 1e583cd11..61bf8d6b8 100644 --- a/src/accessor/grib_accessor_class_evaluate.cc +++ b/src/accessor/grib_accessor_class_evaluate.cc @@ -22,6 +22,8 @@ void grib_accessor_evaluate_t::init(const long l, grib_arguments* c) int grib_accessor_evaluate_t::unpack_long(long* val, size_t* len) { + if (!arg_) return GRIB_INVALID_ARGUMENT; + grib_handle* h = grib_handle_of_accessor(this); grib_expression* e = arg_->get_expression(h, 0); diff --git a/src/geo/GeoIterator.cc b/src/geo/GeoIterator.cc index e15d53406..04fd6969f 100644 --- a/src/geo/GeoIterator.cc +++ b/src/geo/GeoIterator.cc @@ -31,15 +31,21 @@ GeoIterator::GeoIterator(grib_handle* h, unsigned long flags) : CODES_CHECK(codes_get_size(h_, "values", &nv_), ""); ECCODES_ASSERT(nv_ > 0); - data_ = (flags_ & GRIB_GEOITERATOR_NO_VALUES) ? nullptr : static_cast(grib_context_malloc(h_->context, nv_ * sizeof(double))); - ECCODES_ASSERT(data_ != nullptr); + //long numberOfPoints = 0; + //grib_get_long_internal(h, "numberOfPoints", &numberOfPoints); - auto size = nv_; - CODES_CHECK(codes_get_double_array(h_, "values", data_, &size), ""); - ECCODES_ASSERT(nv_ == size); + if (flags_ & GRIB_GEOITERATOR_NO_VALUES) { + data_ = nullptr; + } else { + data_ = static_cast(grib_context_malloc(h_->context, nv_ * sizeof(double))); + ECCODES_ASSERT(data_ != nullptr); + auto size = nv_; + CODES_CHECK(codes_get_double_array(h_, "values", data_, &size), ""); + // Check numberOfPoints equals nv_ + // if not, throw an exception + } } - int GeoIterator::init(grib_handle*, grib_arguments*) { NOTIMP; diff --git a/src/geo/GeoIterator.h b/src/geo/GeoIterator.h index fefc5aca5..0f8396b9d 100644 --- a/src/geo/GeoIterator.h +++ b/src/geo/GeoIterator.h @@ -15,18 +15,12 @@ #include "eckit/geo/Grid.h" -// eccodes macros conflict with eckit -#ifdef Assert - #undef Assert -#endif - #include "geo/iterator/grib_iterator.h" namespace eccodes::geo { - class GeoIterator : public geo_iterator::Iterator { public: @@ -47,5 +41,4 @@ private: geo_iterator::Iterator* create() const override; }; - } // namespace eccodes::geo diff --git a/src/geo/iterator/grib_iterator.cc b/src/geo/iterator/grib_iterator.cc index 9f0be23eb..5c41b9be2 100644 --- a/src/geo/iterator/grib_iterator.cc +++ b/src/geo/iterator/grib_iterator.cc @@ -122,8 +122,14 @@ grib_iterator* grib_iterator_new(const grib_handle* ch, unsigned long flags, int } } } static const init_main; - - i->iterator = new eccodes::geo::GeoIterator(const_cast(ch), flags); + try { + i->iterator = new eccodes::geo::GeoIterator(const_cast(ch), flags); + } + catch(std::exception& e) { + grib_context_log(ch->context, GRIB_LOG_ERROR, "grib_iterator_new: Exception thrown (%s)", e.what()); + *error = GRIB_GEOCALCULUS_PROBLEM; + return NULL; + } } else #endif