mirror of https://github.com/ecmwf/eccodes.git
Add macro for checking array access
This commit is contained in:
parent
4e91ec83f8
commit
852f99f39c
|
@ -260,7 +260,6 @@ static void init(grib_accessor* a,const long v, grib_arguments* args)
|
|||
self->values=NULL;
|
||||
self->size=0;
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
|
||||
|
||||
}
|
||||
|
||||
static int value_count(grib_accessor* a,long* count)
|
||||
|
@ -759,6 +758,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len)
|
|||
maxA=X[count];
|
||||
minA=X[count];
|
||||
for (i=1;i<groupLengthA;i++) {
|
||||
DebugAssertAccess(X, count+i, numberOfValues);
|
||||
if (maxA<X[count+i]) maxA=X[count+i];
|
||||
if (minA>X[count+i]) minA=X[count+i];
|
||||
}
|
||||
|
@ -788,6 +788,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len)
|
|||
maxC=X[offsetC];
|
||||
minC=X[offsetC];
|
||||
for (i=1;i<groupLengthC;i++) {
|
||||
DebugAssertAccess(X, offsetC+i, numberOfValues);
|
||||
if (maxC<X[offsetC+i]) maxC=X[offsetC+i];
|
||||
if (minC>X[offsetC+i]) minC=X[offsetC+i];
|
||||
}
|
||||
|
|
|
@ -177,6 +177,17 @@ extern "C" {
|
|||
enum { assert_static__ = 1/(e) }; \
|
||||
} while (0)
|
||||
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define DebugAssertAccess(array, index, size) \
|
||||
do { \
|
||||
if (!((index) >= 0 && (index) < (size)) ) {printf("ARRAY ACCESS ERROR: array=%s idx=%ld size=%ld @ %s +%d \n", #array, index, size, __FILE__, __LINE__); abort();} \
|
||||
} while(0)
|
||||
#else
|
||||
#define DebugAssertAccess(array, index, size)
|
||||
#endif
|
||||
|
||||
|
||||
#include "grib_api.h"
|
||||
|
||||
#define GRIB_UNKNOWN_VALUE -9999.999
|
||||
|
|
Loading…
Reference in New Issue