Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpim-sw
libcdi
Commits
1cc87b3f
Commit
1cc87b3f
authored
Jul 22, 2015
by
Thomas Jahns
🤸
Browse files
Minor fix for gribCopyString.
* Correct return value when grib_get_length is available. * Fix coding style.
parent
719c3678
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/gribapi_utilities.c
View file @
1cc87b3f
...
...
@@ -31,16 +31,16 @@ char* gribCopyString(grib_handle* gribHandle, const char* key)
size_t
length
;
#ifdef HAVE_GRIB_GET_LENGTH
if
(
!
grib_get_length
(
gribHandle
,
key
,
&
length
))
{
char
*
result
=
xmalloc
(
length
);
if
(
!
grib_get_string
(
gribHandle
,
key
,
result
,
&
length
))
result
=
xrealloc
(
result
,
length
);
else
{
free
(
result
);
result
=
NULL
;
char
*
result
=
xmalloc
(
length
);
if
(
!
grib_get_string
(
gribHandle
,
key
,
result
,
&
length
))
result
=
xrealloc
(
result
,
length
);
else
{
free
(
result
);
result
=
NULL
;
}
}
}
#else
length
=
1024
;
/* there's an implementation limit
* that makes strings longer than
...
...
@@ -50,23 +50,24 @@ char* gribCopyString(grib_handle* gribHandle, const char* key)
result
=
xmalloc
(
length
);
while
((
rc
=
grib_get_string
(
gribHandle
,
key
,
result
,
&
length
))
==
GRIB_BUFFER_TOO_SMALL
||
rc
==
GRIB_ARRAY_TOO_SMALL
)
{
if
(
length
<=
1024UL
*
1024UL
)
{
length
*=
2
;
result
=
xrealloc
(
result
,
length
);
if
(
length
<=
1024UL
*
1024UL
)
{
length
*=
2
;
result
=
xrealloc
(
result
,
length
);
}
else
break
;
}
else
break
;
}
if
(
!
rc
)
{
result
=
xrealloc
(
result
,
length
);
return
result
;
}
free
(
result
);
else
{
free
(
result
);
result
=
NULL
;
}
#endif
return
NULL
;
return
result
;
}
//A simple wrapper for grib_get_string() for the usecase that the result is only compared to a given constant string.
...
...
src/table.h
View file @
1cc87b3f
...
...
@@ -1424,3 +1424,12 @@ tableDefault(void)
}
#endif
/* _TABLE_H */
/*
* Local Variables:
* c-file-style: "Java"
* c-basic-offset: 2
* indent-tabs-mode: nil
* show-trailing-whitespace: t
* require-trailing-newline: t
* End:
*/
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment