Commit 88fc2411 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Prevent duplicate initialization.

parent 39e360e5
...@@ -28,12 +28,11 @@ ...@@ -28,12 +28,11 @@
//A simple wrapper for grib_get_string() that returns a newly allocated string. //A simple wrapper for grib_get_string() that returns a newly allocated string.
char* gribCopyString(grib_handle* gribHandle, const char* key) char* gribCopyString(grib_handle* gribHandle, const char* key)
{ {
char* result = NULL;
size_t length; size_t length;
#ifdef HAVE_GRIB_GET_LENGTH #ifdef HAVE_GRIB_GET_LENGTH
if (!grib_get_length(gribHandle, key, &length)) if (!grib_get_length(gribHandle, key, &length))
{ {
result = (char *)Malloc(length); char *result = (char *)Malloc(length);
if (!grib_get_string(gribHandle, key, result, &length)) if (!grib_get_string(gribHandle, key, result, &length))
result = (char *) Realloc(result, length); result = (char *) Realloc(result, length);
else else
...@@ -48,7 +47,7 @@ char* gribCopyString(grib_handle* gribHandle, const char* key) ...@@ -48,7 +47,7 @@ char* gribCopyString(grib_handle* gribHandle, const char* key)
* this unlikely in grib_api versions * this unlikely in grib_api versions
* not providing grib_get_length */ * not providing grib_get_length */
int rc; int rc;
result = (char *) Malloc(length); char *result = (char *) Malloc(length);
while ((rc = grib_get_string(gribHandle, key, result, &length)) while ((rc = grib_get_string(gribHandle, key, result, &length))
== GRIB_BUFFER_TOO_SMALL || rc == GRIB_ARRAY_TOO_SMALL) == GRIB_BUFFER_TOO_SMALL || rc == GRIB_ARRAY_TOO_SMALL)
{ {
......
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