mirror of
https://github.com/libretro/RetroArch
synced 2025-04-01 04:20:27 +00:00
(nbio_stdio.c) Try to prevent 'argument cannot be negative' coverity warning
This commit is contained in:
parent
67f850c3dc
commit
7c722fca9a
@ -23,7 +23,9 @@ static const char * modes[]={ "rb", "wb", "r+b", "rb", "wb", "r+b" };
|
|||||||
|
|
||||||
struct nbio_t* nbio_open(const char * filename, unsigned mode)
|
struct nbio_t* nbio_open(const char * filename, unsigned mode)
|
||||||
{
|
{
|
||||||
|
void *buf = NULL;
|
||||||
struct nbio_t* handle = NULL;
|
struct nbio_t* handle = NULL;
|
||||||
|
size_t len = 0;
|
||||||
FILE* f = fopen(filename, modes[mode]);
|
FILE* f = fopen(filename, modes[mode]);
|
||||||
if (!f)
|
if (!f)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -34,7 +36,6 @@ struct nbio_t* nbio_open(const char * filename, unsigned mode)
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
handle->f = f;
|
handle->f = f;
|
||||||
handle->len = 0;
|
|
||||||
|
|
||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
@ -43,16 +44,20 @@ struct nbio_t* nbio_open(const char * filename, unsigned mode)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fseek(handle->f, 0, SEEK_END);
|
fseek(handle->f, 0, SEEK_END);
|
||||||
handle->len = ftell(handle->f);
|
len = ftell(handle->f);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
handle->mode = mode;
|
handle->mode = mode;
|
||||||
handle->data = malloc(handle->len);
|
|
||||||
|
|
||||||
if (handle->len && !handle->data)
|
if (len)
|
||||||
|
buf = malloc(len);
|
||||||
|
|
||||||
|
if (!buf)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
handle->data = buf;
|
||||||
|
handle->len = len;
|
||||||
handle->progress = handle->len;
|
handle->progress = handle->len;
|
||||||
handle->op = -2;
|
handle->op = -2;
|
||||||
|
|
||||||
@ -60,13 +65,7 @@ struct nbio_t* nbio_open(const char * filename, unsigned mode)
|
|||||||
|
|
||||||
error:
|
error:
|
||||||
if (handle)
|
if (handle)
|
||||||
{
|
|
||||||
if (handle->data)
|
|
||||||
free(handle->data);
|
|
||||||
handle->data = NULL;
|
|
||||||
free(handle);
|
free(handle);
|
||||||
}
|
|
||||||
handle = NULL;
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user