mirror of
https://github.com/libretro/RetroArch
synced 2025-04-07 13:23:32 +00:00
(trans_stream_zlib.c) Try to prevent null pointer dereferences
This commit is contained in:
parent
dc2664a4ef
commit
f5dedd673f
@ -29,15 +29,16 @@
|
||||
|
||||
struct zlib_trans_stream
|
||||
{
|
||||
z_stream z;
|
||||
int ex; /* window_bits or level */
|
||||
bool inited;
|
||||
int ex; /* window_bits or level */
|
||||
z_stream z;
|
||||
};
|
||||
|
||||
static void *zlib_deflate_stream_new(void)
|
||||
{
|
||||
struct zlib_trans_stream *ret = (struct zlib_trans_stream*)calloc(1, sizeof(struct zlib_trans_stream));
|
||||
if (ret)
|
||||
if (!ret)
|
||||
return NULL;
|
||||
ret->ex = 9;
|
||||
return (void *) ret;
|
||||
}
|
||||
@ -45,7 +46,8 @@ static void *zlib_deflate_stream_new(void)
|
||||
static void *zlib_inflate_stream_new(void)
|
||||
{
|
||||
struct zlib_trans_stream *ret = (struct zlib_trans_stream*)calloc(1, sizeof(struct zlib_trans_stream));
|
||||
if (ret)
|
||||
if (!ret)
|
||||
return NULL;
|
||||
ret->ex = MAX_WBITS;
|
||||
return (void *) ret;
|
||||
}
|
||||
@ -53,6 +55,8 @@ static void *zlib_inflate_stream_new(void)
|
||||
static void zlib_deflate_stream_free(void *data)
|
||||
{
|
||||
struct zlib_trans_stream *z = (struct zlib_trans_stream *) data;
|
||||
if (!z)
|
||||
return;
|
||||
if (z->inited)
|
||||
deflateEnd(&z->z);
|
||||
free(z);
|
||||
@ -73,6 +77,7 @@ static bool zlib_deflate_define(void *data, const char *prop, uint32_t val)
|
||||
struct zlib_trans_stream *z = (struct zlib_trans_stream *) data;
|
||||
if (string_is_equal_fast(prop, "level", 5))
|
||||
{
|
||||
if (z)
|
||||
z->ex = (int) val;
|
||||
return true;
|
||||
}
|
||||
@ -84,6 +89,7 @@ static bool zlib_inflate_define(void *data, const char *prop, uint32_t val)
|
||||
struct zlib_trans_stream *z = (struct zlib_trans_stream *) data;
|
||||
if (string_is_equal_fast(prop, "window_bits", 11))
|
||||
{
|
||||
if (z)
|
||||
z->ex = (int) val;
|
||||
return true;
|
||||
}
|
||||
@ -139,9 +145,10 @@ static bool zlib_deflate_trans(
|
||||
uint32_t *rd, uint32_t *wn,
|
||||
enum trans_stream_error *error)
|
||||
{
|
||||
int zret;
|
||||
bool ret;
|
||||
uint32_t pre_avail_in, pre_avail_out;
|
||||
int zret = 0;
|
||||
bool ret = false;
|
||||
uint32_t pre_avail_in = 0;
|
||||
uint32_t pre_avail_out = 0;
|
||||
struct zlib_trans_stream *zt = (struct zlib_trans_stream *) data;
|
||||
z_stream *z = &zt->z;
|
||||
|
||||
@ -202,8 +209,9 @@ static bool zlib_inflate_trans(
|
||||
enum trans_stream_error *error)
|
||||
{
|
||||
int zret;
|
||||
bool ret;
|
||||
uint32_t pre_avail_in, pre_avail_out;
|
||||
bool ret = false;
|
||||
uint32_t pre_avail_in = 0;
|
||||
uint32_t pre_avail_out = 0;
|
||||
struct zlib_trans_stream *zt = (struct zlib_trans_stream *) data;
|
||||
z_stream *z = &zt->z;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user