stream->height = height;
stream->bbx = width/16;
stream->bby = height/16;
- stream->current = (YUV*)malloc(width*height*sizeof(YUV));
- stream->oldpic = (YUV*)malloc(width*height*sizeof(YUV));
- stream->mvdx = (int*)malloc(stream->bbx*stream->bby*sizeof(int));
- stream->mvdy = (int*)malloc(stream->bbx*stream->bby*sizeof(int));
+ stream->current = (YUV*)rfx_calloc(width*height*sizeof(YUV));
+ stream->oldpic = (YUV*)rfx_calloc(width*height*sizeof(YUV));
+ stream->mvdx = (int*)rfx_alloc(stream->bbx*stream->bby*sizeof(int));
+ stream->mvdy = (int*)rfx_alloc(stream->bbx*stream->bby*sizeof(int));
stream->do_motion = 0;
- memset(stream->oldpic, 0, width*height*sizeof(YUV));
- memset(stream->current, 0, width*height*sizeof(YUV));
-
assert((stream->width&15) == 0);
assert((stream->height&15) == 0);
assert((stream->bbx*16) == stream->width);
}
void swf_VideoStreamClear(VIDEOSTREAM*stream)
{
- free(stream->oldpic);stream->oldpic = 0;
- free(stream->current);stream->current = 0;
- free(stream->mvdx);stream->mvdx=0;
- free(stream->mvdy);stream->mvdy=0;
+ rfx_free(stream->oldpic);stream->oldpic = 0;
+ rfx_free(stream->current);stream->current = 0;
+ rfx_free(stream->mvdx);stream->mvdx=0;
+ rfx_free(stream->mvdy);stream->mvdy=0;
}
typedef struct _block_t
VIDEOSTREAM stream;
VIDEOSTREAM* s = &stream;
TAG*tag;
- RGBA*pic = malloc(256*256*sizeof(RGBA));
+ RGBA*pic = rfx_alloc(256*256*sizeof(RGBA));
block_t fb;
int x,y;
int bx,by;
RGBA* pic = 0;
VIDEOSTREAM stream;
- pic = malloc(width*height*4);
- memset(pic, 0, width*height*4);
+ pic = rfx_calloc(width*height*4);
memset(&swf,0,sizeof(SWF));
memset(&obj,0,sizeof(obj));
memset(&stream, 0, sizeof(stream));
getPNG(fname, &width, &height, &data);
- pic = (RGBA*)malloc(width*height*sizeof(RGBA));
- pic2 = (RGBA*)malloc(width*height*sizeof(RGBA));
+ pic = (RGBA*)rfx_alloc(width*height*sizeof(RGBA));
+ pic2 = (RGBA*)rfx_alloc(width*height*sizeof(RGBA));
memcpy(pic, data, width*height*sizeof(RGBA));
- free(data);
+ rfx_free(data);
printf("Compressing %s, size %dx%d\n", fname, width, height);
U8*data;
while(op)
{
- action->next = (ActionTAG*)malloc(sizeof(ActionTAG));
- memset(action->next, 0, sizeof(ActionTAG));
+ action->next = (ActionTAG*)rfx_calloc(sizeof(ActionTAG));
action->next->prev = action;
action->next->next = 0;
action->next->parent = tmp.next;
length = swf_GetU16(tag);
if(length) {
- data = malloc(length);
+ data = rfx_alloc(length);
swf_GetBlock(tag, data, length);
} else {
data = 0;
{
ActionTAG*tmp;
if(action->data && action->data != action->tmp)
- free(action->data);
+ rfx_free(action->data);
tmp = action;
action=action->next;
- free(tmp);
+ rfx_free(tmp);
}
}
}
#ifdef MAX_LOOKUP
- for (t=0;t<MAX_LOOKUP;t++) if (lookup[t]) free(lookup[t]);
+ for (t=0;t<MAX_LOOKUP;t++) if (lookup[t]) rfx_free(lookup[t]);
#endif
}
if(replacement)
{
int newlen = strlen(replacement);
- char * newdata = malloc(atag->len - replacelen + newlen);
+ char * newdata = rfx_alloc(atag->len - replacelen + newlen);
int rpos = replacepos - atag->data;
memcpy(newdata, atag->data, rpos);
memcpy(&newdata[rpos], replacement, newlen);
memcpy(&newdata[rpos+newlen], &replacepos[replacelen],
&data[atag->len] - &replacepos[replacelen]);
- free(atag->data);
+ rfx_free(atag->data);
atag->data = newdata;
data = &atag->data[rpos+newlen+1];
}
/*static ActionTAG* swf_ActionStart()
{
ActionTAG*atag;
- atag = (ActionTAG*)malloc(sizeof(ActionTAG));
+ atag = (ActionTAG*)rfx_alloc(sizeof(ActionTAG));
atag->prev = 0;
atag->next = 0;
atag->parent = 0;
}
last->prev->next = 0;
- free(last);
+ rfx_free(last);
}*/
static ActionTAG*lastATAG(ActionTAG*atag)
ActionTAG* swf_AddActionTAG(ActionTAG*atag, U8 op, U8*data, U16 len)
{
ActionTAG*tmp;
- tmp = (ActionTAG*)malloc(sizeof(ActionTAG));
+ tmp = (ActionTAG*)rfx_alloc(sizeof(ActionTAG));
tmp->next = 0;
if(atag) {
tmp->prev = atag;
ActionTAG* action_PushString(ActionTAG*atag, char*str)
{
int l = strlen(str);
- char*ptr = (char*)malloc(l+2);
+ char*ptr = (char*)rfx_alloc(l+2);
ptr[0] = 0; // string
strcpy(&ptr[1], str);
return swf_AddActionTAG(atag, ACTION_PUSH, (U8*)ptr, l+2);
}
ActionTAG* action_PushFloat(ActionTAG*atag, float f)
{
- char*ptr = (char*)malloc(5);
+ char*ptr = (char*)rfx_alloc(5);
U32 fd = *(U32*)&f;
ptr[0] = 1; //float
ptr[1] = fd;
}
ActionTAG* action_PushDouble(ActionTAG*atag, double d)
{
- char*ptr = (char*)malloc(9);
+ char*ptr = (char*)rfx_alloc(9);
U8*dd = (U8*)&d;
ptr[0] = 6; //double
#ifdef WORDS_BIGENDIAN
{
int l1= strlen(url);
int l2= strlen(label);
- char*ptr = malloc(l1+l2+2);
+ char*ptr = rfx_alloc(l1+l2+2);
strcpy(ptr, url);
strcpy(&ptr[l1+1], label);
return swf_AddActionTAG(atag, ACTION_GETURL, ptr, l1+l2+2);
swf_SetBlock(tag, buffer, len);
swf_SetU8(tag, 0);
- free(buffer);
+ rfx_free(buffer);
a = swf_ActionGet(tag);
swf_DeleteTag(tag);
static void RFXSWF_init_destination(j_compress_ptr cinfo)
{ JPEGDESTMGR * dmgr = (JPEGDESTMGR *)cinfo->dest;
- dmgr->buffer = (JOCTET*)malloc(OUTBUFFER_SIZE);
+ dmgr->buffer = (JOCTET*)rfx_alloc(OUTBUFFER_SIZE);
dmgr->mgr.next_output_byte = dmgr->buffer;
dmgr->mgr.free_in_buffer = OUTBUFFER_SIZE;
}
static void RFXSWF_term_destination(j_compress_ptr cinfo)
{ JPEGDESTMGR * dmgr = (JPEGDESTMGR *)cinfo->dest;
swf_SetBlock(dmgr->t,(U8*)dmgr->buffer,OUTBUFFER_SIZE-dmgr->mgr.free_in_buffer);
- free(dmgr->buffer);
+ rfx_free(dmgr->buffer);
dmgr->mgr.free_in_buffer = 0;
}
// redirect compression lib output to local SWF Tag structure
- jpeg = (JPEGDESTMGR *)malloc(sizeof(JPEGDESTMGR));
- if (!jpeg) return NULL;
+ jpeg = (JPEGDESTMGR *)rfx_calloc(sizeof(JPEGDESTMGR));
- memset(jpeg,0x00,sizeof(JPEGDESTMGR));
jpeg->cinfo.err = jpeg_std_error(&jpeg->jerr);
jpeg_create_compress(&jpeg->cinfo);
{ JPEGDESTMGR * jpeg = (JPEGDESTMGR *)jpegbits;
if (!jpeg) return -1;
jpeg_finish_compress(&jpeg->cinfo);
- free(jpeg);
+ rfx_free(jpeg);
return 0;
}
jpeg_start_decompress(&cinfo);
out = swf_SetJPEGBitsStart(t,cinfo.output_width,cinfo.output_height,quality);
- scanline = (U8*)malloc(4*cinfo.output_width);
+ scanline = (U8*)rfx_alloc(4*cinfo.output_width);
if (scanline)
{ int y;
jpeg_read_header(&cinfo, TRUE);
*width = cinfo.image_width;
*height = cinfo.image_height;
- dest = malloc(sizeof(RGBA)*cinfo.image_width*cinfo.image_height);
+ dest = rfx_alloc(sizeof(RGBA)*cinfo.image_width*cinfo.image_height);
jpeg_start_decompress(&cinfo);
int y;
int x;
jpeg_read_scanlines(&cinfo,&to,1);
for(x=cinfo.output_width-1;x>=0;--x) {
- int b = to[x*3+0];
+ int r = to[x*3+0];
int g = to[x*3+1];
- int r = to[x*3+2];
+ int b = to[x*3+2];
line[x].r = r;
line[x].g = g;
line[x].b = b;
int RFXSWF_deflate_wraper(TAG * t,z_stream * zs,boolean finish)
{
- U8*data=malloc(OUTBUFFER_SIZE);
+ U8*data=rfx_alloc(OUTBUFFER_SIZE);
zs->next_out = data;
zs->avail_out = OUTBUFFER_SIZE;
while (1)
#ifdef DEBUG_RFXSWF
fprintf(stderr,"rfxswf: zlib compression error (%i)\n",status);
#endif
- free(data);
+ rfx_free(data);
return status;
}
}
if(!finish) {
- free(data);
+ rfx_free(data);
return 0;
}
#ifdef DEBUG_RFXSWF
fprintf(stderr,"rfxswf: zlib compression error (%i)\n",status);
#endif
- free(data);
+ rfx_free(data);
return status;
}
if(status == Z_STREAM_END)
break;
}
- free(data);
+ rfx_free(data);
return 0;
}
if (!pal) // create default palette for grayscale images
{ int i;
- pal = malloc(256*sizeof(RGBA));
+ pal = rfx_alloc(256*sizeof(RGBA));
for (i=0;i<256;i++) { pal[i].r = pal[i].g = pal[i].b = i; pal[i].a = 0xff;}
ncolors = 256;
}
if (deflateInit(&zs,Z_DEFAULT_COMPRESSION)==Z_OK)
{ U8 * zpal; // compress palette
- if ((zpal = malloc(ncolors*4)))
+ if ((zpal = rfx_alloc(ncolors*4)))
{ U8 * pp = zpal;
int i;
deflateEnd(&zs);
- free(zpal);
+ rfx_free(zpal);
} else res = -2; // memory error
} else res = -3; // zlib error
}
- if (!palette) free(pal);
+ if (!palette) rfx_free(pal);
return res;
}
int pos2=0;
char alpha = tag->id == ST_DEFINEBITSLOSSLESS2;
int t,x,y;
- RGBA*palette;
+ RGBA*palette = 0;
U8*data,*data2;
RGBA*dest;
if(tag->id != ST_DEFINEBITSLOSSLESS &&
*dwidth = width = swf_GetU16(tag);
*dheight = height = swf_GetU16(tag);
- dest = malloc(sizeof(RGBA)*width*height);
+ dest = rfx_alloc(sizeof(RGBA)*width*height);
if(format == 3) cols = swf_GetU8(tag) + 1;
else cols = 0;
datalen = (width*height*bpp/8+cols*8);
do {
if(data)
- free(data);
+ rfx_free(data);
datalen+=4096;
- data = malloc(datalen);
+ data = rfx_alloc(datalen);
error = uncompress (data, &datalen, &tag->data[tag->pos], tag->len-tag->pos);
} while(error == Z_BUF_ERROR);
if(error != Z_OK) {
return 0;
}
pos = 0;
-
- palette = (RGBA*)malloc(cols*sizeof(RGBA));
- for(t=0;t<cols;t++) {
- palette[t].r = data[pos++];
- palette[t].g = data[pos++];
- palette[t].b = data[pos++];
- if(alpha) {
- palette[t].a = data[pos++];
- }
+
+ if(cols) {
+ palette = (RGBA*)rfx_alloc(cols*sizeof(RGBA));
+ for(t=0;t<cols;t++) {
+ palette[t].r = data[pos++];
+ palette[t].g = data[pos++];
+ palette[t].b = data[pos++];
+ if(alpha) {
+ palette[t].a = data[pos++];
+ }
+ }
}
for(y=0;y<height;y++) {
pos+=((srcwidth+3)&~3)-srcwidth; //align
}
if(palette)
- free(palette);
- free(data);
+ rfx_free(palette);
+ rfx_free(data);
return dest;
}
swf_SetJPEGBitsFinish(jpeg);
PUT32(&tag->data[pos], tag->len - pos - 4);
- data=malloc(OUTBUFFER_SIZE);
+ data=rfx_alloc(OUTBUFFER_SIZE);
memset(&zs,0x00,sizeof(z_stream));
if (deflateInit(&zs,Z_DEFAULT_COMPRESSION)!=Z_OK) {
}
deflateEnd(&zs);
- free(data);
+ rfx_free(data);
return 0;
}
#endif
// fprintf(stderr,"%s\n",var);
- buf = (unsigned char*)malloc(strlen(var) + sizeof(PREFIX) + 2);
+ buf = (unsigned char*)rfx_alloc(strlen(var) + sizeof(PREFIX) + 2);
if (!buf) return;
strcpy(buf, PREFIX);
}
if ((oldval = getenv(buf)))
- { newval = (unsigned char*)malloc(strlen(oldval) + strlen(buf) + strlen(&c[1]) + 3);
+ { newval = (unsigned char*)rfx_alloc(strlen(oldval) + strlen(buf) + strlen(&c[1]) + 3);
if (!newval) return;
c[0] = '=';
putenv(newval);
if (oldval)
- { free(oldval);
- free(buf);
+ { rfx_free(oldval);
+ rfx_free(buf);
}
}
if (!buf) return NULL;
size = atoi(buf);
- buf = (unsigned char*)malloc(size + 1);
+ buf = (unsigned char*)rfx_alloc(size + 1);
if (buf)
{ do
{ got = fread(buf + sofar, 1, size - sofar, stdin);
if ((query) && strlen(query))
{ dupquery = strdup(query);
swf_scanquery(dupquery);
- free(dupquery);
+ rfx_free(dupquery);
}
method = getenv("REQUEST_METHOD");
if ((method) && ! strcmp(method, "POST"))
{ query = swf_postread();
if ((query)&&(query[0]!=0)) swf_scanquery(query);
- free(query);
+ rfx_free(query);
}
}
static void swf_ShapeDrawerInit(drawer_t*draw, TAG*tag, int fillstylebits, int linestylebits)
{
- SWFSHAPEDRAWER*sdraw = malloc(sizeof(SWFSHAPEDRAWER));
- memset(sdraw, 0, sizeof(SWFSHAPEDRAWER));
+ SWFSHAPEDRAWER*sdraw = rfx_calloc(sizeof(SWFSHAPEDRAWER));
draw->internal = sdraw;
draw->setLineStyle = swf_ShapeDrawerSetLineStyle;
swf_ShapeFree(sdraw->shape);
sdraw->shape = 0;
- free(draw->internal);
+ rfx_free(draw->internal);
draw->internal = 0;
}
SHAPE* swf_ShapeDrawerToShape(drawer_t*draw)
{
SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
- SHAPE* shape = malloc(sizeof(SHAPE));
+ SHAPE* shape = rfx_alloc(sizeof(SHAPE));
if(!sdraw->isfinished) {
fprintf(stderr, "Warning: you should Finish() your drawer before calling DrawerToShape");
swf_ShapeDrawerFinish(draw);
}
memcpy(shape, sdraw->shape, sizeof(SHAPE));
shape->bitlen = (sdraw->tag->len-1)*8;
- shape->data = (U8*)malloc(sdraw->tag->len-1);
+ shape->data = (U8*)rfx_alloc(sdraw->tag->len-1);
memcpy(shape->data, &sdraw->tag->data[1], sdraw->tag->len-1);
return shape;
}
return 0;
}
- font = malloc(sizeof(SWFFONT));
- memset(font, 0, sizeof(SWFFONT));
+ font = rfx_calloc(sizeof(SWFFONT));
font->id = -1;
font->version = 2;
- font->layout = malloc(sizeof(SWFLAYOUT));
- memset(font->layout, 0, sizeof(SWFLAYOUT));
- font->layout->bounds = malloc(face->num_glyphs*sizeof(SRECT));
+ font->layout = rfx_calloc(sizeof(SWFLAYOUT));
+ font->layout->bounds = rfx_calloc(face->num_glyphs*sizeof(SRECT));
font->style = ((face->style_flags&FT_STYLE_FLAG_ITALIC)?FONT_STYLE_ITALIC:0)
|((face->style_flags&FT_STYLE_FLAG_BOLD)?FONT_STYLE_BOLD:0);
font->encoding = FONT_ENCODING_UNICODE;
- font->glyph2ascii = malloc(face->num_glyphs*sizeof(U16));
- memset(font->glyph2ascii, 0, face->num_glyphs*sizeof(U16));
+ font->glyph2ascii = rfx_calloc(face->num_glyphs*sizeof(U16));
font->maxascii = 0;
- font->glyph = malloc(face->num_glyphs*sizeof(SWFGLYPH));
- memset(font->glyph, 0, face->num_glyphs*sizeof(SWFGLYPH));
+ font->glyph = rfx_calloc(face->num_glyphs*sizeof(SWFGLYPH));
if(FT_HAS_GLYPH_NAMES(face)) {
- font->glyphnames = malloc(face->num_glyphs*sizeof(char*));
- memset(font->glyphnames,0,face->num_glyphs*sizeof(char*));
+ font->glyphnames = rfx_calloc(face->num_glyphs*sizeof(char*));
}
font->layout->ascent = abs(face->ascender)*FT_SCALE*loadfont_scale*20/FT_SUBPIXELS/2; //face->bbox.xMin;
if(full_unicode)
font->maxascii = 65535;
- font->ascii2glyph = malloc(font->maxascii*sizeof(int));
+ font->ascii2glyph = rfx_calloc(font->maxascii*sizeof(int));
for(t=0;t<font->maxascii;t++) {
int g = FT_Get_Char_Index(face, t);
font->numchars = 0;
- glyph2glyph = (int*)malloc(face->num_glyphs*sizeof(int));
+ glyph2glyph = (int*)rfx_calloc(face->num_glyphs*sizeof(int));
for(t=0; t < face->num_glyphs; t++) {
FT_Glyph glyph;
font->ascii2glyph[t] = glyph2glyph[font->ascii2glyph[t]];
}
}
- free(glyph2glyph);
+ rfx_free(glyph2glyph);
FT_Done_Face(face);
FT_Done_FreeType(ftlibrary);ftlibrary=0;
underline = T1_GetUnderlinePosition(nr);
bbox = T1_GetFontBBox(nr);
- font = (SWFFONT*)malloc(sizeof(SWFFONT));
- memset(font, 0, sizeof(SWFFONT));
+ font = (SWFFONT*)rfx_calloc(sizeof(SWFFONT));
font->version = 2;
if(fontname)
font->name = (U8*)strdup(fontname);
else
font->name = 0;
- font->layout = (SWFLAYOUT*)malloc(sizeof(SWFLAYOUT));
- memset(font->layout, 0, sizeof(SWFLAYOUT));
+ font->layout = (SWFLAYOUT*)rfx_calloc(sizeof(SWFLAYOUT));
num = 0;
charname = charnames;
font->style = (/*bold*/0?FONT_STYLE_BOLD:0) + (angle>0.05?FONT_STYLE_ITALIC:0);
- font->glyph = (SWFGLYPH*)malloc(num*sizeof(SWFGLYPH));
- memset(font->glyph, 0, num*sizeof(SWFGLYPH));
- font->glyph2ascii = (U16*)malloc(num*sizeof(U16));
- memset(font->glyph2ascii, 0, num*sizeof(U16));
- font->ascii2glyph = (int*)malloc(font->maxascii*sizeof(int));
- memset(font->ascii2glyph, -1, font->maxascii*sizeof(int));
+ font->glyph = (SWFGLYPH*)rfx_calloc(num*sizeof(SWFGLYPH));
+ font->glyph2ascii = (U16*)rfx_calloc(num*sizeof(U16));
+ font->ascii2glyph = (int*)rfx_calloc(font->maxascii*sizeof(int));
font->layout->ascent = (U16)(underline - bbox.lly);
font->layout->descent = (U16)(bbox.ury - underline);
font->layout->leading = (U16)(font->layout->ascent -
font->layout->descent -
(bbox.lly - bbox.ury));
- font->layout->bounds = (SRECT*)malloc(sizeof(SRECT)*num);
- memset(font->layout->bounds, 0, sizeof(SRECT)*num);
+ font->layout->bounds = (SRECT*)rfx_calloc(sizeof(SRECT)*num);
font->layout->kerningcount = 0;
font->layout->kerning = 0;
- font->glyphnames = malloc(num*sizeof(char*));
- memset(font->glyphnames, 0, num*sizeof(char*));
+ font->glyphnames = rfx_calloc(num*sizeof(char*));
num = 0;
T1_DeleteFont(nr);
for(t=0;t<256;t++)
- free(encoding[t]);
+ rfx_free(encoding[t]);
return font;
}
SWFFONT* swf_DummyFont()
{
- SWFFONT*font = (SWFFONT*)malloc(sizeof(SWFFONT));
- memset(font, 0, sizeof(SWFFONT));
+ SWFFONT*font = (SWFFONT*)rfx_calloc(sizeof(SWFFONT));
return font;
}
swf_ResetReadBits(tag);
l = strlen(&tag->data[tag->pos]);
t = 0;
- data = malloc(l+1);
+ data = rfx_alloc(l+1);
obj->name = data;
while((data[t++] = swf_GetU8(tag)));
}
void swf_PlaceObjectFree(SWFPLACEOBJECT* obj)
{
if(obj->name)
- free(obj->name);
- free(obj);
+ rfx_free(obj->name);
}
{
if(!s)
return;
- if (s->linestyle.data) free(s->linestyle.data);
+ if (s->linestyle.data) rfx_free(s->linestyle.data);
s->linestyle.data = NULL;
s->linestyle.n = 0;
- if (s->fillstyle.data) free(s->fillstyle.data);
+ if (s->fillstyle.data) rfx_free(s->fillstyle.data);
s->fillstyle.data = NULL;
s->fillstyle.n = 0;
- if (s->data) free(s->data);
+ if (s->data) rfx_free(s->data);
s->data = NULL;
- free(s);
+ rfx_free(s);
}
int swf_ShapeNew(SHAPE * * s)
{
SHAPE * sh;
if (!s) return -1;
- sh = (SHAPE *)malloc(sizeof(SHAPE));
+ sh = (SHAPE *)rfx_calloc(sizeof(SHAPE));
*s = sh;
- memset(sh,0,sizeof(SHAPE));
return 0;
}
swf_SetTagPos(t,pos);
len = (bitl+7)/8;
- if (sh->data) free(sh->data);
- sh->data = (U8*)malloc(len);
+ if (sh->data) rfx_free(sh->data);
+ sh->data = (U8*)rfx_alloc(len);
if (sh->data)
{ sh->bitlen = bitl;
// handle memory
if (s->fillstyle.data)
- { FILLSTYLE * new = (FILLSTYLE *)realloc(s->fillstyle.data,(s->fillstyle.n+1)*sizeof(FILLSTYLE));
+ { FILLSTYLE * new = (FILLSTYLE *)rfx_realloc(s->fillstyle.data,(s->fillstyle.n+1)*sizeof(FILLSTYLE));
if (!new) return -1;
s->fillstyle.data = new;
}
else
- { s->fillstyle.data = (FILLSTYLE *)malloc(sizeof(FILLSTYLE));
+ { s->fillstyle.data = (FILLSTYLE *)rfx_alloc(sizeof(FILLSTYLE));
s->fillstyle.n = 0;
if (!s->fillstyle.data) return -1;
}
def.r = def.g = def.b = 0;
}
if (s->linestyle.data)
- { LINESTYLE * new = (LINESTYLE *)realloc(s->linestyle.data,(s->linestyle.n+1)*sizeof(LINESTYLE));
+ { LINESTYLE * new = (LINESTYLE *)rfx_realloc(s->linestyle.data,(s->linestyle.n+1)*sizeof(LINESTYLE));
if (!new) return -1;
s->linestyle.data = new;
}
else
- { s->linestyle.data = (LINESTYLE *)malloc(sizeof(LINESTYLE));
+ { s->linestyle.data = (LINESTYLE *)rfx_alloc(sizeof(LINESTYLE));
s->linestyle.n = 0;
if (!s->linestyle.data) return -1;
}
linebits = swf_GetBits(tag, 4);
}
if(flags&1) { //move
- lines->next = (SHAPELINE*)malloc(sizeof(SHAPELINE));
+ lines->next = (SHAPELINE*)rfx_alloc(sizeof(SHAPELINE));
lines = lines->next;
lines->type = moveTo;
lines->x = x;
if(v) y += d;
else x += d;
}
- lines->next = (SHAPELINE*)malloc(sizeof(SHAPELINE));
+ lines->next = (SHAPELINE*)rfx_alloc(sizeof(SHAPELINE));
lines = lines->next;
lines->type = lineTo;
lines->x = x;
x += swf_GetSBits(tag, n);
y += swf_GetSBits(tag, n);
- lines->next = (SHAPELINE*)malloc(sizeof(SHAPELINE));
+ lines->next = (SHAPELINE*)rfx_alloc(sizeof(SHAPELINE));
lines = lines->next;
lines->type = splineTo;
lines->sx = x1;
SHAPELINE*line = s->lines;
while(line) {
SHAPELINE*next = line->next;
- free(line);
+ rfx_free(line);
line = next;
}
if(s->linestyles)
- free(s->linestyles);
+ rfx_free(s->linestyles);
if(s->fillstyles)
- free(s->fillstyles);
+ rfx_free(s->fillstyles);
if(s->bbox)
- free(s->bbox);
+ rfx_free(s->bbox);
}
SHAPE2* swf_ShapeToShape2(SHAPE*shape) {
- SHAPE2*shape2 = (SHAPE2*)malloc(sizeof(SHAPE2));
+ SHAPE2*shape2 = (SHAPE2*)rfx_alloc(sizeof(SHAPE2));
shape2->numlinestyles = shape->linestyle.n;
- shape2->linestyles = (LINESTYLE*)malloc(sizeof(LINESTYLE)*shape->linestyle.n);
+ shape2->linestyles = (LINESTYLE*)rfx_alloc(sizeof(LINESTYLE)*shape->linestyle.n);
memcpy(shape2->linestyles, shape->linestyle.data, sizeof(LINESTYLE)*shape->linestyle.n);
shape2->numfillstyles = shape->fillstyle.n;
- shape2->fillstyles = (FILLSTYLE*)malloc(sizeof(FILLSTYLE)*shape->fillstyle.n);
+ shape2->fillstyles = (FILLSTYLE*)rfx_alloc(sizeof(FILLSTYLE)*shape->fillstyle.n);
memcpy(shape2->fillstyles, shape->fillstyle.data, sizeof(FILLSTYLE)*shape->fillstyle.n);
shape2->lines = swf_ParseShapeData(shape->data, shape->bitlen, shape->bits.fill, shape->bits.line);
memset(shape, 0, sizeof(SHAPE));
shape->linestyle.n = shape2->numlinestyles;
- shape->linestyle.data = (LINESTYLE*)malloc(sizeof(LINESTYLE)*shape->linestyle.n);
+ shape->linestyle.data = (LINESTYLE*)rfx_alloc(sizeof(LINESTYLE)*shape->linestyle.n);
memcpy(shape->linestyle.data, shape2->linestyles, sizeof(LINESTYLE)*shape->linestyle.n);
shape->fillstyle.n = shape2->numfillstyles;
- shape->fillstyle.data = (FILLSTYLE*)malloc(sizeof(FILLSTYLE)*shape->fillstyle.n);
+ shape->fillstyle.data = (FILLSTYLE*)rfx_alloc(sizeof(FILLSTYLE)*shape->fillstyle.n);
memcpy(shape->fillstyle.data, shape2->fillstyles, sizeof(FILLSTYLE)*shape->fillstyle.n);
swf_ShapeCountBits(shape,NULL,NULL);
count = swf_GetU16(tag);
shape->numfillstyles = count;
- shape->fillstyles = malloc(sizeof(FILLSTYLE)*count);
-
- for(t=0;t<count;t++)
- {
- int type;
- U8*pos;
- FILLSTYLE*dest = &shape->fillstyles[t];
- type = swf_GetU8(tag); //type
- shape->fillstyles[t].type = type;
- if(type == 0) {
- /* plain color */
- if(num == 3)
- swf_GetRGBA(tag, &dest->color);
- else
- swf_GetRGB(tag, &dest->color);
- }
- else if(type == 0x10 || type == 0x12)
- {
- /* linear/radial gradient fill */
- swf_ResetReadBits(tag);
- swf_GetMatrix(tag, &dest->m);
- swf_ResetReadBits(tag);
- swf_GetGradient(tag, &dest->gradient, num>=3?1:0);
- }
- else if(type == 0x40 || type == 0x41)
- {
- /* bitmap fill */
- swf_ResetReadBits(tag);
- dest->id_bitmap = swf_GetU16(tag); //id
- swf_ResetReadBits(tag); //?
- swf_GetMatrix(tag, &dest->m);
- }
- else {
- fprintf(stderr, "rfxswf:swftools.c Unknown fillstyle:0x%02x\n",type);
- }
+
+ if(shape->numfillstyles) {
+ shape->fillstyles = rfx_alloc(sizeof(FILLSTYLE)*count);
+
+ for(t=0;t<count;t++)
+ {
+ int type;
+ U8*pos;
+ FILLSTYLE*dest = &shape->fillstyles[t];
+ type = swf_GetU8(tag); //type
+ shape->fillstyles[t].type = type;
+ if(type == 0) {
+ /* plain color */
+ if(num == 3)
+ swf_GetRGBA(tag, &dest->color);
+ else
+ swf_GetRGB(tag, &dest->color);
+ }
+ else if(type == 0x10 || type == 0x12)
+ {
+ /* linear/radial gradient fill */
+ swf_ResetReadBits(tag);
+ swf_GetMatrix(tag, &dest->m);
+ swf_ResetReadBits(tag);
+ swf_GetGradient(tag, &dest->gradient, num>=3?1:0);
+ }
+ else if(type == 0x40 || type == 0x41)
+ {
+ /* bitmap fill */
+ swf_ResetReadBits(tag);
+ dest->id_bitmap = swf_GetU16(tag); //id
+ swf_ResetReadBits(tag); //?
+ swf_GetMatrix(tag, &dest->m);
+ }
+ else {
+ fprintf(stderr, "rfxswf:swftools.c Unknown fillstyle:0x%02x\n",type);
+ }
+ }
}
+
swf_ResetReadBits(tag);
count = swf_GetU8(tag); // line style array
if(count == 0xff)
//if(verbose) printf("lnum: %d\n", count);
shape->numlinestyles = count;
- shape->linestyles = malloc(sizeof(LINESTYLE)*count);
- /* TODO: should we start with 1 and insert a correct definition of the
- "built in" linestyle 0? */
- for(t=0;t<count;t++)
- {
- shape->linestyles[t].width = swf_GetU16(tag);
- if(num == 3)
- swf_GetRGBA(tag, &shape->linestyles[t].color);
- else
- swf_GetRGB(tag, &shape->linestyles[t].color);
+ if(count) {
+ shape->linestyles = rfx_alloc(sizeof(LINESTYLE)*count);
+ /* TODO: should we start with 1 and insert a correct definition of the
+ "built in" linestyle 0? */
+ for(t=0;t<count;t++)
+ {
+ shape->linestyles[t].width = swf_GetU16(tag);
+ if(num == 3)
+ swf_GetRGBA(tag, &shape->linestyles[t].color);
+ else
+ swf_GetRGB(tag, &shape->linestyles[t].color);
+ }
}
return;
}
id = swf_GetU16(tag); //id
memset(shape, 0, sizeof(SHAPE2));
- shape->bbox = malloc(sizeof(SRECT));
+ shape->bbox = rfx_alloc(sizeof(SRECT));
swf_GetRect(tag, &r);
memcpy(shape->bbox, &r, sizeof(SRECT));
char*buf;
int len = 0;
- buf = malloc(init->bufferSize);
+ buf = rfx_alloc(init->bufferSize);
if(!buf)
return;
swf_SetU16(tag, 0); // seek
}
swf_SetBlock(tag, buf, len);
- free(buf);
+ rfx_free(buf);
}
#endif
int numsamples = (int)(((swf_mp3_out_samplerate > 22050) ? 1152 : 576) * ((double)swf_mp3_in_samplerate/swf_mp3_out_samplerate));
int fs = 0;
- buf = malloc(bufsize);
+ buf = rfx_alloc(bufsize);
if(!buf)
return;
fprintf(stderr, "ok: mp3 nonempty block, %d samples, first:%d, framesize:%d\n",
numsamples, first, fs);
}*/
- free(buf);
+ rfx_free(buf);
}
void swf_SetSoundStreamEnd(TAG*tag)
((double)swf_mp3_in_samplerate/swf_mp3_out_samplerate)) // account for resampling
);
- buf = malloc(bufsize);
+ buf = rfx_alloc(bufsize);
if(!buf)
return;
len = 0;
}
- free(buf);
+ rfx_free(buf);
}
#endif
of = swf_GetU16(t);
n = of / 2;
f->numchars = n;
- f->glyph = malloc(sizeof(SWFGLYPH) * n);
- memset(f->glyph, 0, sizeof(SWFGLYPH) * n);
+ f->glyph = rfx_calloc(sizeof(SWFGLYPH) * n);
for (i = 1; i < n; i++)
swf_GetU16(t);
}
if (f->name)
- free(f->name);
+ rfx_free(f->name);
- f->name = (U8 *) malloc(l + 1);
+ f->name = (U8 *) rfx_alloc(l + 1);
swf_GetBlock(t, f->name, l);
f->name[l] = 0;
f->language = swf_GetU8(t);
}
- f->glyph2ascii = (U16 *) malloc(sizeof(U16) * f->numchars);
+ f->glyph2ascii = (U16 *) rfx_alloc(sizeof(U16) * f->numchars);
maxcode = 0;
for (i = 0; i < f->numchars; i++) {
f->glyph2ascii[i] = ((flags & FF_WIDECODES) ? swf_GetU16(t) : swf_GetU8(t));
if (maxcode < 256)
maxcode = 256;
f->maxascii = maxcode;
- f->ascii2glyph = (int *) malloc(sizeof(int) * maxcode);
+ f->ascii2glyph = (int *) rfx_alloc(sizeof(int) * maxcode);
memset(f->ascii2glyph, -1, sizeof(int) * maxcode);
for (i = 0; i < f->numchars; i++)
if (fid == id) {
int num = swf_GetU16(tag);
int t;
- f->glyphnames = malloc(sizeof(char *) * num);
+ f->glyphnames = rfx_alloc(sizeof(char *) * num);
for (t = 0; t < num; t++) {
f->glyphnames[t] = strdup(swf_GetString(tag));
}
font->encoding |= FONT_ENCODING_SHIFTJIS;
namelen = swf_GetU8(tag);
- font->name = (U8 *) malloc(namelen + 1);
+ font->name = (U8 *) rfx_alloc(namelen + 1);
font->name[namelen] = 0;
swf_GetBlock(tag, font->name, namelen);
font->version = 2;
glyphcount = swf_GetU16(tag);
font->numchars = glyphcount;
- font->glyph = (SWFGLYPH *) malloc(sizeof(SWFGLYPH) * glyphcount);
- memset(font->glyph, 0, sizeof(SWFGLYPH) * glyphcount);
- font->glyph2ascii = (U16 *) malloc(sizeof(U16) * glyphcount);
- memset(font->glyph2ascii, 0, sizeof(U16) * glyphcount);
+ font->glyph = (SWFGLYPH *) rfx_calloc(sizeof(SWFGLYPH) * glyphcount);
+ font->glyph2ascii = (U16 *) rfx_calloc(sizeof(U16) * glyphcount);
if (flags1 & 8) { // wide offsets
for (t = 0; t < glyphcount; t++)
if (maxcode < 256)
maxcode = 256;
font->maxascii = maxcode;
- font->ascii2glyph = (int *) malloc(sizeof(int) * maxcode);
+ font->ascii2glyph = (int *) rfx_alloc(sizeof(int) * maxcode);
memset(font->ascii2glyph, -1, sizeof(int) * maxcode);
for (t = 0; t < glyphcount; t++) {
font->ascii2glyph[font->glyph2ascii[t]] = t;
if (flags1 & 128) { // has layout
U16 kerningcount;
- font->layout = (SWFLAYOUT *) malloc(sizeof(SWFLAYOUT));
+ font->layout = (SWFLAYOUT *) rfx_alloc(sizeof(SWFLAYOUT));
font->layout->ascent = swf_GetU16(tag);
font->layout->descent = swf_GetU16(tag);
font->layout->leading = swf_GetU16(tag);
S16 advance = swf_GetS16(tag);
font->glyph[t].advance = advance;
}
- font->layout->bounds = malloc(glyphcount * sizeof(SRECT));
+ font->layout->bounds = rfx_alloc(glyphcount * sizeof(SRECT));
for (t = 0; t < glyphcount; t++) {
swf_ResetReadBits(tag);
swf_GetRect(tag, &font->layout->bounds[t]);
kerningcount = swf_GetU16(tag);
font->layout->kerningcount = kerningcount;
- font->layout->kerning = (SWFKERNING *) malloc(sizeof(SWFKERNING) * kerningcount);
+ font->layout->kerning = (SWFKERNING *) rfx_alloc(sizeof(SWFKERNING) * kerningcount);
if (kerningcount) {
- font->layout->kerning = malloc(sizeof(*font->layout->kerning) * kerningcount);
+ font->layout->kerning = rfx_alloc(sizeof(*font->layout->kerning) * kerningcount);
for (t = 0; t < kerningcount; t++) {
if (flags1 & 4) { // wide codes
font->layout->kerning[t].char1 = swf_GetU16(tag);
if ((!swf) || (!font))
return -1;
- f = (SWFFONT *) malloc(sizeof(SWFFONT));
- memset(f, 0x00, sizeof(SWFFONT));
+ f = (SWFFONT *) rfx_calloc(sizeof(SWFFONT));
t = swf->firstTag;
t = swf_NextTag(t);
}
if (f->id != id) {
- free(f);
+ rfx_free(f);
f = 0;
}
font[0] = f;
{
if (l) {
if (l->kerning)
- free(l->kerning);
+ rfx_free(l->kerning);
l->kerning = NULL;
if (l->bounds)
- free(l->bounds);
+ rfx_free(l->bounds);
l->bounds = NULL;
}
- free(l);
+ rfx_free(l);
}
int t;
for (t = 0; t < f->numchars; t++) {
if (f->glyphnames[t])
- free(f->glyphnames[t]);
+ rfx_free(f->glyphnames[t]);
}
- free(f->glyphnames);
+ rfx_free(f->glyphnames);
f->glyphnames = 0;
}
{
if (f->use) {
if(f->use->chars) {
- free(f->use->chars);f->use->chars = 0;
+ rfx_free(f->use->chars);f->use->chars = 0;
}
- free(f->use); f->use = 0;
+ rfx_free(f->use); f->use = 0;
}
}
static void font_freelayout(SWFFONT*f)
static void font_freename(SWFFONT*f)
{
if (f->name) {
- free(f->name);
+ rfx_free(f->name);
f->name = 0;
}
}
if (!font)
return;
- newplace = malloc(sizeof(int) * font->numchars);
+ newplace = rfx_alloc(sizeof(int) * font->numchars);
for (i = 0; i < font->numchars; i++) {
newplace[i] = i;
}
}
}
- newpos = malloc(sizeof(int) * font->numchars);
+ newpos = rfx_alloc(sizeof(int) * font->numchars);
for (i = 0; i < font->numchars; i++) {
newpos[newplace[i]] = i;
}
font->ascii2glyph[i] = newpos[font->ascii2glyph[i]];
}
- free(newpos);
- free(newplace);
+ rfx_free(newpos);
+ rfx_free(newplace);
}
void swf_FontPrepareForEditText(SWFFONT * font)
fprintf(stderr, "Usage initialized twice");
return -1;
}
- f->use = malloc(sizeof(FONTUSAGE));
+ f->use = rfx_alloc(sizeof(FONTUSAGE));
f->use->is_reduced = 0;
- f->use->chars = malloc(sizeof(f->use->chars[0]) * f->numchars);
- memset(f->use->chars, 0, sizeof(f->use->chars[0]) * f->numchars);
+ f->use->chars = rfx_calloc(sizeof(f->use->chars[0]) * f->numchars);
return 0;
}
{
if (!f || !f->use)
return;
- free(f->use->chars); f->use->chars = 0;
- free(f->use); f->use = 0;
+ rfx_free(f->use->chars); f->use->chars = 0;
+ rfx_free(f->use); f->use = 0;
}
int swf_FontUse(SWFFONT * f, U8 * s)
int swf_FontSetDefine(TAG * t, SWFFONT * f)
{
- U16 *ofs = (U16 *) malloc(f->numchars * 2);
+ U16 *ofs = (U16 *) rfx_alloc(f->numchars * 2);
int p, i, j;
if ((!t) || (!f))
swf_SetSimpleShape(t, f->glyph[i].shape);
swf_ResetWriteBits(t);
- free(ofs);
+ rfx_free(ofs);
return 0;
}
void swf_FontAddLayout(SWFFONT * f, int ascent, int descent, int leading)
{
- f->layout = (SWFLAYOUT *) malloc(sizeof(SWFLAYOUT));
+ f->layout = (SWFLAYOUT *) rfx_alloc(sizeof(SWFLAYOUT));
f->layout->ascent = ascent;
f->layout->descent = descent;
f->layout->leading = leading;
f->layout->kerningcount = 0;
f->layout->kerning = 0;
- f->layout->bounds = (SRECT *) malloc(sizeof(SRECT) * f->numchars);
- memset(f->layout->bounds, 0, sizeof(SRECT) * f->numchars);
+ f->layout->bounds = (SRECT *) rfx_calloc(sizeof(SRECT) * f->numchars);
}
int swf_FontSetInfo(TAG * t, SWFFONT * f)
swf_ShapeFree(f->glyph[i].shape);
f->glyph[i].shape = NULL;
}
- free(f->glyph);
+ rfx_free(f->glyph);
f->glyph = NULL;
}
if (f->ascii2glyph) {
- free(f->ascii2glyph);
+ rfx_free(f->ascii2glyph);
f->ascii2glyph = NULL;
}
if (f->glyph2ascii) {
- free(f->glyph2ascii);
+ rfx_free(f->glyph2ascii);
f->glyph2ascii = NULL;
}
font_freename(f);
font_freeglyphnames(f);
font_freeusage(f);
- free(f);
+ rfx_free(f);
}
int swf_TextSetInfoRecord(TAG * t, SWFFONT * font, U16 size, RGBA * color, int dx, int dy)
if (!f->numchars)
return;
- f->layout = (SWFLAYOUT *) malloc(sizeof(SWFLAYOUT));
- memset(f->layout, 0, sizeof(SWFLAYOUT));
- f->layout->bounds = (SRECT *) malloc(f->numchars * sizeof(SRECT));
+ f->layout = (SWFLAYOUT *) rfx_calloc(sizeof(SWFLAYOUT));
+ f->layout->bounds = (SRECT *) rfx_alloc(f->numchars * sizeof(SRECT));
f->layout->ascent = -32767;
f->layout->descent = -32767;
if(id == ST_END)
break;
tag2->len = tag2->memsize = len;
- tag2->data = malloc(len);
+ tag2->data = rfx_alloc(len);
memcpy(tag2->data, &tag->data[tag->pos], len);
/* I never saw recursive sprites, but they are (theoretically)
possible, so better add base here again */
}
num = swf_GetNumUsedIDs(tag);
- ptr = malloc(sizeof(int)*num);
+ ptr = rfx_alloc(sizeof(int)*num);
swf_GetUsedIDs(tag, ptr);
for(t=0;t<num;t++) {
}
}
+U8 swf_isShapeTag(TAG*tag)
+{
+ if(tag->id == ST_DEFINESHAPE ||
+ tag->id == ST_DEFINESHAPE2 ||
+ tag->id == ST_DEFINESHAPE3)
+ return 1;
+ return 0;
+}
+
+U8 swf_isImageTag(TAG*tag)
+{
+ if(tag->id == ST_DEFINEBITSJPEG ||
+ tag->id == ST_DEFINEBITSJPEG2 ||
+ tag->id == ST_DEFINEBITSJPEG3 ||
+ tag->id == ST_DEFINEBITSLOSSLESS ||
+ tag->id == ST_DEFINEBITSLOSSLESS2)
+ return 1;
+ return 0;
+}
+
TAG* swf_Concatenate (TAG*list1,TAG*list2)
{
TAG*tag=0,*lasttag=0;
void swf_Optimize(SWF*swf)
{
const int hash_size = 131072;
- char* dontremap = malloc(sizeof(char)*65536);
- U16* remap = malloc(sizeof(U16)*65536);
- TAG* id2tag = malloc(sizeof(TAG*)*65536);
- TAG** hashmap = malloc(sizeof(TAG*)*hash_size);
+ char* dontremap = rfx_calloc(sizeof(char)*65536);
+ U16* remap = rfx_alloc(sizeof(U16)*65536);
+ TAG* id2tag = rfx_calloc(sizeof(TAG*)*65536);
+ TAG** hashmap = rfx_calloc(sizeof(TAG*)*hash_size);
TAG* tag;
- memset(dontremap, 0, sizeof(char)*65536);
- memset(hashmap, 0, sizeof(TAG*)*hash_size);
- memset(id2tag, 0, sizeof(TAG*)*65536);
int t;
for(t=0;t<65536;t++) {
remap[t] = t;
if(doremap)
{
int num = swf_GetNumUsedIDs(tag);
- int*positions = malloc(sizeof(int)*num);
+ int*positions = rfx_alloc(sizeof(int)*num);
int t;
swf_GetUsedIDs(tag, positions);
for(t=0;t<num;t++) {
id = remap[id];
PUT16(&tag->data[positions[t]], id);
}
- free(positions);
+ rfx_free(positions);
tag = tag->next;
}
tag = next;
}
- free(dontremap);
- free(remap);
- free(id2tag);
- free(hashmap);
+ rfx_free(dontremap);
+ rfx_free(remap);
+ rfx_free(id2tag);
+ rfx_free(hashmap);
}
#include "./bitio.h"
#include "./MD5.h"
+// memory allocation
+
+void* rfx_alloc(int size)
+{
+ void*ptr;
+ if(size == 0) {
+ *(int*)0 = 0xdead;
+ fprintf(stderr, "Warning: Zero alloc\n");
+ return 0;
+ }
+
+ ptr = malloc(size);
+ if(!ptr) {
+ fprintf(stderr, "FATAL: Out of memory\n");
+ /* TODO: we should send a signal, so that the debugger kicks in */
+ exit(1);
+ }
+ return ptr;
+}
+void* rfx_realloc(void*data, int size)
+{
+ void*ptr;
+ if(size == 0) {
+ *(int*)0 = 0xdead;
+ fprintf(stderr, "Warning: Zero realloc\n");
+ rfx_free(data);
+ return 0;
+ }
+ if(!data) {
+ ptr = malloc(size);
+ } else {
+ ptr = realloc(data, size);
+ }
+
+ if(!ptr) {
+ fprintf(stderr, "FATAL: Out of memory\n");
+ /* TODO: we should send a signal, so that the debugger kicks in */
+ exit(1);
+ }
+ return ptr;
+}
+void* rfx_calloc(int size)
+{
+ void*ptr;
+ if(size == 0) {
+ *(int*)0 = 0xdead;
+ fprintf(stderr, "Warning: Zero alloc\n");
+ return 0;
+ }
+#ifdef HAVE_CALLOC
+ ptr = calloc(size);
+#else
+ ptr = malloc(size);
+#endif
+ if(!ptr) {
+ fprintf(stderr, "FATAL: Out of memory\n");
+ /* TODO: we should send a signal, so that the debugger kicks in */
+ exit(1);
+ }
+#ifndef HAVE_CALLOC
+ memset(ptr, 0, size);
+#endif
+ return ptr;
+}
+
+void rfx_free(void*ptr)
+{
+ if(!ptr)
+ return;
+ free(ptr);
+}
+
// internal constants
#define MALLOC_SIZE 128
#define MEMSIZE(l) (((l/MALLOC_SIZE)+1)*MALLOC_SIZE)
-
// inline wrapper functions
TAG * swf_NextTag(TAG * t) { return t->next; }
swf_ResetWriteBits(t);
if (newlen>t->memsize)
{ U32 newmem = MEMSIZE(newlen);
- U8 * newdata = (U8*)((t->data)?realloc(t->data,newmem):malloc(newmem));
- if (!newdata)
- {
- #ifdef DEBUG_RFXSWF
- fprintf(stderr,"Fatal Error: malloc()/realloc() failed (1). (%d bytes)\n", newmem);
- *(int*)0=0;
- #endif
- return 0;
- }
+ U8 * newdata = (U8*)(rfx_realloc(t->data,newmem));
t->memsize = newmem;
t->data = newdata;
}
return 0;
}
n = x-(md5string1+3);
- salt = (char*)malloc(n+1);
+ salt = (char*)rfx_alloc(n+1);
memcpy(salt, md5string1+3, n);
salt[n] = 0;
md5string2 = crypt_md5(password, salt);
- free(salt);
+ rfx_free(salt);
if(strcmp(md5string1, md5string2) != 0)
return 0;
return 1;
TAG * swf_InsertTag(TAG * after,U16 id)
{ TAG * t;
- t = (TAG *)malloc(sizeof(TAG));
- if (t)
- { memset(t,0x00,sizeof(TAG));
- t->id = id;
-
- if (after)
- {
- t->prev = after;
- t->next = after->next;
- after->next = t;
- if (t->next) t->next->prev = t;
- }
+ t = (TAG *)rfx_calloc(sizeof(TAG));
+ t->id = id;
+
+ if (after)
+ {
+ t->prev = after;
+ t->next = after->next;
+ after->next = t;
+ if (t->next) t->next->prev = t;
}
return t;
}
TAG * swf_InsertTagBefore(SWF* swf, TAG * before,U16 id)
{ TAG * t;
- t = (TAG *)malloc(sizeof(TAG));
- if (t)
- { memset(t,0x00,sizeof(TAG));
- t->id = id;
-
- if (before)
- {
- t->next = before;
- t->prev = before->prev;
- before->prev = t;
- if (t->prev) t->prev->next = t;
- }
+ t = (TAG *)rfx_calloc(sizeof(TAG));
+ t->id = id;
+
+ if (before)
+ {
+ t->next = before;
+ t->prev = before->prev;
+ before->prev = t;
+ if (t->prev) t->prev->next = t;
}
if(swf && swf->firstTag == before) {
swf->firstTag = t;
void swf_ClearTag(TAG * t)
{
- if (t->data) free(t->data);
+ if (t->data) rfx_free(t->data);
t->data = 0;
t->pos = 0;
t->len = 0;
tag->id = id;
}
+TAG* swf_CopyTag(TAG*tag, TAG*to_copy)
+{
+ tag = swf_InsertTag(tag, to_copy->id);
+ swf_SetBlock(tag, to_copy->data, to_copy->len);
+ return tag;
+}
+
int swf_DeleteTag(TAG * t)
{ if (!t) return -1;
if (t->prev) t->prev->next = t->next;
if (t->next) t->next->prev = t->prev;
- if (t->data) free(t->data);
- free(t);
+ if (t->data) rfx_free(t->data);
+ rfx_free(t);
return 0;
}
if (id==ST_DEFINESPRITE) len = 2*sizeof(U16);
// Sprite handling fix: Flatten sprite tree
- t = (TAG *)malloc(sizeof(TAG));
-
- if (!t)
- {
- #ifdef DEBUG_RFXSWF
- fprintf(stderr,"Fatal Error: malloc()/realloc() failed (2). (%d bytes)\n", sizeof(TAG));
- #endif
- return NULL;
- }
-
- memset(t,0x00,sizeof(TAG));
+ t = (TAG *)rfx_calloc(sizeof(TAG));
t->len = len;
t->id = id;
if (t->len)
- { t->data = (U8*)malloc(t->len);
- if (!t->data)
- {
- #ifdef DEBUG_RFXSWF
- fprintf(stderr,"Fatal Error: malloc()/realloc() failed (3). (%d bytes)\n", t->len);
- #endif
- return NULL;
- }
+ { t->data = (U8*)rfx_alloc(t->len);
t->memsize = t->len;
if (reader->read(reader, t->data, t->len) != t->len) return NULL;
}
it->len = len;
it->id = id;
if (it->len)
- { it->data = (U8*)malloc(it->len);
+ { it->data = (U8*)rfx_alloc(it->len);
it->memsize = it->len;
swf_GetBlock(t, it->data, it->len);
}
break;
}
- free(t->data); t->data = 0;
+ rfx_free(t->data); t->data = 0;
t->memsize = t->len = t->pos = 0;
swf_SetU16(t, spriteid);
t->pos = 0;
id = swf_GetU16(t);
- free(t->data);
+ rfx_free(t->data);
t->len = t->pos = t->memsize = 0;
t->data = 0;
while (t)
{ TAG * tnew = t->next;
- if (t->data) free(t->data);
- free(t);
+ if (t->data) rfx_free(t->data);
+ rfx_free(t);
t = tnew;
}
swf->firstTag = 0;