Commit 2fdda575 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Replace explicit byte counts for UUIDs with preprocessor define.

parent b17e46d3
...@@ -218,6 +218,8 @@ extern "C" { ...@@ -218,6 +218,8 @@ extern "C" {
#define CALENDAR_366DAYS 4 #define CALENDAR_366DAYS 4
#define CALENDAR_NONE 5 #define CALENDAR_NONE 5
/* number of unsigned char needed to store UUID */
#define CDI_UUID_SIZE 16
/* CDI control routines */ /* CDI control routines */
......
...@@ -370,6 +370,11 @@ ...@@ -370,6 +370,11 @@
INTEGER CALENDAR_NONE INTEGER CALENDAR_NONE
PARAMETER (CALENDAR_NONE = 5) PARAMETER (CALENDAR_NONE = 5)
! !
! number of unsigned char needed to store UUID
!
INTEGER CDI_UUID_SIZE
PARAMETER (CDI_UUID_SIZE = 16)
!
! CDI control routines ! CDI control routines
! !
! cdiReset ! cdiReset
......
...@@ -57,6 +57,9 @@ ...@@ -57,6 +57,9 @@
/* CALENDAR types */ /* CALENDAR types */
/* number of unsigned char needed to store UUID */
/* CDI control routines */ /* CDI control routines */
FCALLSCSUB0 (cdiReset, CDIRESET, cdireset) FCALLSCSUB0 (cdiReset, CDIRESET, cdireset)
......
...@@ -619,10 +619,12 @@ void gribapiGetGrid(grib_handle *gh, grid_t *grid) ...@@ -619,10 +619,12 @@ void gribapiGetGrid(grib_handle *gh, grid_t *grid)
} }
case GRID_UNSTRUCTURED: case GRID_UNSTRUCTURED:
{ {
char uuid[17]; unsigned char uuid[CDI_UUID_SIZE];
char reference_link[8192]; /*
char reference_link[8192];
size_t len = sizeof(reference_link); size_t len = sizeof(reference_link);
reference_link[0] = 0; reference_link[0] = 0;
*/
/* FIXME: assert(numberOfPoints <= INT_MAX && numberOfPoints >= INT_MIN) */ /* FIXME: assert(numberOfPoints <= INT_MAX && numberOfPoints >= INT_MIN) */
grid->size = (int)numberOfPoints; grid->size = (int)numberOfPoints;
...@@ -641,10 +643,10 @@ void gribapiGetGrid(grib_handle *gh, grid_t *grid) ...@@ -641,10 +643,10 @@ void gribapiGetGrid(grib_handle *gh, grid_t *grid)
grid->reference = strdupx(reference_link); grid->reference = strdupx(reference_link);
} }
*/ */
len = (size_t) 16; size_t len = (size_t)CDI_UUID_SIZE;
if ( grib_get_bytes(gh, "uuidOfHGrid", (unsigned char *) uuid, &len) == 0) if ( grib_get_bytes(gh, "uuidOfHGrid", uuid, &len) == 0)
{ {
memcpy(grid->uuid, uuid, 16); memcpy(grid->uuid, uuid, CDI_UUID_SIZE);
} }
} }
break; break;
...@@ -924,7 +926,7 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh, ...@@ -924,7 +926,7 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh,
case ZAXIS_REFERENCE: case ZAXIS_REFERENCE:
{ {
size_t len; size_t len;
char uuid[17]; char uuid[CDI_UUID_SIZE];
long ltmp; long ltmp;
long nhlev, nvgrid; long nhlev, nvgrid;
...@@ -937,9 +939,9 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh, ...@@ -937,9 +939,9 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh,
nhlev = ltmp; nhlev = ltmp;
GRIB_CHECK(grib_get_long(gh, "numberOfVGridUsed", &ltmp), 0); GRIB_CHECK(grib_get_long(gh, "numberOfVGridUsed", &ltmp), 0);
nvgrid = ltmp; nvgrid = ltmp;
len = (size_t) 16; len = (size_t)CDI_UUID_SIZE;
uuid[16] = 0; memset(uuid, 0, CDI_UUID_SIZE);
GRIB_CHECK(grib_get_bytes(gh, "uuidOfVGrid", (unsigned char *) uuid, &len), 0); GRIB_CHECK(grib_get_bytes(gh, "uuidOfVGrid", uuid, &len), 0);
varDefZAxisReference((int) nhlev, (int) nvgrid, uuid); varDefZAxisReference((int) nhlev, (int) nvgrid, uuid);
break; break;
} }
...@@ -2731,16 +2733,16 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype ...@@ -2731,16 +2733,16 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
} }
else else
{ {
char uuid[17]; unsigned char uuid[CDI_UUID_SIZE];
int position = gridInqPosition(gridID); int position = gridInqPosition(gridID);
int number = gridInqNumber(gridID); int number = gridInqNumber(gridID);
if ( position < 0 ) position = 0; if ( position < 0 ) position = 0;
if ( number < 0 ) number = 0; if ( number < 0 ) number = 0;
GRIB_CHECK(my_grib_set_long(gh, "numberOfGridUsed", number), 0); GRIB_CHECK(my_grib_set_long(gh, "numberOfGridUsed", number), 0);
GRIB_CHECK(my_grib_set_long(gh, "numberOfGridInReference", position), 0); GRIB_CHECK(my_grib_set_long(gh, "numberOfGridInReference", position), 0);
len = 16; len = CDI_UUID_SIZE;
gridInqUUID(gridID, uuid); gridInqUUID(gridID, uuid);
if (grib_set_bytes(gh, "uuidOfHGrid", (unsigned char *) uuid, &len) != 0) if (grib_set_bytes(gh, "uuidOfHGrid", uuid, &len) != 0)
Warning("Can't write UUID!"); Warning("Can't write UUID!");
} }
...@@ -3017,7 +3019,7 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID, ...@@ -3017,7 +3019,7 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID,
} }
case ZAXIS_REFERENCE: case ZAXIS_REFERENCE:
{ {
char uuid[16]; unsigned char uuid[CDI_UUID_SIZE];
int number; int number;
if ( !gcinit ) if ( !gcinit )
...@@ -3037,9 +3039,9 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID, ...@@ -3037,9 +3039,9 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID,
GRIB_CHECK(my_grib_set_long(gh, "NV", 6), 0); GRIB_CHECK(my_grib_set_long(gh, "NV", 6), 0);
GRIB_CHECK(my_grib_set_long(gh, "nlev", zaxisInqNlevRef(zaxisID)), 0); GRIB_CHECK(my_grib_set_long(gh, "nlev", zaxisInqNlevRef(zaxisID)), 0);
GRIB_CHECK(my_grib_set_long(gh, "numberOfVGridUsed", number), 0); GRIB_CHECK(my_grib_set_long(gh, "numberOfVGridUsed", number), 0);
size_t len = 16; size_t len = CDI_UUID_SIZE;
zaxisInqUUID(zaxisID, uuid); zaxisInqUUID(zaxisID, uuid);
if (grib_set_bytes(gh, "uuidOfVGrid", (unsigned char *) uuid, &len) != 0) if (grib_set_bytes(gh, "uuidOfVGrid", uuid, &len) != 0)
Warning("Can't write UUID!"); Warning("Can't write UUID!");
GRIB_CHECK(my_grib_set_long(gh, "topLevel", (long) dlevel1), 0); GRIB_CHECK(my_grib_set_long(gh, "topLevel", (long) dlevel1), 0);
GRIB_CHECK(my_grib_set_long(gh, "bottomLevel", (long) dlevel2), 0); GRIB_CHECK(my_grib_set_long(gh, "bottomLevel", (long) dlevel2), 0);
...@@ -3056,9 +3058,9 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID, ...@@ -3056,9 +3058,9 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID,
GRIB_CHECK(my_grib_set_long(gh, "NV", 6), 0); GRIB_CHECK(my_grib_set_long(gh, "NV", 6), 0);
GRIB_CHECK(my_grib_set_long(gh, "nlev", zaxisInqNlevRef(zaxisID)), 0); GRIB_CHECK(my_grib_set_long(gh, "nlev", zaxisInqNlevRef(zaxisID)), 0);
GRIB_CHECK(my_grib_set_long(gh, "numberOfVGridUsed", number), 0); GRIB_CHECK(my_grib_set_long(gh, "numberOfVGridUsed", number), 0);
size_t len = 16; size_t len = CDI_UUID_SIZE;
zaxisInqUUID(zaxisID, uuid); zaxisInqUUID(zaxisID, uuid);
if (grib_set_bytes(gh, "uuidOfVGrid", (unsigned char *) uuid, &len) != 0) if (grib_set_bytes(gh, "uuidOfVGrid", uuid, &len) != 0)
Warning("Can't write UUID!"); Warning("Can't write UUID!");
GRIB_CHECK(my_grib_set_double(gh, "level", level), 0); GRIB_CHECK(my_grib_set_double(gh, "level", level), 0);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment