X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=dpvsimpledecode.c;h=3f6567bd3bd29d2991dc93857820e287628b61ae;hb=f170ee3a587ffab1f06680de213b033838cb0b8a;hp=6544ac7a4ae55a83f09e58e8abd84fee87ae59c6;hpb=f9d8bc7ea04ff91fcbd90fe50a299b37724b349b;p=xonotic%2Fdarkplaces.git diff --git a/dpvsimpledecode.c b/dpvsimpledecode.c index 6544ac7a..3f6567bd 100644 --- a/dpvsimpledecode.c +++ b/dpvsimpledecode.c @@ -38,9 +38,9 @@ hz_bitstream_read_t *hz_bitstream_read_open(char *filename) { qfile_t *file; hz_bitstream_read_t *stream; - if ((file = FS_Open (filename, "rb", false, false))) + if ((file = FS_OpenVirtualFile(filename, false))) { - stream = (hz_bitstream_read_t *)malloc(sizeof(hz_bitstream_read_t)); + stream = (hz_bitstream_read_t *)Z_Malloc(sizeof(hz_bitstream_read_t)); memset(stream, 0, sizeof(*stream)); stream->file = file; return stream; @@ -54,14 +54,14 @@ void hz_bitstream_read_close(hz_bitstream_read_t *stream) if (stream) { FS_Close(stream->file); - free(stream); + Z_Free(stream); } } hz_bitstream_readblocks_t *hz_bitstream_read_blocks_new(void) { hz_bitstream_readblocks_t *blocks; - blocks = (hz_bitstream_readblocks_t *)malloc(sizeof(hz_bitstream_readblocks_t)); + blocks = (hz_bitstream_readblocks_t *)Z_Malloc(sizeof(hz_bitstream_readblocks_t)); if (blocks == NULL) return NULL; memset(blocks, 0, sizeof(hz_bitstream_readblocks_t)); @@ -76,9 +76,9 @@ void hz_bitstream_read_blocks_free(hz_bitstream_readblocks_t *blocks) for (b = blocks->blocks;b;b = n) { n = b->next; - free(b); + Z_Free(b); } - free(blocks); + Z_Free(blocks); } void hz_bitstream_read_flushbits(hz_bitstream_readblocks_t *blocks) @@ -98,7 +98,7 @@ int hz_bitstream_read_blocks_read(hz_bitstream_readblocks_t *blocks, hz_bitstrea { if (b == NULL) { - b = (hz_bitstream_readblock_t *)malloc(sizeof(hz_bitstream_readblock_t)); + b = (hz_bitstream_readblock_t *)Z_Malloc(sizeof(hz_bitstream_readblock_t)); if (b == NULL) return HZREADERROR_MALLOCFAILED; b->next = NULL; @@ -279,7 +279,6 @@ static int dpvsimpledecode_setpixelformat(dpvsimpledecodestream_t *s, unsigned i default: s->error = DPVSIMPLEDECODEERROR_UNSUPPORTEDBPP; return s->error; - break; } for (Rshift = 0;!(Rmask & 1);Rshift++, Rmask >>= 1); for (Gshift = 0;!(Gmask & 1);Gshift++, Gmask >>= 1); @@ -333,30 +332,6 @@ static int dpvsimpledecode_setpixelformat(dpvsimpledecodestream_t *s, unsigned i // opening and closing streams -static void StripExtension(char *in, char *out) -{ - char *dot, *c; - dot = NULL; - for (c = in;*c;c++) - { - if (*c == ':' || *c == '\\' || *c == '/') - dot = NULL; - if (*c == '.') - dot = c; - } - if (dot == NULL) - { - // nothing to remove - strcpy(out, in); - return; - } - else - { - memcpy(out, in, dot - in); - out[dot - in] = 0; - } -} - // opens a stream void *dpvsimpledecode_open(char *filename, char **errorstring) { @@ -392,19 +367,22 @@ void *dpvsimpledecode_open(char *filename, char **errorstring) s->videopixels = (unsigned int *)Z_Malloc(s->info_imagewidth * s->info_imageheight * sizeof(*s->videopixels)); if (s->videopixels != NULL) { - wavename = (char *)Z_Malloc(strlen(filename) + 10); + size_t namelen; + + namelen = strlen(filename) + 10; + wavename = (char *)Z_Malloc(namelen); if (wavename) { sfx_t* sfx; - StripExtension(filename, wavename); - strcat(wavename, ".wav"); + FS_StripExtension(filename, wavename, namelen); + strlcat(wavename, ".wav", namelen); sfx = S_PrecacheSound (wavename, false, false); if (sfx != NULL) s->sndchan = S_StartSound (-1, 0, sfx, vec3_origin, 1.0f, 0); else s->sndchan = -1; - free(wavename); + Z_Free(wavename); } // all is well... s->videoframenum = -10000; @@ -429,7 +407,7 @@ void *dpvsimpledecode_open(char *filename, char **errorstring) } else if (errorstring != NULL) *errorstring = "unable to open file"; - free(s); + Z_Free(s); } else if (errorstring != NULL) *errorstring = "unable to allocate memory for stream info structure"; @@ -443,14 +421,14 @@ void dpvsimpledecode_close(void *stream) if (s == NULL) return; if (s->videopixels) - free(s->videopixels); + Z_Free(s->videopixels); if (s->sndchan != -1) - S_StopChannel (s->sndchan); + S_StopChannel (s->sndchan, true); if (s->framedatablocks) hz_bitstream_read_blocks_free(s->framedatablocks); if (s->bitstream) hz_bitstream_read_close(s->bitstream); - free(s); + Z_Free(s); } // utilitarian functions