Metar: fix memory issues

This commit is contained in:
Shahram Najm 2020-02-06 17:56:25 +00:00
parent 17a82d1019
commit 221ab04078
2 changed files with 9 additions and 6 deletions

View File

@ -125,13 +125,16 @@ static string evaluate_string(grib_expression* g, grib_handle* h, char* buf, siz
start += *size;
if (e->length != 0) {
memcpy(buf, mybuf + start, e->length);
if (start > 0)
memcpy(buf, mybuf + start, e->length);
buf[e->length] = 0;
}
else {
memcpy(buf, mybuf, *size);
if (*size == 1024)
*size = *size - 1; /* ECC-336 */
if (*size > 0) {
memcpy(buf, mybuf, *size);
if (*size == 1024)
*size = *size - 1; /* ECC-336 */
}
buf[*size] = 0;
}
return buf;

View File

@ -107,8 +107,8 @@ static int evaluate_long(grib_expression* g, grib_handle* h, long* lres)
size_t l1 = sizeof(b1);
char b2[1024];
size_t l2 = sizeof(b2);
const char* v1;
const char* v2;
const char* v1 = NULL;
const char* v2 = NULL;
grib_expression_string_compare* e = (grib_expression_string_compare*)g;