mirror of https://github.com/ecmwf/eccodes.git
Action write: check for -ve value
This commit is contained in:
parent
ea84ba6381
commit
2ad5dd29e9
|
@ -103,7 +103,7 @@ static int execute(grib_action* act, grib_handle* h)
|
||||||
{
|
{
|
||||||
grib_action_write* a = (grib_action_write*)act;
|
grib_action_write* a = (grib_action_write*)act;
|
||||||
int err = GRIB_SUCCESS;
|
int err = GRIB_SUCCESS;
|
||||||
size_t size;
|
size_t size = 0;
|
||||||
const void* buffer = NULL;
|
const void* buffer = NULL;
|
||||||
const char* filename = NULL;
|
const char* filename = NULL;
|
||||||
char string[1024] = {0,};
|
char string[1024] = {0,};
|
||||||
|
@ -159,14 +159,16 @@ static int execute(grib_action* act, grib_handle* h)
|
||||||
|
|
||||||
if (a->padtomultiple) {
|
if (a->padtomultiple) {
|
||||||
char* zeros = NULL;
|
char* zeros = NULL;
|
||||||
|
if (a->padtomultiple < 0)
|
||||||
|
return GRIB_INVALID_ARGUMENT;
|
||||||
size_t padding = a->padtomultiple - size % a->padtomultiple;
|
size_t padding = a->padtomultiple - size % a->padtomultiple;
|
||||||
/* printf("XXX padding=%d size=%d padtomultiple=%d\n",padding,size,a->padtomultiple); */
|
/* printf("XXX padding=%zu size=%zu padtomultiple=%d\n", padding, size,a->padtomultiple); */
|
||||||
zeros = (char*)calloc(padding, 1);
|
zeros = (char*)calloc(padding, 1);
|
||||||
if (!zeros)
|
if (!zeros)
|
||||||
return GRIB_OUT_OF_MEMORY;
|
return GRIB_OUT_OF_MEMORY;
|
||||||
if (fwrite(zeros, 1, padding, of->handle) != padding) {
|
if (fwrite(zeros, 1, padding, of->handle) != padding) {
|
||||||
grib_context_log(act->context, (GRIB_LOG_ERROR) | (GRIB_LOG_PERROR),
|
grib_context_log(act->context, (GRIB_LOG_ERROR) | (GRIB_LOG_PERROR),
|
||||||
"Error writing to %s", filename);
|
"Error writing to '%s'", filename);
|
||||||
free(zeros);
|
free(zeros);
|
||||||
return GRIB_IO_PROBLEM;
|
return GRIB_IO_PROBLEM;
|
||||||
}
|
}
|
||||||
|
@ -177,7 +179,7 @@ static int execute(grib_action* act, grib_handle* h)
|
||||||
const char gts_trailer[4] = { '\x0D', '\x0D', '\x0A', '\x03' };
|
const char gts_trailer[4] = { '\x0D', '\x0D', '\x0A', '\x03' };
|
||||||
if (fwrite(gts_trailer, 1, 4, of->handle) != 4) {
|
if (fwrite(gts_trailer, 1, 4, of->handle) != 4) {
|
||||||
grib_context_log(act->context, (GRIB_LOG_ERROR) | (GRIB_LOG_PERROR),
|
grib_context_log(act->context, (GRIB_LOG_ERROR) | (GRIB_LOG_PERROR),
|
||||||
"Error writing GTS trailer to %s", filename);
|
"Error writing GTS trailer to '%s'", filename);
|
||||||
return GRIB_IO_PROBLEM;
|
return GRIB_IO_PROBLEM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue