No real changes, just use smart pointers in GIF decoding code.
Use wxScopedArray to make the code much shorter and guarantee that it doesn't leak memory. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75953 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "wx/gifdecod.h"
|
#include "wx/gifdecod.h"
|
||||||
|
#include "wx/scopedarray.h"
|
||||||
#include "wx/scopedptr.h"
|
#include "wx/scopedptr.h"
|
||||||
#include "wx/scopeguard.h"
|
#include "wx/scopeguard.h"
|
||||||
|
|
||||||
@@ -317,26 +318,18 @@ wxGIFErrorCode
|
|||||||
wxGIFDecoder::dgif(wxInputStream& stream, GIFImage *img, int interl, int bits)
|
wxGIFDecoder::dgif(wxInputStream& stream, GIFImage *img, int interl, int bits)
|
||||||
{
|
{
|
||||||
static const int allocSize = 4096 + 1;
|
static const int allocSize = 4096 + 1;
|
||||||
int *ab_prefix = new int[allocSize]; // alphabet (prefixes)
|
|
||||||
if (ab_prefix == NULL)
|
|
||||||
{
|
|
||||||
return wxGIF_MEMERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
int *ab_tail = new int[allocSize]; // alphabet (tails)
|
wxScopedArray<int> ab_prefix(allocSize); // alphabet (prefixes)
|
||||||
if (ab_tail == NULL)
|
if ( !ab_prefix )
|
||||||
{
|
|
||||||
delete[] ab_prefix;
|
|
||||||
return wxGIF_MEMERR;
|
return wxGIF_MEMERR;
|
||||||
}
|
|
||||||
|
|
||||||
int *stack = new int[allocSize]; // decompression stack
|
wxScopedArray<int> ab_tail(allocSize); // alphabet (tails)
|
||||||
if (stack == NULL)
|
if ( !ab_tail )
|
||||||
{
|
return wxGIF_MEMERR;
|
||||||
delete[] ab_prefix;
|
|
||||||
delete[] ab_tail;
|
wxScopedArray<int> stack(allocSize); // decompression stack
|
||||||
|
if ( !stack )
|
||||||
return wxGIF_MEMERR;
|
return wxGIF_MEMERR;
|
||||||
}
|
|
||||||
|
|
||||||
int ab_clr; // clear code
|
int ab_clr; // clear code
|
||||||
int ab_fin; // end of info code
|
int ab_fin; // end of info code
|
||||||
@@ -406,21 +399,11 @@ wxGIFDecoder::dgif(wxInputStream& stream, GIFImage *img, int interl, int bits)
|
|||||||
// GIF files, the allocSize of 4096+1 is enough. This
|
// GIF files, the allocSize of 4096+1 is enough. This
|
||||||
// will only happen with badly formed GIFs.
|
// will only happen with badly formed GIFs.
|
||||||
if (pos >= allocSize)
|
if (pos >= allocSize)
|
||||||
{
|
|
||||||
delete[] ab_prefix;
|
|
||||||
delete[] ab_tail;
|
|
||||||
delete[] stack;
|
|
||||||
return wxGIF_INVFORMAT;
|
return wxGIF_INVFORMAT;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pos >= allocSize)
|
if (pos >= allocSize)
|
||||||
{
|
|
||||||
delete[] ab_prefix;
|
|
||||||
delete[] ab_tail;
|
|
||||||
delete[] stack;
|
|
||||||
return wxGIF_INVFORMAT;
|
return wxGIF_INVFORMAT;
|
||||||
}
|
|
||||||
|
|
||||||
stack[pos] = code; // push last code into the stack
|
stack[pos] = code; // push last code into the stack
|
||||||
abcabca = code; // save for special case
|
abcabca = code; // save for special case
|
||||||
@@ -433,12 +416,7 @@ wxGIFDecoder::dgif(wxInputStream& stream, GIFImage *img, int interl, int bits)
|
|||||||
// to reset it. This checks whether we really got it, otherwise
|
// to reset it. This checks whether we really got it, otherwise
|
||||||
// the GIF is damaged.
|
// the GIF is damaged.
|
||||||
if (ab_free > ab_max)
|
if (ab_free > ab_max)
|
||||||
{
|
|
||||||
delete[] ab_prefix;
|
|
||||||
delete[] ab_tail;
|
|
||||||
delete[] stack;
|
|
||||||
return wxGIF_INVFORMAT;
|
return wxGIF_INVFORMAT;
|
||||||
}
|
|
||||||
|
|
||||||
// This assert seems unnecessary since the condition above
|
// This assert seems unnecessary since the condition above
|
||||||
// eliminates the only case in which it went false. But I really
|
// eliminates the only case in which it went false. But I really
|
||||||
@@ -578,10 +556,6 @@ as an End of Information itself)
|
|||||||
}
|
}
|
||||||
while (code != ab_fin);
|
while (code != ab_fin);
|
||||||
|
|
||||||
delete [] ab_prefix ;
|
|
||||||
delete [] ab_tail ;
|
|
||||||
delete [] stack ;
|
|
||||||
|
|
||||||
return wxGIF_OK;
|
return wxGIF_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user