From 9cda41d51a50a319676d24ba85dc5f39747ba356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Thu, 13 Dec 2007 17:31:53 +0100 Subject: Free the temporary variables that are allocated, avoid memory leaks. (transplanted from c994a2508893efc4c85f5b49600b7dceec5c890e) --HG-- extra : transplant_source : %C9%94%A2P%88%93%EF%C4%C8_%5BI%60%0B%7D%CE%EC%5C%89%0E --- src/demuxers/demux_matroska.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_matroska.c b/src/demuxers/demux_matroska.c index 0169651a0..4f3476049 100644 --- a/src/demuxers/demux_matroska.c +++ b/src/demuxers/demux_matroska.c @@ -1181,8 +1181,10 @@ static int parse_track_entry(demux_matroska_t *this, matroska_track_t *track) { case MATROSKA_ID_TR_CODECID: { char *codec_id = malloc (elem.len + 1); lprintf("CodecID\n"); - if (!ebml_read_ascii(ebml, &elem, codec_id)) + if (!ebml_read_ascii(ebml, &elem, codec_id)) { + free(codec_id); return 0; + } codec_id[elem.len] = '\0'; track->codec_id = codec_id; } @@ -1191,8 +1193,10 @@ static int parse_track_entry(demux_matroska_t *this, matroska_track_t *track) { case MATROSKA_ID_TR_CODECPRIVATE: { char *codec_private = malloc (elem.len); lprintf("CodecPrivate\n"); - if (!ebml_read_binary(ebml, &elem, codec_private)) + if (!ebml_read_binary(ebml, &elem, codec_private)) { + free(codec_private); return 0; + } track->codec_private = codec_private; track->codec_private_len = elem.len; } @@ -1201,8 +1205,10 @@ static int parse_track_entry(demux_matroska_t *this, matroska_track_t *track) { case MATROSKA_ID_TR_LANGUAGE: { char *language = malloc (elem.len + 1); lprintf("Language\n"); - if (!ebml_read_ascii(ebml, &elem, language)) + if (!ebml_read_ascii(ebml, &elem, language)) { + free(language); return 0; + } language[elem.len] = '\0'; track->language = language; } -- cgit v1.2.3 From 04b9c745d4e4c379724df14a422e35ad81c7bce6 Mon Sep 17 00:00:00 2001 From: Matthias Kretz Date: Fri, 14 Dec 2007 20:00:52 +0100 Subject: Fixed a crash that happened when a video output was closed img->stream->video_fifo can be 0 --- src/xine-engine/video_out.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/xine-engine/video_out.c b/src/xine-engine/video_out.c index b961c6060..a5fd544d0 100644 --- a/src/xine-engine/video_out.c +++ b/src/xine-engine/video_out.c @@ -950,6 +950,7 @@ static vo_frame_t *get_next_frame (vos_t *this, int64_t cur_vpts, if (!img->stream || _x_stream_info_get(img->stream, XINE_STREAM_INFO_VIDEO_HAS_STILL) || + !img->stream->video_fifo || img->stream->video_fifo->size(img->stream->video_fifo) < 10) { lprintf ("possible still frame\n"); -- cgit v1.2.3 From 64a216c54142bde7188b690776c0a5decc0cef94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Thu, 13 Dec 2007 19:29:35 +0100 Subject: If the number of channels is not in the known cases, return a failure. (transplanted from f3d84191da5d930ac90193bbdc0ca5d7c43b8302) --HG-- extra : transplant_source : D%837c_%7D%89%F0%E3%2B%7C%96%85IM9%250D%ED --- src/libfaad/xine_faad_decoder.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/libfaad/xine_faad_decoder.c b/src/libfaad/xine_faad_decoder.c index 11a5c5798..934140a32 100644 --- a/src/libfaad/xine_faad_decoder.c +++ b/src/libfaad/xine_faad_decoder.c @@ -194,6 +194,8 @@ static int faad_open_output( faad_decoder_t *this ) { case 2: this->ao_cap_mode=AO_CAP_MODE_STEREO; break; + default: + return 0; } this->output_open = (this->stream->audio_out->open) (this->stream->audio_out, -- cgit v1.2.3 From d1d18588d3bc91f72f6e9534d1f90b8aac7c118f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Thu, 13 Dec 2007 19:38:53 +0100 Subject: Set stream information only when reading a streaminfo FLAC block. (transplanted from 6d9f36be48839984c3888f3d803319942c4d76e6) --HG-- extra : transplant_source : E%81r%E5-%5B%C2%21%15h%E3_%CB%23%25%9B%01l%03Y --- src/demuxers/demux_ogg.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_ogg.c b/src/demuxers/demux_ogg.c index 4eacf7070..9ed39f12d 100644 --- a/src/demuxers/demux_ogg.c +++ b/src/demuxers/demux_ogg.c @@ -1221,16 +1221,17 @@ static void decode_flac_header (demux_ogg_t *this, const int stream_num, ogg_pac case FLAC_BLOCKTYPE_STREAMINFO: _x_assert(header.length == FLAC_STREAMINFO_SIZE); _x_parse_flac_streaminfo_block(&op->packet[17], &streaminfo); + + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE, streaminfo.samplerate); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_CHANNELS, streaminfo.channels); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITS, streaminfo.bits_per_sample); + break; } this->si[stream_num]->buf_types = BUF_AUDIO_FLAC +this->num_audio_streams++; - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE, streaminfo.samplerate); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_CHANNELS, streaminfo.channels); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITS, streaminfo.bits_per_sample); - this->si[stream_num]->factor = 90000; buf = this->audio_fifo->buffer_pool_alloc(this->audio_fifo); -- cgit v1.2.3 From 6bbfd480d0d173887305db527b641f832b6c4310 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Fri, 14 Dec 2007 21:44:43 +0000 Subject: Convert XML to UTF-8 for parsing if a BOM is detected. --- src/xine-utils/xmllexer.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'src') diff --git a/src/xine-utils/xmllexer.c b/src/xine-utils/xmllexer.c index 8879f7d0c..75362e10d 100644 --- a/src/xine-utils/xmllexer.c +++ b/src/xine-utils/xmllexer.c @@ -40,6 +40,8 @@ #include #endif +#include "bswap.h" + /* private constants*/ #define NORMAL 0 /* normal lex mode */ #define DATA 1 /* data lex mode */ @@ -50,10 +52,70 @@ static int lexbuf_size = 0; static int lexbuf_pos = 0; static int lex_mode = NORMAL; static int in_comment = 0; +static char *lex_malloc = NULL; + +enum utf { UTF32BE, UTF32LE, UTF16BE, UTF16LE }; + +static void lex_convert (const char * buf, int size, enum utf utf) +{ + char *utf8 = malloc (size * (utf >= UTF16BE ? 3 : 6) + 1); + char *bp = utf8; + while (size > 0) + { + uint32_t c = 0; + switch (utf) + { + case UTF32BE: c = _X_BE_32 (buf); buf += 4; break; + case UTF32LE: c = _X_LE_32 (buf); buf += 4; break; + case UTF16BE: c = _X_BE_16 (buf); buf += 2; break; + case UTF16LE: c = _X_LE_16 (buf); buf += 2; break; + } + if (!c) + break; /* embed a NUL, get a truncated string */ + if (c < 128) + *bp++ = c; + else + { + int count = (c >= 0x04000000) ? 5 : + (c >= 0x00200000) ? 4 : + (c >= 0x00010000) ? 3 : + (c >= 0x00000800) ? 2 : 1; + *bp = (char)(0x1F80 >> count); + count *= 6; + *bp++ |= c >> count; + while ((count -= 6) >= 0) + *bp++ = 128 | ((c >> count) & 0x3F); + } + } + *bp = 0; + lexbuf_size = bp - utf8; + lexbuf = lex_malloc = realloc (utf8, lexbuf_size + 1); +} void lexer_init(const char * buf, int size) { + static const char boms[] = { 0xFF, 0xFE, 0, 0, 0xFE, 0xFF }, + bom_utf8[] = { 0xEF, 0xBB, 0xBF }; + + free (lex_malloc); + lex_malloc = NULL; + lexbuf = buf; lexbuf_size = size; + + if (size >= 4 && !memcmp (buf, boms + 2, 4)) + lex_convert (buf + 4, size - 4, UTF32BE); + else if (size >= 4 && !memcmp (buf, boms, 4)) + lex_convert (buf + 4, size - 4, UTF32LE); + else if (size >= 3 && !memcmp (buf, bom_utf8, 4)) + { + lexbuf += 3; + lexbuf_size -= 3; + } + else if (size >= 2 && !memcmp (buf, boms + 4, 2)) + lex_convert (buf + 2, size - 2, UTF16BE); + else if (size >= 2 && !memcmp (buf, boms, 2)) + lex_convert (buf + 2, size - 2, UTF16LE); + lexbuf_pos = 0; lex_mode = NORMAL; in_comment = 0; -- cgit v1.2.3 From 8cba2f6983736209def1c838dd53aa5e8c19ec4a Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sat, 15 Dec 2007 04:22:04 +0000 Subject: Remove a stray semicolon. --- src/xine-engine/load_plugins.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c index 2d2f3f3e4..a03ea6d17 100644 --- a/src/xine-engine/load_plugins.c +++ b/src/xine-engine/load_plugins.c @@ -2533,7 +2533,7 @@ char *xine_get_mime_types (xine_t *self) { cls = (demux_class_t *)node->plugin_class; - if ( cls->mimetypes ); + if ( cls->mimetypes ) len += strlen(cls->mimetypes); } } -- cgit v1.2.3 From dca7aad8c609e205dd4bb793573fec966fdbfc31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Sat, 15 Dec 2007 09:24:49 +0100 Subject: Fix wrongly-named function. Thanks to Petri Hintukainen for reporting. --- src/combined/flac_decoder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/combined/flac_decoder.c b/src/combined/flac_decoder.c index cb7db0364..9ec024d71 100644 --- a/src/combined/flac_decoder.c +++ b/src/combined/flac_decoder.c @@ -388,7 +388,7 @@ init_plugin (xine_t *xine, void *data) { this->decoder_class.open_plugin = open_plugin; this->decoder_class.identifier = "flacdec"; this->decoder_class.description = N_("flac audio decoder plugin"); - this->decoder_class.dispose = default_audio_decoder_dispose; + this->decoder_class.dispose = default_audio_decoder_class_dispose; return this; -- cgit v1.2.3 From b6df7d39efa2fffefe0685d271e28038c484512a Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 16 Dec 2007 14:20:34 +0000 Subject: Drop the priority of the aud demuxer. It has been observed claiming files which should be claimed by other demuxers such as playlist or real. --- src/demuxers/group_audio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/demuxers/group_audio.c b/src/demuxers/group_audio.c index 78bf4012b..d3832c36d 100644 --- a/src/demuxers/group_audio.c +++ b/src/demuxers/group_audio.c @@ -42,7 +42,7 @@ static const demuxer_info_t demux_info_ac3 = { }; static const demuxer_info_t demux_info_aud = { - 10 /* priority */ + -2 /* priority */ }; static const demuxer_info_t demux_info_aiff = { -- cgit v1.2.3 From fdf9cb58ce03df58c25dc9dd0c9f939abd343183 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 16 Dec 2007 14:23:25 +0000 Subject: Tell the Real demuxer about http references. --- src/demuxers/demux_real.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_real.c b/src/demuxers/demux_real.c index 11c5069eb..938e1ca24 100644 --- a/src/demuxers/demux_real.c +++ b/src/demuxers/demux_real.c @@ -820,8 +820,8 @@ static int demux_real_parse_references( demux_real_t *this) { if( !strncmp(&buf[i],"-->",3) ) comment = 0; - if( (!strncmp(&buf[i],"pnm://",6) || !strncmp(&buf[i],"rtsp://",7)) && - !comment ) { + if( (!strncmp(&buf[i],"pnm://",6) || !strncmp(&buf[i],"rtsp://",7) || + !strncmp(&buf[i],"http://",7)) && !comment ) { for(j=i; buf[j] && buf[j] != '"' && !isspace(buf[j]); j++ ) ; buf[j]='\0'; @@ -1532,7 +1532,8 @@ static int real_check_stream_type(uint8_t *buf, int len) return 1; buf[len] = '\0'; - if( strstr(buf,"pnm://") || strstr(buf,"rtsp://") || strstr(buf,"") ) + if( strstr(buf,"pnm://") || strstr(buf,"rtsp://") || strstr(buf,"") || + strstr(buf,"http://") ) return 2; return 0; -- cgit v1.2.3 From a7e8065a32e0151ef995d696881d4d2ecf27fd33 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Mon, 17 Dec 2007 16:55:35 +0000 Subject: Fix an off-by-one error concerning UTF-8-encoded BOMs. --- src/xine-utils/xmllexer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/xine-utils/xmllexer.c b/src/xine-utils/xmllexer.c index 75362e10d..047dbb1a6 100644 --- a/src/xine-utils/xmllexer.c +++ b/src/xine-utils/xmllexer.c @@ -106,7 +106,7 @@ void lexer_init(const char * buf, int size) { lex_convert (buf + 4, size - 4, UTF32BE); else if (size >= 4 && !memcmp (buf, boms, 4)) lex_convert (buf + 4, size - 4, UTF32LE); - else if (size >= 3 && !memcmp (buf, bom_utf8, 4)) + else if (size >= 3 && !memcmp (buf, bom_utf8, 3)) { lexbuf += 3; lexbuf_size -= 3; -- cgit v1.2.3 From 8a3706ba2814436bba1e164bf29cd02c6125083b Mon Sep 17 00:00:00 2001 From: Matthias Kretz Date: Mon, 17 Dec 2007 22:00:34 +0100 Subject: add video/flv and application/x-flash-video MIME aliases as used by shared-mime --- src/demuxers/demux_flv.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/demuxers/demux_flv.c b/src/demuxers/demux_flv.c index 39c34d91e..5669a4b2e 100644 --- a/src/demuxers/demux_flv.c +++ b/src/demuxers/demux_flv.c @@ -892,7 +892,9 @@ static const char *get_extensions (demux_class_t *this_gen) { } static const char *get_mimetypes (demux_class_t *this_gen) { - return "video/x-flv: flv: Flash video;"; + return "video/x-flv: flv: Flash video;" + "video/flv: flv: Flash video;" + "application/x-flash-video: flv: Flash video;" } static void class_dispose (demux_class_t *this_gen) { -- cgit v1.2.3 From eacdc6fc2e37f80cc03b022988112741979724e6 Mon Sep 17 00:00:00 2001 From: Matthias Kretz Date: Mon, 17 Dec 2007 22:16:52 +0100 Subject: compile --- src/demuxers/demux_flv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/demuxers/demux_flv.c b/src/demuxers/demux_flv.c index 5669a4b2e..bdb33d21d 100644 --- a/src/demuxers/demux_flv.c +++ b/src/demuxers/demux_flv.c @@ -894,7 +894,7 @@ static const char *get_extensions (demux_class_t *this_gen) { static const char *get_mimetypes (demux_class_t *this_gen) { return "video/x-flv: flv: Flash video;" "video/flv: flv: Flash video;" - "application/x-flash-video: flv: Flash video;" + "application/x-flash-video: flv: Flash video;"; } static void class_dispose (demux_class_t *this_gen) { -- cgit v1.2.3 From b864b902b6ba16c7bcee14fcb7f71cac640a23c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 16:49:04 +0100 Subject: Fix demuxing of VCDs, DVDs and PVR streams. --- src/demuxers/demux_mpeg_block.c | 36 ++---------------------------------- 1 file changed, 2 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_mpeg_block.c b/src/demuxers/demux_mpeg_block.c index 2f7c48d44..91b69328c 100644 --- a/src/demuxers/demux_mpeg_block.c +++ b/src/demuxers/demux_mpeg_block.c @@ -1452,39 +1452,7 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str } break; - case METHOD_BY_MRL: { - char *ending; - - const char *const mrl = input->get_mrl (input); - - if(!strncmp(mrl, "vcd:", 4)) { - this->blocksize = 2324; - demux_mpeg_block_accept_input (this, input); - } else if(!strncmp(mrl, "dvd:", 4) || !strncmp(mrl, "pvr:", 4)) { - this->blocksize = 2048; - demux_mpeg_block_accept_input (this, input); - } else { - ending = strrchr(mrl, '.'); - - if (!ending) { - free (this->scratch_base); - free (this); - return NULL; - } - if ( (!strncasecmp (ending, ".vob", 4)) || - (!strncmp((ending + 3), "mpeg2", 5)) || - (!strncmp((ending + 3), "mpeg1", 5)) ) { - this->blocksize = 2048; - demux_mpeg_block_accept_input(this, input); - } else { - free (this->scratch_base); - free (this); - return NULL; - } - } - } - break; - + case METHOD_BY_MRL: case METHOD_EXPLICIT: { this->blocksize = input->get_blocksize(input); @@ -1525,7 +1493,7 @@ static void *init_plugin (xine_t *xine, void *data) { this->demux_class.description = N_("DVD/VOB demux plugin"); this->demux_class.identifier = "MPEG_BLOCK"; this->demux_class.mimetypes = NULL; - this->demux_class.extensions = "vob"; + this->demux_class.extensions = "vob vcd:/ dvd:/ pvr:/"; this->demux_class.dispose = default_demux_class_dispose; return this; -- cgit v1.2.3 From 3840424ca421b186ae4aa24281536a86f850d744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 17:09:44 +0100 Subject: Use xine_xmalloc to allocate the plugin structures, so that they get zeroed out. --- src/post/planar/boxblur.c | 2 +- src/post/planar/denoise3d.c | 2 +- src/post/planar/eq.c | 2 +- src/post/planar/eq2.c | 2 +- src/post/planar/expand.c | 2 +- src/post/planar/fill.c | 2 +- src/post/planar/invert.c | 2 +- src/post/planar/noise.c | 2 +- src/post/planar/pp.c | 2 +- src/post/planar/unsharp.c | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/post/planar/boxblur.c b/src/post/planar/boxblur.c index 66af08e5c..924e58bf0 100644 --- a/src/post/planar/boxblur.c +++ b/src/post/planar/boxblur.c @@ -134,7 +134,7 @@ static int boxblur_draw(vo_frame_t *frame, xine_stream_t *stream); void *boxblur_init_plugin(xine_t *xine, void *data) { - post_class_t *class = (post_class_t *)malloc(sizeof(post_class_t)); + post_class_t *class = (post_class_t *)xine_xmalloc(sizeof(post_class_t)); if (!class) return NULL; diff --git a/src/post/planar/denoise3d.c b/src/post/planar/denoise3d.c index 647ab075e..a59de5479 100644 --- a/src/post/planar/denoise3d.c +++ b/src/post/planar/denoise3d.c @@ -174,7 +174,7 @@ static int denoise3d_draw(vo_frame_t *frame, xine_stream_t *stream); void *denoise3d_init_plugin(xine_t *xine, void *data) { - post_class_t *class = (post_class_t *)malloc(sizeof(post_class_t)); + post_class_t *class = (post_class_t *)xine_xmalloc(sizeof(post_class_t)); if (!class) return NULL; diff --git a/src/post/planar/eq.c b/src/post/planar/eq.c index cb28cafa2..2cf6464aa 100644 --- a/src/post/planar/eq.c +++ b/src/post/planar/eq.c @@ -226,7 +226,7 @@ static int eq_draw(vo_frame_t *frame, xine_stream_t *stream); void *eq_init_plugin(xine_t *xine, void *data) { - post_class_t *class = (post_class_t *)malloc(sizeof(post_class_t)); + post_class_t *class = (post_class_t *)xine_xmalloc(sizeof(post_class_t)); if (!class) return NULL; diff --git a/src/post/planar/eq2.c b/src/post/planar/eq2.c index 277aca00e..0d16cc32a 100644 --- a/src/post/planar/eq2.c +++ b/src/post/planar/eq2.c @@ -407,7 +407,7 @@ static int eq2_draw(vo_frame_t *frame, xine_stream_t *stream); void *eq2_init_plugin(xine_t *xine, void *data) { - post_class_t *class = (post_class_t *)malloc(sizeof(post_class_t)); + post_class_t *class = (post_class_t *)xine_xmalloc(sizeof(post_class_t)); if (!class) return NULL; diff --git a/src/post/planar/expand.c b/src/post/planar/expand.c index df5fa874e..f2f9fc748 100644 --- a/src/post/planar/expand.c +++ b/src/post/planar/expand.c @@ -128,7 +128,7 @@ static int32_t expand_overlay_add_event(video_overlay_manager_t *this_gen void *expand_init_plugin(xine_t *xine, void *data) { - post_class_t *class = (post_class_t *)malloc(sizeof(post_class_t)); + post_class_t *class = (post_class_t *)xine_xmalloc(sizeof(post_class_t)); if (!class) return NULL; diff --git a/src/post/planar/fill.c b/src/post/planar/fill.c index 14bd55102..51272600d 100644 --- a/src/post/planar/fill.c +++ b/src/post/planar/fill.c @@ -46,7 +46,7 @@ static int fill_draw(vo_frame_t *frame, xine_stream_t *stream); void *fill_init_plugin(xine_t *xine, void *data) { - post_class_t *class = (post_class_t *)malloc(sizeof(post_class_t)); + post_class_t *class = (post_class_t *)xine_xmalloc(sizeof(post_class_t)); if (!class) return NULL; diff --git a/src/post/planar/invert.c b/src/post/planar/invert.c index dd1d7ac07..98e0b84f9 100644 --- a/src/post/planar/invert.c +++ b/src/post/planar/invert.c @@ -47,7 +47,7 @@ static int invert_draw(vo_frame_t *frame, xine_stream_t *stream); void *invert_init_plugin(xine_t *xine, void *data) { - post_class_t *class = (post_class_t *)malloc(sizeof(post_class_t)); + post_class_t *class = (post_class_t *)xine_xmalloc(sizeof(post_class_t)); if (!class) return NULL; diff --git a/src/post/planar/noise.c b/src/post/planar/noise.c index 53dc3065d..5a2a2ac0a 100644 --- a/src/post/planar/noise.c +++ b/src/post/planar/noise.c @@ -443,7 +443,7 @@ static int noise_draw(vo_frame_t *frame, xine_stream_t *stream); void *noise_init_plugin(xine_t *xine, void *data) { - post_class_t *class = (post_class_t *)malloc(sizeof(post_class_t)); + post_class_t *class = (post_class_t *)xine_xmalloc(sizeof(post_class_t)); if (!class) return NULL; diff --git a/src/post/planar/pp.c b/src/post/planar/pp.c index 22a25fc90..c7cbbbceb 100644 --- a/src/post/planar/pp.c +++ b/src/post/planar/pp.c @@ -149,7 +149,7 @@ static int pp_draw(vo_frame_t *frame, xine_stream_t *stream); void *pp_init_plugin(xine_t *xine, void *data) { - post_class_t *class = (post_class_t *)malloc(sizeof(post_class_t)); + post_class_t *class = (post_class_t *)xine_xmalloc(sizeof(post_class_t)); if (!class) return NULL; diff --git a/src/post/planar/unsharp.c b/src/post/planar/unsharp.c index b850b05b7..6b9b5b9fa 100644 --- a/src/post/planar/unsharp.c +++ b/src/post/planar/unsharp.c @@ -267,7 +267,7 @@ static int unsharp_draw(vo_frame_t *frame, xine_stream_t *stream); void *unsharp_init_plugin(xine_t *xine, void *data) { - post_class_t *class = (post_class_t *)malloc(sizeof(post_class_t)); + post_class_t *class = (post_class_t *)xine_xmalloc(sizeof(post_class_t)); if (!class) return NULL; -- cgit v1.2.3 From 92325b7f17bc96da46dda3445c9f9facec17a485 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Tue, 18 Dec 2007 16:57:13 +0000 Subject: Fix MRL protocol matching (for demuxer lookup). --- src/xine-engine/demux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/xine-engine/demux.c b/src/xine-engine/demux.c index 6f9f6381d..5010c60eb 100644 --- a/src/xine-engine/demux.c +++ b/src/xine-engine/demux.c @@ -464,7 +464,7 @@ int _x_demux_check_extension (const char *mrl, const char *extensions){ while ( ( e = xine_strsep(&ext_work, " ")) != NULL ) { if ( strstr(e, ":/") ) { - if ( strcasecmp (mrl, e) == 0 ) { + if ( strncasecmp (mrl, e, strlen (e)) == 0 ) { found = 1; break; } -- cgit v1.2.3 From ac983bbadbd6b518539390fa3608eaf102e6a2b1 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Tue, 18 Dec 2007 17:01:33 +0000 Subject: Allow vdr/netvdr MRLs to work without requiring #demux:mpeg_pes. (This doesn't work with detection by content.) --- src/demuxers/demux_mpeg_pes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/demuxers/demux_mpeg_pes.c b/src/demuxers/demux_mpeg_pes.c index 1ec5b8365..d47c1ed01 100644 --- a/src/demuxers/demux_mpeg_pes.c +++ b/src/demuxers/demux_mpeg_pes.c @@ -1754,7 +1754,7 @@ static void *init_plugin (xine_t *xine, void *data) { this->demux_class.description = N_("mpeg pes demux plugin"); this->demux_class.identifier = "MPEG_PES"; this->demux_class.mimetypes = NULL; - this->demux_class.extensions = "pes"; + this->demux_class.extensions = "pes vdr:/ netvdr:/"; this->demux_class.dispose = default_demux_class_dispose; return this; -- cgit v1.2.3 From c71eb9175c5e7622b362be50daa8e6663804e5dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 19:36:16 +0100 Subject: Remove more class_dispose functions, and replace with default_post_class_dispose. --- src/post/mosaico/mosaico.c | 9 +-------- src/post/mosaico/switch.c | 9 +-------- src/post/planar/boxblur.c | 9 +-------- src/post/planar/denoise3d.c | 9 +-------- src/post/planar/eq.c | 9 +-------- src/post/planar/eq2.c | 9 +-------- src/post/planar/expand.c | 9 +-------- src/post/planar/fill.c | 8 +------- src/post/planar/invert.c | 9 +-------- src/post/planar/noise.c | 9 +-------- src/post/planar/pp.c | 9 +-------- src/post/planar/unsharp.c | 8 +------- 12 files changed, 12 insertions(+), 94 deletions(-) (limited to 'src') diff --git a/src/post/mosaico/mosaico.c b/src/post/mosaico/mosaico.c index ccfd641aa..5683002f6 100644 --- a/src/post/mosaico/mosaico.c +++ b/src/post/mosaico/mosaico.c @@ -96,7 +96,6 @@ struct post_mosaico_s { static post_plugin_t *mosaico_open_plugin(post_class_t *class_gen, int inputs, xine_audio_port_t **audio_target, xine_video_port_t **video_target); -static void mosaico_class_dispose(post_class_t *class_gen); /* plugin instance functions */ static void mosaico_dispose(post_plugin_t *this_gen); @@ -128,7 +127,7 @@ static void *mosaico_init_plugin(xine_t *xine, void *data) this->class.open_plugin = mosaico_open_plugin; this->class.identifier = "mosaico"; this->class.description = N_("Mosaico is a picture in picture (pip) post plugin"); - this->class.dispose = mosaico_class_dispose; + this->class.dispose = default_post_class_dispose; this->xine = xine; return &this->class; @@ -200,12 +199,6 @@ static post_plugin_t *mosaico_open_plugin(post_class_t *class_gen, int inputs, return &this->post; } -static void mosaico_class_dispose(post_class_t *class_gen) -{ - free(class_gen); -} - - static void mosaico_dispose(post_plugin_t *this_gen) { post_mosaico_t *this = (post_mosaico_t *)this_gen; diff --git a/src/post/mosaico/switch.c b/src/post/mosaico/switch.c index 19e563680..23469e566 100644 --- a/src/post/mosaico/switch.c +++ b/src/post/mosaico/switch.c @@ -82,7 +82,6 @@ struct post_switch_s { static post_plugin_t *switch_open_plugin(post_class_t *class_gen, int inputs, xine_audio_port_t **audio_target, xine_video_port_t **video_target); -static void switch_class_dispose(post_class_t *class_gen); /* plugin instance functions */ static void switch_dispose(post_plugin_t *this_gen); @@ -107,7 +106,7 @@ static void *switch_init_plugin(xine_t *xine, void *data) this->class.open_plugin = switch_open_plugin; this->class.identifier = "switch"; this->class.description = N_("Switch is a post plugin able to switch at any time between different streams"); - this->class.dispose = switch_class_dispose; + this->class.dispose = default_post_class_dispose; this->xine = xine; return &this->class; @@ -166,12 +165,6 @@ static post_plugin_t *switch_open_plugin(post_class_t *class_gen, int inputs, return &this->post; } -static void switch_class_dispose(post_class_t *class_gen) -{ - free(class_gen); -} - - static void switch_dispose(post_plugin_t *this_gen) { post_switch_t *this = (post_switch_t *)this_gen; diff --git a/src/post/planar/boxblur.c b/src/post/planar/boxblur.c index 924e58bf0..225e75954 100644 --- a/src/post/planar/boxblur.c +++ b/src/post/planar/boxblur.c @@ -120,7 +120,6 @@ static xine_post_api_t post_api = { static post_plugin_t *boxblur_open_plugin(post_class_t *class_gen, int inputs, xine_audio_port_t **audio_target, xine_video_port_t **video_target); -static void boxblur_class_dispose(post_class_t *class_gen); /* plugin instance functions */ static void boxblur_dispose(post_plugin_t *this_gen); @@ -142,7 +141,7 @@ void *boxblur_init_plugin(xine_t *xine, void *data) class->open_plugin = boxblur_open_plugin; class->identifier = "boxblur"; class->description = N_("box blur filter from mplayer"); - class->dispose = boxblur_class_dispose; + class->dispose = default_post_class_dispose; return class; } @@ -192,12 +191,6 @@ static post_plugin_t *boxblur_open_plugin(post_class_t *class_gen, int inputs, return &this->post; } -static void boxblur_class_dispose(post_class_t *class_gen) -{ - free(class_gen); -} - - static void boxblur_dispose(post_plugin_t *this_gen) { post_plugin_boxblur_t *this = (post_plugin_boxblur_t *)this_gen; diff --git a/src/post/planar/denoise3d.c b/src/post/planar/denoise3d.c index a59de5479..fb7021ece 100644 --- a/src/post/planar/denoise3d.c +++ b/src/post/planar/denoise3d.c @@ -157,7 +157,6 @@ static xine_post_api_t post_api = { static post_plugin_t *denoise3d_open_plugin(post_class_t *class_gen, int inputs, xine_audio_port_t **audio_target, xine_video_port_t **video_target); -static void denoise3d_class_dispose(post_class_t *class_gen); /* plugin instance functions */ static void denoise3d_dispose(post_plugin_t *this_gen); @@ -182,7 +181,7 @@ void *denoise3d_init_plugin(xine_t *xine, void *data) class->open_plugin = denoise3d_open_plugin; class->identifier = "denoise3d"; class->description = N_("3D Denoiser (variable lowpass filter)"); - class->dispose = denoise3d_class_dispose; + class->dispose = default_post_class_dispose; return class; } @@ -235,12 +234,6 @@ static post_plugin_t *denoise3d_open_plugin(post_class_t *class_gen, int inputs, return &this->post; } -static void denoise3d_class_dispose(post_class_t *class_gen) -{ - free(class_gen); -} - - static void denoise3d_dispose(post_plugin_t *this_gen) { post_plugin_denoise3d_t *this = (post_plugin_denoise3d_t *)this_gen; diff --git a/src/post/planar/eq.c b/src/post/planar/eq.c index 2cf6464aa..03f647d68 100644 --- a/src/post/planar/eq.c +++ b/src/post/planar/eq.c @@ -208,7 +208,6 @@ static xine_post_api_t post_api = { static post_plugin_t *eq_open_plugin(post_class_t *class_gen, int inputs, xine_audio_port_t **audio_target, xine_video_port_t **video_target); -static void eq_class_dispose(post_class_t *class_gen); /* plugin instance functions */ static void eq_dispose(post_plugin_t *this_gen); @@ -234,7 +233,7 @@ void *eq_init_plugin(xine_t *xine, void *data) class->open_plugin = eq_open_plugin; class->identifier = "eq"; class->description = N_("soft video equalizer"); - class->dispose = eq_class_dispose; + class->dispose = default_post_class_dispose; return class; } @@ -290,12 +289,6 @@ static post_plugin_t *eq_open_plugin(post_class_t *class_gen, int inputs, return &this->post; } -static void eq_class_dispose(post_class_t *class_gen) -{ - free(class_gen); -} - - static void eq_dispose(post_plugin_t *this_gen) { post_plugin_eq_t *this = (post_plugin_eq_t *)this_gen; diff --git a/src/post/planar/eq2.c b/src/post/planar/eq2.c index 0d16cc32a..ceb9f9024 100644 --- a/src/post/planar/eq2.c +++ b/src/post/planar/eq2.c @@ -389,7 +389,6 @@ static xine_post_api_t post_api = { static post_plugin_t *eq2_open_plugin(post_class_t *class_gen, int inputs, xine_audio_port_t **audio_target, xine_video_port_t **video_target); -static void eq2_class_dispose(post_class_t *class_gen); /* plugin instance functions */ static void eq2_dispose(post_plugin_t *this_gen); @@ -415,7 +414,7 @@ void *eq2_init_plugin(xine_t *xine, void *data) class->open_plugin = eq2_open_plugin; class->identifier = "eq2"; class->description = N_("Software video equalizer"); - class->dispose = eq2_class_dispose; + class->dispose = default_post_class_dispose; return class; } @@ -487,12 +486,6 @@ static post_plugin_t *eq2_open_plugin(post_class_t *class_gen, int inputs, return &this->post; } -static void eq2_class_dispose(post_class_t *class_gen) -{ - free(class_gen); -} - - static void eq2_dispose(post_plugin_t *this_gen) { post_plugin_eq2_t *this = (post_plugin_eq2_t *)this_gen; diff --git a/src/post/planar/expand.c b/src/post/planar/expand.c index f2f9fc748..db62a5512 100644 --- a/src/post/planar/expand.c +++ b/src/post/planar/expand.c @@ -100,7 +100,6 @@ typedef struct post_expand_s { static post_plugin_t *expand_open_plugin(post_class_t *class_gen, int inputs, xine_audio_port_t **audio_target, xine_video_port_t **video_target); -static void expand_class_dispose(post_class_t *class_gen); /* plugin instance functions */ static void expand_dispose(post_plugin_t *this_gen); @@ -136,7 +135,7 @@ void *expand_init_plugin(xine_t *xine, void *data) class->open_plugin = expand_open_plugin; class->identifier = "expand"; class->description = N_("add black borders to top and bottom of video to expand it to 4:3 aspect ratio"); - class->dispose = expand_class_dispose; + class->dispose = default_post_class_dispose; return class; } @@ -189,12 +188,6 @@ static post_plugin_t *expand_open_plugin(post_class_t *class_gen, int inputs, return &this->post; } -static void expand_class_dispose(post_class_t *class_gen) -{ - free(class_gen); -} - - static void expand_dispose(post_plugin_t *this_gen) { post_expand_t *this = (post_expand_t *)this_gen; diff --git a/src/post/planar/fill.c b/src/post/planar/fill.c index 51272600d..62fdc1381 100644 --- a/src/post/planar/fill.c +++ b/src/post/planar/fill.c @@ -32,7 +32,6 @@ void *fill_init_plugin(xine_t *xine, void *); static post_plugin_t *fill_open_plugin(post_class_t *class_gen, int inputs, xine_audio_port_t **audio_target, xine_video_port_t **video_target); -static void fill_class_dispose(post_class_t *class_gen); /* plugin instance functions */ static void fill_dispose(post_plugin_t *this_gen); @@ -54,7 +53,7 @@ void *fill_init_plugin(xine_t *xine, void *data) class->open_plugin = fill_open_plugin; class->identifier = "fill"; class->description = N_("crops left and right of video to fill 4:3 aspect ratio"); - class->dispose = fill_class_dispose; + class->dispose = default_post_class_dispose; return class; } @@ -90,11 +89,6 @@ static post_plugin_t *fill_open_plugin(post_class_t *class_gen, int inputs, return this; } -static void fill_class_dispose(post_class_t *class_gen) -{ - free(class_gen); -} - static void fill_dispose(post_plugin_t *this) { if (_x_post_dispose(this)) diff --git a/src/post/planar/invert.c b/src/post/planar/invert.c index 98e0b84f9..b5ee1e3f2 100644 --- a/src/post/planar/invert.c +++ b/src/post/planar/invert.c @@ -33,7 +33,6 @@ void *invert_init_plugin(xine_t *xine, void *); static post_plugin_t *invert_open_plugin(post_class_t *class_gen, int inputs, xine_audio_port_t **audio_target, xine_video_port_t **video_target); -static void invert_class_dispose(post_class_t *class_gen); /* plugin instance functions */ static void invert_dispose(post_plugin_t *this_gen); @@ -55,7 +54,7 @@ void *invert_init_plugin(xine_t *xine, void *data) class->open_plugin = invert_open_plugin; class->identifier = "invert"; class->description = N_("inverts the colours of every video frame"); - class->dispose = invert_class_dispose; + class->dispose = default_post_class_dispose; return class; } @@ -89,12 +88,6 @@ static post_plugin_t *invert_open_plugin(post_class_t *class_gen, int inputs, return this; } -static void invert_class_dispose(post_class_t *class_gen) -{ - free(class_gen); -} - - static void invert_dispose(post_plugin_t *this) { if (_x_post_dispose(this)) diff --git a/src/post/planar/noise.c b/src/post/planar/noise.c index 5a2a2ac0a..afe05b180 100644 --- a/src/post/planar/noise.c +++ b/src/post/planar/noise.c @@ -429,7 +429,6 @@ static xine_post_api_t post_api = { static post_plugin_t *noise_open_plugin(post_class_t *class_gen, int inputs, xine_audio_port_t **audio_target, xine_video_port_t **video_target); -static void noise_class_dispose(post_class_t *class_gen); /* plugin instance functions */ static void noise_dispose(post_plugin_t *this_gen); @@ -451,7 +450,7 @@ void *noise_init_plugin(xine_t *xine, void *data) class->open_plugin = noise_open_plugin; class->identifier = "noise"; class->description = N_("Adds noise"); - class->dispose = noise_class_dispose; + class->dispose = default_post_class_dispose; #ifdef ARCH_X86 if (xine_mm_accel() & MM_ACCEL_X86_MMX) { @@ -513,12 +512,6 @@ static post_plugin_t *noise_open_plugin(post_class_t *class_gen, int inputs, return &this->post; } -static void noise_class_dispose(post_class_t *class_gen) -{ - free(class_gen); -} - - static void noise_dispose(post_plugin_t *this_gen) { post_plugin_noise_t *this = (post_plugin_noise_t *)this_gen; diff --git a/src/post/planar/pp.c b/src/post/planar/pp.c index c7cbbbceb..3f9c0d745 100644 --- a/src/post/planar/pp.c +++ b/src/post/planar/pp.c @@ -135,7 +135,6 @@ static xine_post_api_t post_api = { static post_plugin_t *pp_open_plugin(post_class_t *class_gen, int inputs, xine_audio_port_t **audio_target, xine_video_port_t **video_target); -static void pp_class_dispose(post_class_t *class_gen); /* plugin instance functions */ static void pp_dispose(post_plugin_t *this_gen); @@ -157,7 +156,7 @@ void *pp_init_plugin(xine_t *xine, void *data) class->open_plugin = pp_open_plugin; class->identifier = "pp"; class->description = N_("plugin for ffmpeg libpostprocess"); - class->dispose = pp_class_dispose; + class->dispose = default_post_class_dispose; return class; } @@ -219,12 +218,6 @@ static post_plugin_t *pp_open_plugin(post_class_t *class_gen, int inputs, return &this->post; } -static void pp_class_dispose(post_class_t *class_gen) -{ - free(class_gen); -} - - static void pp_dispose(post_plugin_t *this_gen) { post_plugin_pp_t *this = (post_plugin_pp_t *)this_gen; diff --git a/src/post/planar/unsharp.c b/src/post/planar/unsharp.c index 6b9b5b9fa..ff86f21bc 100644 --- a/src/post/planar/unsharp.c +++ b/src/post/planar/unsharp.c @@ -253,7 +253,6 @@ static xine_post_api_t post_api = { static post_plugin_t *unsharp_open_plugin(post_class_t *class_gen, int inputs, xine_audio_port_t **audio_target, xine_video_port_t **video_target); -static void unsharp_class_dispose(post_class_t *class_gen); /* plugin instance functions */ static void unsharp_dispose(post_plugin_t *this_gen); @@ -275,7 +274,7 @@ void *unsharp_init_plugin(xine_t *xine, void *data) class->open_plugin = unsharp_open_plugin; class->identifier = "unsharp"; class->description = N_("unsharp mask & gaussian blur"); - class->dispose = unsharp_class_dispose; + class->dispose = default_post_class_dispose; return class; } @@ -330,11 +329,6 @@ static post_plugin_t *unsharp_open_plugin(post_class_t *class_gen, int inputs, return &this->post; } -static void unsharp_class_dispose(post_class_t *class_gen) -{ - free(class_gen); -} - static void unsharp_free_SC(post_plugin_unsharp_t *this) { int i; -- cgit v1.2.3 From 899f195796be5218dd49ae7af1f50132cddc46ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:02:57 +0100 Subject: Use default_demux_plugin_dispose as dispose function. --- src/combined/wavpack_demuxer.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'src') diff --git a/src/combined/wavpack_demuxer.c b/src/combined/wavpack_demuxer.c index ac5c66a8d..310f4cecb 100644 --- a/src/combined/wavpack_demuxer.c +++ b/src/combined/wavpack_demuxer.c @@ -302,12 +302,6 @@ static int demux_wv_seek (demux_plugin_t *this_gen, return this->status; } -static void demux_wv_dispose (demux_plugin_t *const this_gen) { - demux_wv_t *const this = (demux_wv_t *) this_gen; - - free(this); -} - static int demux_wv_get_status (demux_plugin_t *const this_gen) { const demux_wv_t *const this = (const demux_wv_t *) this_gen; @@ -339,7 +333,7 @@ static demux_plugin_t *open_plugin (demux_class_t *const class_gen, this->demux_plugin.send_headers = demux_wv_send_headers; this->demux_plugin.send_chunk = demux_wv_send_chunk; this->demux_plugin.seek = demux_wv_seek; - this->demux_plugin.dispose = demux_wv_dispose; + this->demux_plugin.dispose = default_demux_plugin_dispose; this->demux_plugin.get_status = demux_wv_get_status; this->demux_plugin.get_stream_length = demux_wv_get_stream_length; this->demux_plugin.get_capabilities = demux_wv_get_capabilities; -- cgit v1.2.3 From 456f5a5a8bc07ba783cddbaca3716add185a5e7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:04:19 +0100 Subject: Use xine_xmalloc rather than setting everything at zero by hand. --- src/demuxers/ebml.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'src') diff --git a/src/demuxers/ebml.c b/src/demuxers/ebml.c index 218046cf5..532f41ebf 100644 --- a/src/demuxers/ebml.c +++ b/src/demuxers/ebml.c @@ -41,20 +41,10 @@ ebml_parser_t *new_ebml_parser (xine_t *xine, input_plugin_t *input) { ebml_parser_t *ebml; - ebml = malloc(sizeof(ebml_parser_t)); + ebml = xine_xmalloc(sizeof(ebml_parser_t)); ebml->xine = xine; ebml->input = input; - ebml->version = 0; - ebml->read_version = 0; - ebml->max_id_len = 0; - ebml->max_size_len = 0; - ebml->doctype = NULL; - ebml->doctype_version = 0; - ebml->doctype_read_version = 0; - - ebml->level = 0; - return ebml; } -- cgit v1.2.3 From 6bcba9598c0e23ab4475efc4e5f227f94614d445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:06:46 +0100 Subject: Simplify code by returning immediately in case of error. --- src/demuxers/ebml.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/demuxers/ebml.c b/src/demuxers/ebml.c index 532f41ebf..23a27f674 100644 --- a/src/demuxers/ebml.c +++ b/src/demuxers/ebml.c @@ -315,25 +315,25 @@ int ebml_read_date (ebml_parser_t *ebml, ebml_elem_t *elem, int64_t *date) { int ebml_read_master (ebml_parser_t *ebml, ebml_elem_t *elem) { ebml_elem_t *top_elem; - if (ebml->level >= 0) { - top_elem = &ebml->elem_stack[ebml->level]; - top_elem->start = elem->start; - top_elem->len = elem->len; - top_elem->id = elem->id; - - ebml->level++; - lprintf("id: 0x%x, len: %" PRIu64 ", level: %d\n", elem->id, elem->len, ebml->level); - if (ebml->level >= EBML_STACK_SIZE) { - xprintf(ebml->xine, XINE_VERBOSITY_LOG, - "ebml: max level exceeded\n"); - return 0; - } - return 1; - } else { + if (ebml->level < 0) { xprintf(ebml->xine, XINE_VERBOSITY_LOG, "ebml: invalid current level\n"); return 0; } + + top_elem = &ebml->elem_stack[ebml->level]; + top_elem->start = elem->start; + top_elem->len = elem->len; + top_elem->id = elem->id; + + ebml->level++; + lprintf("id: 0x%x, len: %" PRIu64 ", level: %d\n", elem->id, elem->len, ebml->level); + if (ebml->level >= EBML_STACK_SIZE) { + xprintf(ebml->xine, XINE_VERBOSITY_LOG, + "ebml: max level exceeded\n"); + return 0; + } + return 1; } int ebml_read_binary(ebml_parser_t *ebml, ebml_elem_t *elem, void *binary) { -- cgit v1.2.3 From d3c734f256cf1f78042e322f2bdfab7dfe8f5967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:07:22 +0100 Subject: Simplify code. --- src/demuxers/ebml.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src') diff --git a/src/demuxers/ebml.c b/src/demuxers/ebml.c index 23a27f674..d5f7bb9b5 100644 --- a/src/demuxers/ebml.c +++ b/src/demuxers/ebml.c @@ -337,10 +337,7 @@ int ebml_read_master (ebml_parser_t *ebml, ebml_elem_t *elem) { } int ebml_read_binary(ebml_parser_t *ebml, ebml_elem_t *elem, void *binary) { - if (!ebml_read_elem_data(ebml, binary, elem->len)) - return 0; - - return 1; + return !!ebml_read_elem_data(ebml, binary, elem->len); } int ebml_check_header(ebml_parser_t *ebml) { -- cgit v1.2.3 From 485a597194d373aa233017be47c8cfa1b92748d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:15:26 +0100 Subject: Don't test for the pointer before freeing. --- src/demuxers/demux_qt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index b46cbc593..f9b14f9e8 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -651,8 +651,7 @@ static void free_qt_info(qt_info *info) { for (j = 0; j < info->traks[i].stsd_atoms_count; j++) { if (info->traks[i].type == MEDIA_AUDIO) { free(info->traks[i].stsd_atoms[j].audio.properties_atom); - if (info->traks[i].stsd_atoms[j].audio.wave) - free(info->traks[i].stsd_atoms[j].audio.wave); + free(info->traks[i].stsd_atoms[j].audio.wave); } else if (info->traks[i].type == MEDIA_VIDEO) free(info->traks[i].stsd_atoms[j].video.properties_atom); } -- cgit v1.2.3 From 38b08ea4a1a3130eb05139b7121ece98a4c3d232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:20:04 +0100 Subject: Alloc preview only when needed; use zeroed allocation rather than memset. --- src/demuxers/demux_qt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index f9b14f9e8..e2db5855a 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -686,13 +686,12 @@ static int is_qt_file(input_plugin_t *qt_file) { int64_t moov_atom_size = -1; int i; unsigned char atom_preamble[ATOM_PREAMBLE_SIZE]; - unsigned char preview[MAX_PREVIEW_SIZE]; int len; /* if the input is non-seekable, be much more stringent about qualifying * a QT file: In this case, the moov must be the first atom in the file */ if ((qt_file->get_capabilities(qt_file) & INPUT_CAP_SEEKABLE) == 0) { - memset (&preview, 0, MAX_PREVIEW_SIZE); + unsigned char preview[MAX_PREVIEW_SIZE] = { 0, }; len = qt_file->get_optional_data(qt_file, preview, INPUT_OPTIONAL_DATA_PREVIEW); if (_X_BE_32(&preview[4]) == MOOV_ATOM) return 1; -- cgit v1.2.3 From ccb545fca89e270271b9ace18289db433e2e1d09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:20:52 +0100 Subject: Don't use an if when returning a comparison. --- src/demuxers/demux_qt.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index e2db5855a..402b7be99 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -706,10 +706,7 @@ static int is_qt_file(input_plugin_t *qt_file) { i = moov_atom_size + ATOM_PREAMBLE_SIZE; if (i >= MAX_PREVIEW_SIZE) return 0; - if (_X_BE_32(&preview[i - 4]) == MOOV_ATOM) - return 1; - else - return 0; + return _X_BE_32(&preview[i - 4]) == MOOV_ATOM; } else return 0; } -- cgit v1.2.3 From 8d1a32f1880988b27a1da296d0670f24e89954cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:21:41 +0100 Subject: Return right away if the atom is not an FTYP. --- src/demuxers/demux_qt.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index 402b7be99..3e5faf390 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -696,19 +696,19 @@ static int is_qt_file(input_plugin_t *qt_file) { if (_X_BE_32(&preview[4]) == MOOV_ATOM) return 1; else { - if (_X_BE_32(&preview[4]) == FTYP_ATOM) { - /* show some lenience if the first atom is 'ftyp'; the second atom - * could be 'moov' */ - moov_atom_size = _X_BE_32(&preview[0]); - /* compute the size of the current atom plus the preamble of the - * next atom; if the size is within the range on the preview buffer - * then the next atom's preamble is in the preview buffer */ - i = moov_atom_size + ATOM_PREAMBLE_SIZE; - if (i >= MAX_PREVIEW_SIZE) - return 0; - return _X_BE_32(&preview[i - 4]) == MOOV_ATOM; - } else - return 0; + if (_X_BE_32(&preview[4]) != FTYP_ATOM) + return 0; + + /* show some lenience if the first atom is 'ftyp'; the second atom + * could be 'moov' */ + moov_atom_size = _X_BE_32(&preview[0]); + /* compute the size of the current atom plus the preamble of the + * next atom; if the size is within the range on the preview buffer + * then the next atom's preamble is in the preview buffer */ + i = moov_atom_size + ATOM_PREAMBLE_SIZE; + if (i >= MAX_PREVIEW_SIZE) + return 0; + return _X_BE_32(&preview[i - 4]) == MOOV_ATOM; } } -- cgit v1.2.3 From 0deccd94faa1565e28bebefafed7fe32b369d2b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:25:38 +0100 Subject: Simplify code, set ftyp_atom_size at once. --- src/demuxers/demux_qt.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index 3e5faf390..2fb79fe2a 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -700,15 +700,14 @@ static int is_qt_file(input_plugin_t *qt_file) { return 0; /* show some lenience if the first atom is 'ftyp'; the second atom - * could be 'moov' */ - moov_atom_size = _X_BE_32(&preview[0]); - /* compute the size of the current atom plus the preamble of the + * could be 'moov' + * compute the size of the current atom plus the preamble of the * next atom; if the size is within the range on the preview buffer * then the next atom's preamble is in the preview buffer */ - i = moov_atom_size + ATOM_PREAMBLE_SIZE; - if (i >= MAX_PREVIEW_SIZE) + uint64_t ftyp_atom_size = _X_BE_32(&preview[0]) + ATOM_PREAMBLE_SIZE; + if (ftyp_atom_size >= MAX_PREVIEW_SIZE) return 0; - return _X_BE_32(&preview[i - 4]) == MOOV_ATOM; + return _X_BE_32(&preview[ftyp_atom_size - 4]) == MOOV_ATOM; } } -- cgit v1.2.3 From 1a366138f0b39cfa1d8586d54f5dfce296a001d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:28:55 +0100 Subject: Allocate atom_preamble only when it's actually going to be used. --- src/demuxers/demux_qt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index 2fb79fe2a..3cd573530 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -685,7 +685,6 @@ static int is_qt_file(input_plugin_t *qt_file) { off_t moov_atom_offset = -1; int64_t moov_atom_size = -1; int i; - unsigned char atom_preamble[ATOM_PREAMBLE_SIZE]; int len; /* if the input is non-seekable, be much more stringent about qualifying @@ -715,6 +714,7 @@ static int is_qt_file(input_plugin_t *qt_file) { if (moov_atom_offset == -1) { return 0; } else { + unsigned char atom_preamble[ATOM_PREAMBLE_SIZE]; /* check that the next atom in the chunk contains alphanumeric * characters in the atom type field; if not, disqualify the file * as a QT file */ -- cgit v1.2.3 From d3298c9017077d3ea3ea91110dcac349d58448a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:34:40 +0100 Subject: Replace seven calls to parse_data_atom with a single call, and then set the value on the proper structure. This way, parse_data_atom is inlined by GCC. --- src/demuxers/demux_qt.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index 3cd573530..4c9399608 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -801,31 +801,33 @@ static void parse_meta_atom(qt_info *info, unsigned char *meta_atom) { const uint8_t *const sub_atom = &meta_atom[j]; const qt_atom sub_atom_code = _X_BE_32(&sub_atom[4]); const uint32_t sub_atom_size = _X_BE_32(&sub_atom[0]); + char *const data_atom = parse_data_atom(&sub_atom[8]); switch(sub_atom_code) { case ART_ATOM: - info->artist = parse_data_atom(&sub_atom[8]); + info->artist = data_atom; break; case NAM_ATOM: - info->name = parse_data_atom(&sub_atom[8]); + info->name = data_atom; break; case ALB_ATOM: - info->album = parse_data_atom(&sub_atom[8]); + info->album = data_atom; break; case GEN_ATOM: - info->genre = parse_data_atom(&sub_atom[8]); + info->genre = data_atom; break; case CMT_ATOM: - info->comment = parse_data_atom(&sub_atom[8]); + info->comment = data_atom; break; case WRT_ATOM: - info->composer = parse_data_atom(&sub_atom[8]); + info->composer = data_atom; break; case DAY_ATOM: - info->year = parse_data_atom(&sub_atom[8]); + info->year = data_atom; break; default: debug_meta_load("unknown atom %08x in ilst\n", sub_atom_code); + free(data_atom); } j += sub_atom_size; -- cgit v1.2.3 From c57b06b240fd159758f93206726556f31e12a8d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:36:37 +0100 Subject: Declare color_* variables only when actually used. --- src/demuxers/demux_qt.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index 4c9399608..ae657fb66 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -1004,18 +1004,17 @@ static qt_error parse_trak_atom (qt_trak *trak, const uint32_t current_stsd_atom_size = _X_BE_32(&trak_atom[atom_pos - 4]); - /* for palette traversal */ - int color_depth; - int color_flag; - int color_start; - int color_count; - int color_end; - int color_index; - int color_dec; - int color_greyscale; - const unsigned char *color_table; - if (trak->type == MEDIA_VIDEO) { + /* for palette traversal */ + int color_depth; + int color_flag; + int color_start; + int color_count; + int color_end; + int color_index; + int color_dec; + int color_greyscale; + const unsigned char *color_table; trak->stsd_atoms[k].video.media_id = k + 1; trak->stsd_atoms[k].video.properties_offset = properties_offset; -- cgit v1.2.3 From 80826e77cf419d92711e175dcc9e40edaecfd7f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:43:36 +0100 Subject: Use calloc() when the allocated size would be counted by multiplying the size of an item for the number of items. Also don't memset calloc()ed areas to zero. --- src/demuxers/demux_qt.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index ae657fb66..3fb60c1a8 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -1459,8 +1459,7 @@ static qt_error parse_trak_atom (qt_trak *trak, debug_atom_load(" qt stco atom (32-bit chunk offset atom): %d chunk offsets\n", trak->chunk_offset_count); - trak->chunk_offset_table = (int64_t *)malloc( - trak->chunk_offset_count * sizeof(int64_t)); + trak->chunk_offset_table = calloc(trak->chunk_offset_count, sizeof(int64_t)); if (!trak->chunk_offset_table) { last_error = QT_NO_MEMORY; goto free_trak; @@ -1487,8 +1486,7 @@ static qt_error parse_trak_atom (qt_trak *trak, debug_atom_load(" qt co64 atom (64-bit chunk offset atom): %d chunk offsets\n", trak->chunk_offset_count); - trak->chunk_offset_table = (int64_t *)malloc( - trak->chunk_offset_count * sizeof(int64_t)); + trak->chunk_offset_table = calloc(trak->chunk_offset_count, sizeof(int64_t)); if (!trak->chunk_offset_table) { last_error = QT_NO_MEMORY; goto free_trak; @@ -1518,8 +1516,7 @@ static qt_error parse_trak_atom (qt_trak *trak, debug_atom_load(" qt stsc atom (sample-to-chunk atom): %d entries\n", trak->sample_to_chunk_count); - trak->sample_to_chunk_table = (sample_to_chunk_table_t *)malloc( - trak->sample_to_chunk_count * sizeof(sample_to_chunk_table_t)); + trak->sample_to_chunk_table = calloc(trak->sample_to_chunk_count, sizeof(sample_to_chunk_table_t)); if (!trak->sample_to_chunk_table) { last_error = QT_NO_MEMORY; goto free_trak; @@ -1553,8 +1550,7 @@ static qt_error parse_trak_atom (qt_trak *trak, debug_atom_load(" qt stts atom (time-to-sample atom): %d entries\n", trak->time_to_sample_count); - trak->time_to_sample_table = (time_to_sample_table_t *)malloc( - (trak->time_to_sample_count+1) * sizeof(time_to_sample_table_t)); + trak->time_to_sample_table = calloc(trak->time_to_sample_count+1, sizeof(time_to_sample_table_t)); if (!trak->time_to_sample_table) { last_error = QT_NO_MEMORY; goto free_trak; @@ -1747,8 +1743,7 @@ static qt_error build_frame_table(qt_trak *trak, /* in this case, the total number of frames is equal to the number of * entries in the sample size table */ trak->frame_count = trak->sample_size_count; - trak->frames = (qt_frame *)malloc( - trak->frame_count * sizeof(qt_frame)); + trak->frames = calloc(trak->frame_count, sizeof(qt_frame)); if (!trak->frames) return QT_NO_MEMORY; trak->current_frame = 0; @@ -1760,10 +1755,9 @@ static qt_error build_frame_table(qt_trak *trak, pts_index_countdown = trak->time_to_sample_table[pts_index].count; - media_id_counts = xine_xmalloc(trak->stsd_atoms_count * sizeof(int)); + media_id_counts = xine_xcalloc(trak->stsd_atoms_count, sizeof(int)); if (!media_id_counts) return QT_NO_MEMORY; - memset(media_id_counts, 0, trak->stsd_atoms_count * sizeof(int)); /* iterate through each start chunk in the stsc table */ for (i = 0; i < trak->sample_to_chunk_count; i++) { @@ -1898,8 +1892,7 @@ static qt_error build_frame_table(qt_trak *trak, /* in this case, the total number of frames is equal to the number of * chunks */ trak->frame_count = trak->chunk_offset_count; - trak->frames = (qt_frame *)malloc( - trak->frame_count * sizeof(qt_frame)); + trak->frames = calloc(trak->frame_count, sizeof(qt_frame)); if (!trak->frames) return QT_NO_MEMORY; -- cgit v1.2.3 From 8e9cb121101b1b43f6b52cd01e3e0fb841c538c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:46:23 +0100 Subject: Allocate the preview buffer only when actually needed; use zeroed allocation rather than memset(). --- src/demuxers/demux_qt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index 3fb60c1a8..8fb554de2 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -2134,7 +2134,6 @@ static qt_error open_qt_file(qt_info *info, input_plugin_t *input, unsigned char *moov_atom = NULL; off_t moov_atom_offset = -1; int64_t moov_atom_size = -1; - unsigned char preview[MAX_PREVIEW_SIZE]; /* zlib stuff */ z_stream z_state; @@ -2157,7 +2156,7 @@ static qt_error open_qt_file(qt_info *info, input_plugin_t *input, if ((input->get_capabilities(input) & INPUT_CAP_SEEKABLE)) find_moov_atom(input, &moov_atom_offset, &moov_atom_size); else { - memset (&preview, 0, MAX_PREVIEW_SIZE); + unsigned char preview[MAX_PREVIEW_SIZE] = { 0, }; input->get_optional_data(input, preview, INPUT_OPTIONAL_DATA_PREVIEW); if (_X_BE_32(&preview[4]) != MOOV_ATOM) { /* special case if there is an ftyp atom first */ -- cgit v1.2.3 From c62965b6941f714d69830e3a8fdaf612b14bd543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:50:01 +0100 Subject: Remove superfluous include. --- src/xine-engine/scratch.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/xine-engine/scratch.c b/src/xine-engine/scratch.c index 98fed2cdd..8f9021aa1 100644 --- a/src/xine-engine/scratch.c +++ b/src/xine-engine/scratch.c @@ -26,7 +26,6 @@ #include #include -#include /* For memset */ #define LOG_MODULE "scratch" #define LOG_VERBOSE -- cgit v1.2.3 From be6ed0bd6b920c37a823cd599162900120cd3b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:54:54 +0100 Subject: Remove a memset after xine_xmalloc. --- src/xine-engine/metronom.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/xine-engine/metronom.c b/src/xine-engine/metronom.c index 328d2cb3c..e9bd86836 100644 --- a/src/xine-engine/metronom.c +++ b/src/xine-engine/metronom.c @@ -176,7 +176,6 @@ static scr_plugin_t* unixscr_init () { unixscr_t *this; this = (unixscr_t *) xine_xmalloc(sizeof(unixscr_t)); - memset(this, 0, sizeof(*this)); this->scr.interface_version = 3; this->scr.get_priority = unixscr_get_priority; -- cgit v1.2.3 From d9a190ce3659666d38b99c12ac8564993a5f25e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:57:33 +0100 Subject: Use calloc() when the allocated size would be counted by multiplying the size of an item for the number of items. --- src/input/input_cdda.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/input/input_cdda.c b/src/input/input_cdda.c index df4617e22..8929a8af7 100644 --- a/src/input/input_cdda.c +++ b/src/input/input_cdda.c @@ -422,10 +422,9 @@ static int read_cdrom_toc(int fd, cdrom_toc *toc) { toc->total_tracks = toc->last_track - toc->first_track + 1; /* allocate space for the toc entries */ - toc->toc_entries = - (cdrom_toc_entry *)malloc(toc->total_tracks * sizeof(cdrom_toc_entry)); + toc->toc_entries = calloc(toc->total_tracks, sizeof(cdrom_toc_entry)); if (!toc->toc_entries) { - perror("malloc"); + perror("calloc"); return -1; } @@ -533,10 +532,9 @@ static int read_cdrom_toc(int fd, cdrom_toc *toc) { toc->total_tracks = toc->last_track - toc->first_track + 1; /* allocate space for the toc entries */ - toc->toc_entries = - (cdrom_toc_entry *)malloc(toc->total_tracks * sizeof(cdrom_toc_entry)); + toc->toc_entries = calloc(toc->total_tracks, sizeof(cdrom_toc_entry)); if (!toc->toc_entries) { - perror("malloc"); + perror("calloc"); return -1; } @@ -646,10 +644,9 @@ static int read_cdrom_toc(int fd, cdrom_toc *toc) { toc->total_tracks = toc->last_track - toc->first_track + 1; /* allocate space for the toc entries */ - toc->toc_entries = - (cdrom_toc_entry *)malloc(toc->total_tracks * sizeof(cdrom_toc_entry)); + toc->toc_entries = calloc(toc->total_tracks, sizeof(cdrom_toc_entry)); if (!toc->toc_entries) { - perror("malloc"); + perror("calloc"); return -1; } @@ -839,10 +836,9 @@ static int read_cdrom_toc(cdda_input_plugin_t *this_gen, cdrom_toc *toc) { /* allocate space for the toc entries */ - toc->toc_entries = - (cdrom_toc_entry *)malloc(toc->total_tracks * sizeof(cdrom_toc_entry)); + toc->toc_entries = calloc(toc->total_tracks, sizeof(cdrom_toc_entry)); if (!toc->toc_entries) { - perror("malloc"); + perror("calloc"); return -1; } @@ -1085,10 +1081,9 @@ static int network_read_cdrom_toc(xine_stream_t *stream, int fd, cdrom_toc *toc) toc->total_tracks = toc->last_track - toc->first_track + 1; /* allocate space for the toc entries */ - toc->toc_entries = - (cdrom_toc_entry *)malloc(toc->total_tracks * sizeof(cdrom_toc_entry)); + toc->toc_entries = calloc(toc->total_tracks, sizeof(cdrom_toc_entry)); if (!toc->toc_entries) { - perror("malloc"); + perror("calloc"); return -1; } -- cgit v1.2.3 From 9c866afab8308a58ce03555a61daa4380c09d73a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:59:29 +0100 Subject: Use zeroed allocation instead of memset, and don't zero out a string that is going to be fully sprintf'd. --- src/input/input_cdda.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/input/input_cdda.c b/src/input/input_cdda.c index 8929a8af7..e658e30ca 100644 --- a/src/input/input_cdda.c +++ b/src/input/input_cdda.c @@ -1287,15 +1287,12 @@ static void _cdda_mkdir_safe(xine_t *xine, char *path) { */ static void _cdda_mkdir_recursive_safe(xine_t *xine, char *path) { char *p, *pp; - char buf[XINE_PATH_MAX + XINE_NAME_MAX + 1]; - char buf2[XINE_PATH_MAX + XINE_NAME_MAX + 1]; + char buf[XINE_PATH_MAX + XINE_NAME_MAX + 1] = { 0, }; + char buf2[XINE_PATH_MAX + XINE_NAME_MAX + 1] = { 0, }; if(path == NULL) return; - memset(&buf, 0, sizeof(buf)); - memset(&buf2, 0, sizeof(buf2)); - snprintf(buf, sizeof(buf), "%s", path); pp = buf; while((p = xine_strsep(&pp, "/")) != NULL) { @@ -1438,7 +1435,6 @@ static int _cdda_load_cached_cddb_infos(cdda_input_plugin_t *this) { while((pdir = readdir(dir)) != NULL) { char discid[9]; - memset(&discid, 0, sizeof(discid)); snprintf(discid, sizeof(discid), "%08lx", this->cddb.disc_id); if(!strcasecmp(pdir->d_name, discid)) { -- cgit v1.2.3 From 03829d385e84676debb6f64d6fd79969b3a5b6b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 21:03:26 +0100 Subject: Use asprintf instead of sprintf. --- src/audio_out/audio_alsa_out.c | 2 +- src/audio_out/audio_oss_out.c | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/audio_out/audio_alsa_out.c b/src/audio_out/audio_alsa_out.c index 1a26b01e9..40dc7ffed 100644 --- a/src/audio_out/audio_alsa_out.c +++ b/src/audio_out/audio_alsa_out.c @@ -138,7 +138,7 @@ static int my_snd_mixer_wait(snd_mixer_t *mixer, int timeout) { return count; if ((unsigned int) count > sizeof(spfds) / sizeof(spfds[0])) { - pfds = malloc(count * sizeof(*pfds)); + pfds = calloc(count, sizeof(*pfds)); if (!pfds) return -ENOMEM; diff --git a/src/audio_out/audio_oss_out.c b/src/audio_out/audio_oss_out.c index 5576b1d5f..b22f3344b 100644 --- a/src/audio_out/audio_oss_out.c +++ b/src/audio_out/audio_oss_out.c @@ -1035,15 +1035,12 @@ static ao_driver_t *open_plugin (audio_driver_class_t *class_gen, const void *da if ((parse = strstr(mixer_name, "dsp"))) { parse[0] = '\0'; parse += 3; - this->mixer.name = (char *)malloc(strlen(mixer_name) + sizeof("mixer") + 2); if (devname_val == 0) - sprintf(this->mixer.name, "%smixer%s", mixer_name, parse); - else { - if (mixer_num == -1) - sprintf(this->mixer.name, "%smixer", mixer_name); - else - sprintf(this->mixer.name, "%smixer%d", mixer_name, mixer_num); - } + asprintf(&this->mixer.name, "%smixer%s", mixer_name, parse); + else if (mixer_num == -1) + asprintf(&this->mixer.name, "%smixer", mixer_name); + else + asprintf(&this->mixer.name, "%smixer%d", mixer_name, mixer_num); } else { this->mixer.name = (char *)malloc(1); this->mixer.name[0] = '\0'; -- cgit v1.2.3 From d4bf43b39b37af9ec22a72de2da95c101fc460bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 21:04:55 +0100 Subject: As the error codepath is going to assert out anyway, don't do the extra malloc. --- src/audio_out/audio_oss_out.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src') diff --git a/src/audio_out/audio_oss_out.c b/src/audio_out/audio_oss_out.c index b22f3344b..5b4faada5 100644 --- a/src/audio_out/audio_oss_out.c +++ b/src/audio_out/audio_oss_out.c @@ -1041,11 +1041,8 @@ static ao_driver_t *open_plugin (audio_driver_class_t *class_gen, const void *da asprintf(&this->mixer.name, "%smixer", mixer_name); else asprintf(&this->mixer.name, "%smixer%d", mixer_name, mixer_num); - } else { - this->mixer.name = (char *)malloc(1); - this->mixer.name[0] = '\0'; } - _x_assert(this->mixer.name[0] != '\0'); + _x_assert(this->mixer.name); this->mixer.fd = open(this->mixer.name, O_RDONLY); -- cgit v1.2.3 From c03568412615ffb294650149c5f6de18288f0976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 21:10:55 +0100 Subject: Set the values of buffers in the same if as they are tested. Use calloc(1, ...) rather than using memset right afterward. --- src/demuxers/asfheader.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/demuxers/asfheader.c b/src/demuxers/asfheader.c index 26a61d8fd..35bd187df 100644 --- a/src/demuxers/asfheader.c +++ b/src/demuxers/asfheader.c @@ -130,8 +130,7 @@ static uint8_t *asf_reader_get_bytes(asf_reader_t *reader, size_t size) { if ((reader->size - reader->pos) < size) return NULL; - buffer = malloc(size); - if (!buffer) + if (! (buffer = malloc(size)) ) return NULL; memcpy(buffer, reader->buffer + reader->pos, size); reader->pos += size; @@ -241,8 +240,7 @@ static int asf_header_parse_file_properties(asf_header_t *header, uint8_t *buffe return 0; } - asf_file = malloc(sizeof(asf_file_t)); - if (!asf_file) { + if (! (asf_file = malloc(sizeof(asf_file_t))) ) { lprintf("cannot allocate asf_file_struct\n"); return 0; } @@ -296,8 +294,7 @@ static int asf_header_parse_stream_properties(asf_header_t *header, uint8_t *buf if (buffer_len < 54) goto exit_error; - asf_stream = malloc(sizeof(asf_stream_t)); - if (!asf_stream) + if (! (asf_stream = malloc(sizeof(asf_stream_t))) ) goto exit_error; asf_reader_init(&reader, buffer, buffer_len); @@ -363,8 +360,7 @@ static int asf_header_parse_stream_extended_properties(asf_header_t *header, uin if (buffer_len < 64) return 0; - asf_stream_extension = malloc(sizeof(asf_stream_extension_t)); - if (!asf_stream_extension) + if (! (asf_stream_extension = malloc(sizeof(asf_stream_extension_t))) ) return 0; asf_reader_init(&reader, buffer, buffer_len); @@ -581,10 +577,8 @@ static int asf_header_parse_content_description(asf_header_t *header_pub, uint8_ if (buffer_len < 10) return 0; - content = malloc(sizeof(asf_content_t)); - if (!content) + if (! (content = calloc(1, sizeof(asf_content_t))) ) return 0; - memset(content, 0, sizeof(asf_content_t)); asf_reader_init(&reader, buffer, buffer_len); asf_reader_get_16(&reader, &title_length); @@ -611,10 +605,8 @@ asf_header_t *asf_header_new (uint8_t *buffer, int buffer_len) { uint32_t object_count; uint16_t junk; - asf_header = malloc(sizeof(asf_header_internal_t)); - if (!asf_header) + if (! (asf_header = calloc(1, sizeof(asf_header_internal_t))) ) return NULL; - memset(asf_header, 0, sizeof(asf_header_internal_t)); lprintf("parsing_asf_header\n"); if (buffer_len < 6) { @@ -697,10 +689,8 @@ asf_header_t *asf_header_new (uint8_t *buffer, int buffer_len) { } if (!asf_header->pub.content) { lprintf("no content object present\n"); - asf_header->pub.content = malloc(sizeof(asf_content_t)); - if (!asf_header->pub.content) + if (! (asf_header->pub.content = calloc(1, sizeof(asf_content_t))) ) goto exit_error; - memset(asf_header->pub.content, 0, sizeof(asf_content_t)); } return &asf_header->pub; -- cgit v1.2.3 From de2319031060f7ac4e7e4c169944490e43539777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 21:12:12 +0100 Subject: Check for buffer_len before allocating the buffer, so it hasn't to be freed. --- src/demuxers/asfheader.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/demuxers/asfheader.c b/src/demuxers/asfheader.c index 35bd187df..720bf5423 100644 --- a/src/demuxers/asfheader.c +++ b/src/demuxers/asfheader.c @@ -605,16 +605,15 @@ asf_header_t *asf_header_new (uint8_t *buffer, int buffer_len) { uint32_t object_count; uint16_t junk; - if (! (asf_header = calloc(1, sizeof(asf_header_internal_t))) ) - return NULL; - lprintf("parsing_asf_header\n"); if (buffer_len < 6) { printf("invalid buffer size\n"); - free(asf_header); return NULL; } + if (! (asf_header = calloc(1, sizeof(asf_header_internal_t))) ) + return NULL; + asf_header->iconv_cd = iconv_open ("UTF-8", "UCS-2LE"); if (asf_header->iconv_cd == (iconv_t)-1) { printf("iconv open error\n"); -- cgit v1.2.3 From b3945e2e0132309fd2eaf583e4ad9c0245c7828e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 21:28:51 +0100 Subject: Only open (and close) iconv in asf_header_parse_content_description. This way the iconv descriptor is not left open during the whole ASF demuxing. --- src/demuxers/asfheader.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/demuxers/asfheader.c b/src/demuxers/asfheader.c index 720bf5423..23692574e 100644 --- a/src/demuxers/asfheader.c +++ b/src/demuxers/asfheader.c @@ -63,7 +63,6 @@ struct asf_header_internal_s { /* private part */ int number_count; uint16_t numbers[ASF_MAX_NUM_STREAMS]; - iconv_t iconv_cd; uint8_t *bitrate_pointers[ASF_MAX_NUM_STREAMS]; }; @@ -573,6 +572,7 @@ static int asf_header_parse_content_description(asf_header_t *header_pub, uint8_ asf_reader_t reader; asf_content_t *content; uint16_t title_length, author_length, copyright_length, description_length, rating_length; + iconv_t iconv_cd; if (buffer_len < 10) return 0; @@ -580,6 +580,9 @@ static int asf_header_parse_content_description(asf_header_t *header_pub, uint8_ if (! (content = calloc(1, sizeof(asf_content_t))) ) return 0; + if ( (iconv_cd = iconv_open("UTF-8", "UCS-2LE")) == (iconv_t)-1 ) + return 0; + asf_reader_init(&reader, buffer, buffer_len); asf_reader_get_16(&reader, &title_length); asf_reader_get_16(&reader, &author_length); @@ -587,13 +590,15 @@ static int asf_header_parse_content_description(asf_header_t *header_pub, uint8_ asf_reader_get_16(&reader, &description_length); asf_reader_get_16(&reader, &rating_length); - content->title = asf_reader_get_string(&reader, title_length, header->iconv_cd); - content->author = asf_reader_get_string(&reader, author_length, header->iconv_cd); - content->copyright = asf_reader_get_string(&reader, copyright_length, header->iconv_cd); - content->description = asf_reader_get_string(&reader, description_length, header->iconv_cd); - content->rating = asf_reader_get_string(&reader, rating_length, header->iconv_cd); + content->title = asf_reader_get_string(&reader, title_length, iconv_cd); + content->author = asf_reader_get_string(&reader, author_length, iconv_cd); + content->copyright = asf_reader_get_string(&reader, copyright_length, iconv_cd); + content->description = asf_reader_get_string(&reader, description_length, iconv_cd); + content->rating = asf_reader_get_string(&reader, rating_length, iconv_cd); header->pub.content = content; + + iconv_close(iconv_cd); return 1; } @@ -614,13 +619,6 @@ asf_header_t *asf_header_new (uint8_t *buffer, int buffer_len) { if (! (asf_header = calloc(1, sizeof(asf_header_internal_t))) ) return NULL; - asf_header->iconv_cd = iconv_open ("UTF-8", "UCS-2LE"); - if (asf_header->iconv_cd == (iconv_t)-1) { - printf("iconv open error\n"); - free(asf_header); - return NULL; - } - asf_reader_init(&reader, buffer, buffer_len); asf_reader_get_32(&reader, &object_count); asf_reader_get_16(&reader, &junk); @@ -755,9 +753,6 @@ void asf_header_delete (asf_header_t *header_pub) { asf_header_delete_stream_extended_properties(header->pub.stream_extensions[i]); } - if (header->iconv_cd != (iconv_t)-1) - iconv_close (header->iconv_cd); - free(header); } -- cgit v1.2.3 From 081e91d5a7631867606609fae0cb861abd5586b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 21:31:09 +0100 Subject: Use an automatic array rather than malloc'ing and free'ing it on the function. --- src/demuxers/demux_asf.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_asf.c b/src/demuxers/demux_asf.c index 889299beb..f5091035b 100644 --- a/src/demuxers/demux_asf.c +++ b/src/demuxers/demux_asf.c @@ -612,14 +612,14 @@ static int demux_asf_send_headers_common (demux_asf_t *this) { } static void asf_reorder(demux_asf_t *this, uint8_t *src, int len){ - uint8_t *dst = malloc(len); + uint8_t dst[len]; uint8_t *s2 = src; int i = 0, x, y; while(len-i >= this->reorder_h * this->reorder_w*this->reorder_b){ for(x = 0; x < this->reorder_w; x++) for(y = 0; y < this->reorder_h; y++){ - memcpy(dst + i, s2 + (y * this->reorder_w+x) * this->reorder_b, + memcpy(&dst[i], s2 + (y * this->reorder_w+x) * this->reorder_b, this->reorder_b); i += this->reorder_b; } @@ -627,7 +627,6 @@ static void asf_reorder(demux_asf_t *this, uint8_t *src, int len){ } xine_fast_memcpy(src,dst,i); - free(dst); } /* redefine abs as macro to handle 64-bit diffs. -- cgit v1.2.3 From 0014ed290612dfecaad2b16f030ee8808f60e1b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 21:33:34 +0100 Subject: There's no need to use an if: when block_data is NULL, realloc() acts as malloc(). --- src/demuxers/demux_matroska.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_matroska.c b/src/demuxers/demux_matroska.c index f8166173a..16cf87978 100644 --- a/src/demuxers/demux_matroska.c +++ b/src/demuxers/demux_matroska.c @@ -1749,10 +1749,7 @@ static int parse_tags(demux_matroska_t *this) { static void alloc_block_data (demux_matroska_t *this, int len) { /* memory management */ if (this->block_data_size < len) { - if (this->block_data) - this->block_data = realloc(this->block_data, len); - else - this->block_data = malloc(len); + this->block_data = realloc(this->block_data, len); this->block_data_size = len; } } -- cgit v1.2.3 From 528cbe3723dcdafc6eb80817721ea5cf6fb9b050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 21:36:15 +0100 Subject: Use calloc() when allocating an array of elements. --- src/demuxers/demux_real.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_real.c b/src/demuxers/demux_real.c index af74d979b..962030083 100644 --- a/src/demuxers/demux_real.c +++ b/src/demuxers/demux_real.c @@ -232,7 +232,7 @@ static void real_parse_index(demux_real_t *this) { if(index && entries) { /* Allocate memory for index */ - *index = xine_xmalloc(entries * sizeof(real_index_entry_t)); + *index = xine_xcalloc(entries, sizeof(real_index_entry_t)); /* Read index */ for(i = 0; i < entries; i++) { @@ -275,17 +275,17 @@ static mdpr_t *real_parse_mdpr(const char *data) { mdpr->duration=_X_BE_32(&data[28]); mdpr->stream_name_size=data[32]; - mdpr->stream_name=malloc(sizeof(char)*(mdpr->stream_name_size+1)); + mdpr->stream_name=calloc(mdpr->stream_name_size+1, sizeof(char)); memcpy(mdpr->stream_name, &data[33], mdpr->stream_name_size); mdpr->stream_name[(int)mdpr->stream_name_size]=0; mdpr->mime_type_size=data[33+mdpr->stream_name_size]; - mdpr->mime_type=malloc(sizeof(char)*(mdpr->mime_type_size+1)); + mdpr->mime_type=calloc(mdpr->mime_type_size+1, sizeof(char)); memcpy(mdpr->mime_type, &data[34+mdpr->stream_name_size], mdpr->mime_type_size); mdpr->mime_type[(int)mdpr->mime_type_size]=0; mdpr->type_specific_len=_X_BE_32(&data[34+mdpr->stream_name_size+mdpr->mime_type_size]); - mdpr->type_specific_data=malloc(sizeof(char)*(mdpr->type_specific_len)); + mdpr->type_specific_data=calloc(mdpr->type_specific_len, sizeof(char)); memcpy(mdpr->type_specific_data, &data[38+mdpr->stream_name_size+mdpr->mime_type_size], mdpr->type_specific_len); -- cgit v1.2.3 From e3ab135aff25bcb39f9d536784f08fb16945264a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 21:38:21 +0100 Subject: Use automatic buffers rather than malloc/free the buffer. --- src/demuxers/id3.c | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/demuxers/id3.c b/src/demuxers/id3.c index 4149c0512..ceb66014f 100644 --- a/src/demuxers/id3.c +++ b/src/demuxers/id3.c @@ -273,15 +273,9 @@ static int id3v22_parse_frame_header(input_plugin_t *input, static int id3v22_interp_frame(input_plugin_t *input, xine_stream_t *stream, id3v22_frame_header_t *frame_header) { - char *buf; + char buf[frame_header->size + 1]; int enc; - buf = malloc(frame_header->size + 1); - if (buf == NULL) { - lprintf("malloc error"); - return 0; - } - if (input->read (input, buf, frame_header->size) == frame_header->size) { buf[frame_header->size] = 0; enc = buf[0]; @@ -327,11 +321,9 @@ static int id3v22_interp_frame(input_plugin_t *input, lprintf("unhandled frame\n"); } - free(buf); return 1; } else { lprintf("read error\n"); - free(buf); return 0; } } @@ -467,15 +459,9 @@ static int id3v23_parse_frame_ext_header(input_plugin_t *input, static int id3v23_interp_frame(input_plugin_t *input, xine_stream_t *stream, id3v23_frame_header_t *frame_header) { - char *buf; + char buf[frame_header->size + 1]; int enc; - buf = malloc(frame_header->size + 1); - if (buf == NULL) { - lprintf("malloc error"); - return 0; - } - if (input->read (input, buf, frame_header->size) == frame_header->size) { buf[frame_header->size] = 0; enc = buf[0]; @@ -521,11 +507,9 @@ static int id3v23_interp_frame(input_plugin_t *input, lprintf("unhandled frame\n"); } - free(buf); return 1; } else { lprintf("read error\n"); - free(buf); return 0; } } @@ -716,15 +700,9 @@ static int id3v24_parse_ext_header(input_plugin_t *input, static int id3v24_interp_frame(input_plugin_t *input, xine_stream_t *stream, id3v24_frame_header_t *frame_header) { - char *buf; + char buf[frame_header->size + 1]; int enc; - buf = malloc(frame_header->size + 1); - if (buf == NULL) { - lprintf("malloc error"); - return 0; - } - if (input->read (input, buf, frame_header->size) == frame_header->size) { buf[frame_header->size] = 0; enc = buf[0]; @@ -772,11 +750,9 @@ static int id3v24_interp_frame(input_plugin_t *input, lprintf("unhandled frame\n"); } - free(buf); return 1; } else { lprintf("read error\n"); - free(buf); return 0; } } -- cgit v1.2.3 From be4a142d17fdcf23a79b02c45064f98141468dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 21:40:28 +0100 Subject: Use asprintf(). --- src/input/http_helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/input/http_helper.c b/src/input/http_helper.c index 4883763b0..279d3ff05 100644 --- a/src/input/http_helper.c +++ b/src/input/http_helper.c @@ -240,8 +240,7 @@ char *_x_canonicalise_url (const char *base, const char *url) { ++cut; } base_length = cut ? (size_t)(cut - base) : strlen (base); - ret = malloc (base_length + strlen (url) + 1); - sprintf (ret, "%.*s%s", (int)base_length, base, url); + asprintf (&ret, "%.*s%s", (int)base_length, base, url); return ret; } -- cgit v1.2.3 From a365222f0200a3f5437a601b06791eb7c03ff4e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 21:52:04 +0100 Subject: Use variable-sized arrays rather than allocated buffers. --- src/input/librtsp/rtsp.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/input/librtsp/rtsp.c b/src/input/librtsp/rtsp.c index a44d0e8e1..236dbc41e 100644 --- a/src/input/librtsp/rtsp.c +++ b/src/input/librtsp/rtsp.c @@ -103,8 +103,7 @@ const char rtsp_protocol_version[]="RTSP/1.0"; */ static char *rtsp_get(rtsp_t *s) { - - char *buffer = malloc(BUF_SIZE); + char buffer[BUF_SIZE]; char *string = NULL; if ( _x_io_tcp_read_line(s->stream, s->s, buffer, BUF_SIZE) >= 0 ) { @@ -112,7 +111,6 @@ static char *rtsp_get(rtsp_t *s) { string = strdup( buffer ); } - free(buffer); return string; } @@ -124,7 +122,7 @@ static char *rtsp_get(rtsp_t *s) { static void rtsp_put(rtsp_t *s, const char *string) { int len=strlen(string); - char *buf = malloc(sizeof(char)*len+2); + char buf[len+2]; lprintf(">> '%s'", string); @@ -135,8 +133,6 @@ static void rtsp_put(rtsp_t *s, const char *string) { _x_io_tcp_write(s->stream, s->s, buf, len+2); lprintf("done.\n"); - - free(buf); } /* @@ -171,13 +167,11 @@ static int rtsp_get_code(rtsp_t *s, const char *string) { static void rtsp_send_request(rtsp_t *s, const char *type, const char *what) { char **payload=s->scheduled; - char *buf; - - buf = malloc(strlen(type)+strlen(what)+strlen(rtsp_protocol_version)+3); + char buf[strlen(type)+strlen(what)+strlen(rtsp_protocol_version)+3]; sprintf(buf,"%s %s %s",type, what, rtsp_protocol_version); rtsp_put(s,buf); - free(buf); + if (payload) while (*payload) { rtsp_put(s,*payload); @@ -199,11 +193,9 @@ static void rtsp_schedule_standard(rtsp_t *s) { rtsp_schedule_field(s, tmp); if (s->session) { - char *buf; - buf = malloc(strlen(s->session)+15); + char buf[strlen(s->session)+15]; sprintf(buf, "Session: %s", s->session); rtsp_schedule_field(s, buf); - free(buf); } } /* @@ -241,14 +233,13 @@ static int rtsp_get_answers(rtsp_t *s) { } } if (!strncasecmp(answer,"Server:",7)) { - char *buf = xine_xmalloc(strlen(answer)); + char buf[strlen(answer)]; sscanf(answer,"%*s %s",buf); if (s->server) free(s->server); s->server=strdup(buf); - free(buf); } if (!strncasecmp(answer,"Session:",8)) { - char *buf = xine_xmalloc(strlen(answer)); + char buf[strlen(answer)]; sscanf(answer,"%*s %s",buf); if (s->session) { if (strcmp(buf, s->session)) { @@ -263,7 +254,6 @@ static int rtsp_get_answers(rtsp_t *s) { s->session=strdup(buf); } - free(buf); } *answer_ptr=answer; answer_ptr++; -- cgit v1.2.3 From a87b60337712543a6f715b45c80affbdc5ba520a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 21:53:57 +0100 Subject: Use asprintf where possible. --- src/input/librtsp/rtsp.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/input/librtsp/rtsp.c b/src/input/librtsp/rtsp.c index 236dbc41e..b6dad6a31 100644 --- a/src/input/librtsp/rtsp.c +++ b/src/input/librtsp/rtsp.c @@ -21,6 +21,8 @@ * *not* RFC 2326 compilant yet. */ +#include + #include #include #include @@ -294,8 +296,7 @@ int rtsp_request_options(rtsp_t *s, const char *what) { buf=strdup(what); } else { - buf = malloc(sizeof(char)*(strlen(s->host)+16)); - sprintf(buf,"rtsp://%s:%i", s->host, s->port); + asprintf(&buf,"rtsp://%s:%i", s->host, s->port); } rtsp_send_request(s,"OPTIONS",buf); free(buf); @@ -311,8 +312,7 @@ int rtsp_request_describe(rtsp_t *s, const char *what) { buf=strdup(what); } else { - buf = malloc(sizeof(char)*(strlen(s->host)+strlen(s->path)+16)); - sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path); + asprintf(&buf,"rtsp://%s:%i/%s", s->host, s->port, s->path); } rtsp_send_request(s,"DESCRIBE",buf); free(buf); @@ -335,8 +335,7 @@ int rtsp_request_setparameter(rtsp_t *s, const char *what) { buf=strdup(what); } else { - buf = malloc(sizeof(char)*(strlen(s->host)+strlen(s->path)+16)); - sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path); + asprintf(&buf,"rtsp://%s:%i/%s", s->host, s->port, s->path); } rtsp_send_request(s,"SET_PARAMETER",buf); free(buf); @@ -352,8 +351,7 @@ int rtsp_request_play(rtsp_t *s, const char *what) { buf=strdup(what); } else { - buf = malloc(sizeof(char)*(strlen(s->host)+strlen(s->path)+16)); - sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path); + asprintf(&buf,"rtsp://%s:%i/%s", s->host, s->port, s->path); } rtsp_send_request(s,"PLAY",buf); free(buf); @@ -402,8 +400,7 @@ int rtsp_read_data(rtsp_t *s, void *buffer_gen, unsigned int size) { } /* lets make the server happy */ rtsp_put(s, "RTSP/1.0 451 Parameter Not Understood"); - rest = malloc(sizeof(char)*17); - sprintf(rest,"CSeq: %u", seq); + asprintf(&rest,"CSeq: %u", seq); rtsp_put(s, rest); free(rest); rtsp_put(s, ""); -- cgit v1.2.3 From 213baa59e3644093f5b208218e8d233d95fd4a74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 21:55:53 +0100 Subject: Use strndup. --- src/input/librtsp/rtsp.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/input/librtsp/rtsp.c b/src/input/librtsp/rtsp.c index b6dad6a31..d0f09d563 100644 --- a/src/input/librtsp/rtsp.c +++ b/src/input/librtsp/rtsp.c @@ -473,9 +473,7 @@ rtsp_t *rtsp_connect(xine_stream_t *stream, const char *mrl, const char *user_ag pathbegin=slash-mrl_ptr; hostend=colon-mrl_ptr; - s->host = malloc(sizeof(char)*hostend+1); - strncpy(s->host, mrl_ptr, hostend); - s->host[hostend]=0; + s->host = strndup(mrl_ptr, hostend); if (pathbegin < strlen(mrl_ptr)) s->path=strdup(mrl_ptr+pathbegin+1); if (colon != slash) { -- cgit v1.2.3 From 8420c9a0ec8eb05b30fc5e48e062b14f1af095f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 21:56:02 +0100 Subject: Use calloc() when allocating an array of elements. --- src/input/libreal/real.c | 2 +- src/input/libreal/rmff.c | 21 +++++++++------------ src/input/libreal/sdpplin.c | 4 ++-- 3 files changed, 12 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/input/libreal/real.c b/src/input/libreal/real.c index 9ea65d9df..925b0fdf8 100644 --- a/src/input/libreal/real.c +++ b/src/input/libreal/real.c @@ -660,7 +660,7 @@ rmff_header_t *real_setup_and_get_header(rtsp_t *rtsp_session, uint32_t bandwid lprintf("Stream description size: %i\n", size); - description = malloc(sizeof(char)*(size+1)); + description = calloc(size+1, sizeof(char)); if( rtsp_read_data(rtsp_session, description, size) <= 0) { xine_buffer_free(buf); diff --git a/src/input/libreal/rmff.c b/src/input/libreal/rmff.c index e942fe4cc..4fea74636 100644 --- a/src/input/libreal/rmff.c +++ b/src/input/libreal/rmff.c @@ -311,17 +311,17 @@ static rmff_mdpr_t *rmff_scan_mdpr(const char *data) { mdpr->duration=_X_BE_32(&data[36]); mdpr->stream_name_size=data[40]; - mdpr->stream_name = malloc(sizeof(char)*(mdpr->stream_name_size+1)); + mdpr->stream_name = calloc(mdpr->stream_name_size+1, sizeof(char)); memcpy(mdpr->stream_name, &data[41], mdpr->stream_name_size); mdpr->stream_name[mdpr->stream_name_size]=0; mdpr->mime_type_size=data[41+mdpr->stream_name_size]; - mdpr->mime_type = malloc(sizeof(char)*(mdpr->mime_type_size+1)); + mdpr->mime_type = calloc(mdpr->mime_type_size+1, sizeof(char)); memcpy(mdpr->mime_type, &data[42+mdpr->stream_name_size], mdpr->mime_type_size); mdpr->mime_type[mdpr->mime_type_size]=0; mdpr->type_specific_len=_X_BE_32(&data[42+mdpr->stream_name_size+mdpr->mime_type_size]); - mdpr->type_specific_data = malloc(sizeof(char)*(mdpr->type_specific_len)); + mdpr->type_specific_data = calloc(mdpr->type_specific_len, sizeof(char)); memcpy(mdpr->type_specific_data, &data[46+mdpr->stream_name_size+mdpr->mime_type_size], mdpr->type_specific_len); @@ -341,22 +341,22 @@ static rmff_cont_t *rmff_scan_cont(const char *data) { lprintf("warning: unknown object version in CONT: 0x%04x\n", cont->object_version); } cont->title_len=_X_BE_16(&data[10]); - cont->title = malloc(sizeof(char)*(cont->title_len+1)); + cont->title = calloc((cont->title_len+1), sizeof(char)); memcpy(cont->title, &data[12], cont->title_len); cont->title[cont->title_len]=0; pos=cont->title_len+12; cont->author_len=_X_BE_16(&data[pos]); - cont->author = malloc(sizeof(char)*(cont->author_len+1)); + cont->author = calloc(cont->author_len+1, sizeof(char)); memcpy(cont->author, &data[pos+2], cont->author_len); cont->author[cont->author_len]=0; pos=pos+2+cont->author_len; cont->copyright_len=_X_BE_16(&data[pos]); - cont->copyright = malloc(sizeof(char)*(cont->copyright_len+1)); + cont->copyright = calloc(cont->copyright_len+1, sizeof(char)); memcpy(cont->copyright, &data[pos+2], cont->copyright_len); cont->copyright[cont->copyright_len]=0; pos=pos+2+cont->copyright_len; cont->comment_len=_X_BE_16(&data[pos]); - cont->comment = malloc(sizeof(char)*(cont->comment_len+1)); + cont->comment = calloc(cont->comment_len+1, sizeof(char)); memcpy(cont->comment, &data[pos+2], cont->comment_len); cont->comment[cont->comment_len]=0; @@ -404,10 +404,7 @@ rmff_header_t *rmff_scan_header(const char *data) { header->fileheader=rmff_scan_fileheader(ptr); ptr += header->fileheader->size; - header->streams = malloc(sizeof(rmff_mdpr_t*)*(header->fileheader->num_headers)); - for (i=0; ifileheader->num_headers; i++) { - header->streams[i]=NULL; - } + header->streams = calloc(header->fileheader->num_headers, sizeof(rmff_mdpr_t*)); for (i=1; ifileheader->num_headers; i++) { chunk_type = _X_BE_32(ptr); @@ -587,7 +584,7 @@ rmff_mdpr_t *rmff_new_mdpr( mdpr->mime_type_size=strlen(mime_type); } mdpr->type_specific_len=type_specific_len; - mdpr->type_specific_data = malloc(sizeof(char)*type_specific_len); + mdpr->type_specific_data = calloc(type_specific_len, sizeof(char)); memcpy(mdpr->type_specific_data,type_specific_data,type_specific_len); mdpr->mlti_data=NULL; diff --git a/src/input/libreal/sdpplin.c b/src/input/libreal/sdpplin.c index c62b6bbc1..5b22e9044 100644 --- a/src/input/libreal/sdpplin.c +++ b/src/input/libreal/sdpplin.c @@ -199,7 +199,7 @@ static sdpplin_stream_t *sdpplin_parse_stream(char **data) { if(filter(*data,"a=OpaqueData:buffer;",&buf)) { decoded = b64_decode(buf, decoded, &(desc->mlti_data_size)); if ( decoded != NULL ) { - desc->mlti_data = malloc(sizeof(char)*desc->mlti_data_size); + desc->mlti_data = calloc(desc->mlti_data_size, sizeof(char)); memcpy(desc->mlti_data, decoded, desc->mlti_data_size); handled=1; *data=nl(*data); @@ -294,7 +294,7 @@ sdpplin_t *sdpplin_parse(char *data) { if(filter(data,"a=StreamCount:integer;",&buf)) { desc->stream_count=atoi(buf); - desc->stream = malloc(sizeof(sdpplin_stream_t*)*desc->stream_count); + desc->stream = calloc(desc->stream_count, sizeof(sdpplin_stream_t*)); handled=1; data=nl(data); } -- cgit v1.2.3 From 60fb61f5d503d16233b2bfed884cd7bfd9865343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 21:59:40 +0100 Subject: Use strndup. --- src/input/pnm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/input/pnm.c b/src/input/pnm.c index 38d65b850..942e52957 100644 --- a/src/input/pnm.c +++ b/src/input/pnm.c @@ -21,6 +21,8 @@ * based upon code from joschka */ +#include + #include #include #include @@ -732,9 +734,7 @@ pnm_t *pnm_connect(xine_stream_t *stream, const char *mrl) { pathbegin=slash-mrl_ptr; hostend=colon-mrl_ptr; - p->host = malloc(sizeof(char)*hostend+1); - strncpy(p->host, mrl_ptr, hostend); - p->host[hostend]=0; + p->host = strndup(mrl_ptr, hostend); if (pathbegin < strlen(mrl_ptr)) p->path=strdup(mrl_ptr+pathbegin+1); if (colon != slash) { -- cgit v1.2.3 From 0c8f64fe6f210591a36aaf9261a8106db2a20ea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 22:00:31 +0100 Subject: Use strdup. --- src/input/vcd/xineplug_inp_vcd.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/input/vcd/xineplug_inp_vcd.c b/src/input/vcd/xineplug_inp_vcd.c index 45d9789ba..b794331f1 100644 --- a/src/input/vcd/xineplug_inp_vcd.c +++ b/src/input/vcd/xineplug_inp_vcd.c @@ -272,11 +272,9 @@ vcd_add_mrl_slot(vcd_input_class_t *this, const char *mrl, off_t size, this->mrls[*i]->type = mrl_vcd; this->mrls[*i]->size = size * M2F2_SECTOR_SIZE; - this->mrls[*i]->mrl = (char *) malloc(strlen(mrl) + 1); + this->mrls[*i]->mrl = strdup(mrl); if (NULL==this->mrls[*i]->mrl) { - LOG_ERR("Can't malloc %zu bytes for MRL name %s", sizeof(xine_mrl_t), mrl); - } else { - sprintf(this->mrls[*i]->mrl, "%s", mrl); + LOG_ERR("Can't strndup %zu bytes for MRL name %s", strlen(mrl), mrl); } (*i)++; } -- cgit v1.2.3 From ba4661262255c0a23218b1722779dea5015c9f7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 22:22:07 +0100 Subject: Use asprintf. --- src/input/input_dvd.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src') diff --git a/src/input/input_dvd.c b/src/input/input_dvd.c index 446b7c778..8656097bc 100644 --- a/src/input/input_dvd.c +++ b/src/input/input_dvd.c @@ -1374,10 +1374,7 @@ check_solaris_vold_device(dvd_input_class_t *this) (volume_action = getenv("VOLUME_ACTION")) != NULL && strcmp(volume_action, "insert") == 0) { - device = malloc(strlen(volume_device) + strlen(volume_name) + 2); - if (device == NULL) - return; - sprintf(device, "%s/%s", volume_device, volume_name); + asprintf(&device, "%s/%s", volume_device, volume_name); if (stat(device, &stb) != 0 || !S_ISCHR(stb.st_mode)) { free(device); return; -- cgit v1.2.3 From c537cb8014eb4a46d4de61e9359c4af2e04c4574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 22:23:59 +0100 Subject: Use asprintf. --- src/input/input_pvr.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/input/input_pvr.c b/src/input/input_pvr.c index ac7c5f2f0..40bb9dc79 100644 --- a/src/input/input_pvr.c +++ b/src/input/input_pvr.c @@ -511,10 +511,7 @@ static char *make_temp_name(pvr_input_plugin_t *this, int page) { char *filename; - int size = strlen(this->tmp_prefix)+PVR_FILENAME_SIZE; - filename = malloc(size); - - snprintf(filename, size, PVR_FILENAME, this->tmp_prefix, this->session, page); + asprintf(&filename, PVR_FILENAME, this->tmp_prefix, this->session, page); return filename; } @@ -527,12 +524,9 @@ static char *make_base_save_name(int channel, time_t tm) { struct tm rec_time; char *filename; - int size = SAVE_BASE_FILENAME_SIZE; - filename = malloc(size); - localtime_r(&tm, &rec_time); - snprintf(filename, size, SAVE_BASE_FILENAME, + asprintf(&filename, SAVE_BASE_FILENAME, channel, rec_time.tm_mon+1, rec_time.tm_mday, rec_time.tm_year+1900, rec_time.tm_hour, rec_time.tm_min, rec_time.tm_sec); @@ -546,10 +540,7 @@ static char *make_save_name(pvr_input_plugin_t *this, char *base, int page) { char *filename; - int size = strlen(this->save_prefix)+strlen(base)+SAVE_FILENAME_SIZE; - filename = malloc(size); - - snprintf(filename, size, SAVE_FILENAME, this->save_prefix, base, page); + asprintf(&filename, SAVE_FILENAME, this->save_prefix, base, page); return filename; } -- cgit v1.2.3 From 0f3a27b95f4efb0b541bacf2684a904787e4bab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 22:32:15 +0100 Subject: Avoid a multiplication. --- src/input/input_http.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/input/input_http.c b/src/input/input_http.c index 38658b161..c4ce7af83 100644 --- a/src/input/input_http.c +++ b/src/input/input_http.c @@ -249,7 +249,7 @@ static int http_plugin_basicauth (const char *user, const char *password, char* if (len < enclen) return -1; - tmp = malloc (sizeof(char) * (totlen + 1)); + tmp = malloc (totlen + 1); strcpy (tmp, user); strcat (tmp, ":"); if (password != NULL) -- cgit v1.2.3 From 923db0a3878ffe545084b13f23f7b2e23f66f097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 22:32:46 +0100 Subject: Mark the enctable static. --- src/input/input_http.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/input/input_http.c b/src/input/input_http.c index c4ce7af83..407e2045e 100644 --- a/src/input/input_http.c +++ b/src/input/input_http.c @@ -232,7 +232,7 @@ static int _x_use_proxy(http_input_class_t *this, const char *host) { } static int http_plugin_basicauth (const char *user, const char *password, char* dest, int len) { - static char *enctable="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + static const char enctable[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; char *tmp; char *sptr; char *dptr; -- cgit v1.2.3 From ef321eddada42f14079be191a9e10c499afd29df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 22:44:19 +0100 Subject: Use variable-sized arrays rather than allocated buffer. --- src/xine-engine/xine.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c index 17ea5d679..5ad642202 100644 --- a/src/xine-engine/xine.c +++ b/src/xine-engine/xine.c @@ -850,7 +850,7 @@ static int open_internal (xine_stream_t *stream, const char *mrl) { /* look for the next '#' or try the whole MRL, if none is found */ while (*stream_setup && (stream_setup = (strchr(stream_setup, '#') ? strchr(stream_setup, '#') : strlen(mrl) + mrl))) { - char *input_source = (char *)malloc(stream_setup - mrl + 1); + char input_source[stream_setup - mrl + 1]; memcpy(input_source, mrl, stream_setup - mrl); input_source[stream_setup - mrl] = '\0'; @@ -872,10 +872,8 @@ static int open_internal (xine_stream_t *stream, const char *mrl) { res = (stream->input_plugin->open) (stream->input_plugin); switch(res) { case 1: /* Open successfull */ - free(input_source); break; case -1: /* Open unsuccessfull, but correct plugin */ - free(input_source); stream->err = XINE_ERROR_INPUT_FAILED; _x_flush_events_queues (stream); return 0; @@ -888,7 +886,6 @@ static int open_internal (xine_stream_t *stream, const char *mrl) { if ( res ) break; } - free(input_source); /* if we fail when passing up to the first '#' to the input plugins, * maybe the user stated a (invalid) MRL, with a '#' belonging to the * input source -> look for the next '#' and try again */ @@ -1640,9 +1637,8 @@ static void config_demux_strategy_cb (void *this_gen, xine_cfg_entry_t *entry) { static void config_save_cb (void *this_gen, xine_cfg_entry_t *entry) { xine_t *this = (xine_t *)this_gen; - char *homedir_trail_slash; + char homedir_trail_slash[strlen(xine_get_homedir()) + 2]; - homedir_trail_slash = (char *)malloc(strlen(xine_get_homedir()) + 2); sprintf(homedir_trail_slash, "%s/", xine_get_homedir()); if (entry->str_value[0] && (entry->str_value[0] != '/' || strstr(entry->str_value, "/.") || @@ -1662,7 +1658,6 @@ static void config_save_cb (void *this_gen, xine_cfg_entry_t *entry) { pthread_mutex_unlock(&this->streams_lock); } - free(homedir_trail_slash); this->save_path = entry->str_value; } -- cgit v1.2.3 From 922ee9ab4045c81d6874b07fdb8aadc551f824d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 22:45:28 +0100 Subject: Use calloc() when allocating an array of elements. --- src/xine-utils/array.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/xine-utils/array.c b/src/xine-utils/array.c index 6c226c7ef..f6989fbb6 100644 --- a/src/xine-utils/array.c +++ b/src/xine-utils/array.c @@ -56,7 +56,7 @@ xine_array_t *xine_array_new(size_t initial_size) { if (initial_size < MIN_CHUNK_SIZE) initial_size = MIN_CHUNK_SIZE; - new_array->chunk = (void**)malloc(sizeof(void*) * initial_size); + new_array->chunk = (void**)calloc(initial_size, sizeof(void*)); if (!new_array->chunk) { free(new_array); return NULL; -- cgit v1.2.3 From 4ccb69e98ecdca80bad9e656d686b0086ca3149a Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Tue, 18 Dec 2007 21:55:52 +0000 Subject: Clean up recursive mkdir(). --- src/input/input_cdda.c | 46 ++++++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/input/input_cdda.c b/src/input/input_cdda.c index e658e30ca..ed6f2b4f9 100644 --- a/src/input/input_cdda.c +++ b/src/input/input_cdda.c @@ -1283,39 +1283,29 @@ static void _cdda_mkdir_safe(xine_t *xine, char *path) { } /* - * Make recursive directory creation + * Make recursive directory creation (given an absolute pathname) */ -static void _cdda_mkdir_recursive_safe(xine_t *xine, char *path) { - char *p, *pp; - char buf[XINE_PATH_MAX + XINE_NAME_MAX + 1] = { 0, }; - char buf2[XINE_PATH_MAX + XINE_NAME_MAX + 1] = { 0, }; - - if(path == NULL) +static void _cdda_mkdir_recursive_safe (xine_t *xine, char *path) +{ + if (!path) return; - snprintf(buf, sizeof(buf), "%s", path); - pp = buf; - while((p = xine_strsep(&pp, "/")) != NULL) { - if(p && strlen(p)) { - -#ifdef WIN32 - if (*buf2 != '\0') { -#endif - - int size = strlen(buf2); - snprintf(buf2 + size, sizeof(buf2) - size, "/%s", p); - -#ifdef WIN32 - } - else { - snprintf(buf2, sizeof(buf2), "%s", p); - } + char buf[strlen (path) + 1]; + strcpy (buf, path); + char *p = strchr (buf, '/') ? : buf; -#endif /* WIN32 */ + do + { + while (*p++ == '/') /**/; + p = strchr (p, '/'); + if (p) + *p = 0; + _cdda_mkdir_safe (xine, buf); + if (p) + *p = '/'; + } while (p); - _cdda_mkdir_safe(xine, buf2); - } - } + return 0; } /* -- cgit v1.2.3 From 90d290b7abac28a57c4abee41556e5f48064f60d Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Tue, 18 Dec 2007 23:06:30 +0000 Subject: Don't treat # in MRLs as literals or URI-decode raw filenames. [Bug 1784272] --- src/input/input_file.c | 44 ++++++++++++++------------------------------ src/xine-engine/xine.c | 33 +++++++++++++++++---------------- 2 files changed, 31 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/input/input_file.c b/src/input/input_file.c index abb689e39..f81103dcd 100644 --- a/src/input/input_file.c +++ b/src/input/input_file.c @@ -340,7 +340,7 @@ static int file_plugin_open (input_plugin_t *this_gen ) { lprintf("file_plugin_open\n"); - if (strncasecmp (this->mrl, "file:", 5) == 0) + if (strncasecmp (this->mrl, "file:/", 6) == 0) { if (strncasecmp (this->mrl, "file://localhost/", 16) == 0) filename = decode_uri(&(this->mrl[16])); @@ -350,43 +350,27 @@ static int file_plugin_open (input_plugin_t *this_gen ) { filename = decode_uri(&(this->mrl[5])); } else - filename = decode_uri(this->mrl); + filename = strdup(this->mrl); /* NEVER unescape plain file names! */ this->fh = open (filename, O_RDONLY|O_BINARY); - - free(filename); if (this->fh == -1) { - /* try again without unescaping; such MRLs might be invalid, - * but we are a nice software */ - if (strncasecmp (this->mrl, "file:", 5) == 0) - { - if (strncasecmp (this->mrl, "file://localhost/", 16) == 0) - this->fh = open(&this->mrl[16], O_RDONLY|O_BINARY); - else if (strncasecmp (this->mrl, "file://127.0.0.1/", 16) == 0) - this->fh = open(&this->mrl[16], O_RDONLY|O_BINARY); - else - this->fh = open(&this->mrl[5], O_RDONLY|O_BINARY); + if (errno == EACCES) { + _x_message(this->stream, XINE_MSG_PERMISSION_ERROR, this->mrl, NULL); + xine_log (this->stream->xine, XINE_LOG_MSG, + _("input_file: Permission denied: >%s<\n"), this->mrl); + } else if (errno == ENOENT) { + _x_message(this->stream, XINE_MSG_FILE_NOT_FOUND, this->mrl, NULL); + xine_log (this->stream->xine, XINE_LOG_MSG, + _("input_file: File not found: >%s<\n"), this->mrl); } - else - this->fh = open(this->mrl, O_RDONLY|O_BINARY); - - if (this->fh == -1) { - if (errno == EACCES) { - _x_message(this->stream, XINE_MSG_PERMISSION_ERROR, this->mrl, NULL); - xine_log (this->stream->xine, XINE_LOG_MSG, - _("input_file: Permission denied: >%s<\n"), this->mrl); - return -1; - } else if (errno == ENOENT) { - _x_message(this->stream, XINE_MSG_FILE_NOT_FOUND, this->mrl, NULL); - xine_log (this->stream->xine, XINE_LOG_MSG, - _("input_file: File not found: >%s<\n"), this->mrl); - } - return -1; - } + free(filename); + return -1; } + free(filename); + #ifdef HAVE_MMAP this->mmap_on = 0; this->mmap_base = NULL; diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c index 097ce99ef..f3b59942d 100644 --- a/src/xine-engine/xine.c +++ b/src/xine-engine/xine.c @@ -35,6 +35,7 @@ #include #include #include +#include #if defined (__linux__) || defined (__GLIBC__) #include #elif defined (__FreeBSD__) @@ -779,9 +780,9 @@ void _x_flush_events_queues (xine_stream_t *stream) { pthread_mutex_unlock (&stream->event_queues_lock); } -static int open_internal (xine_stream_t *stream, const char *mrl) { +/*static*/ int open_internal (xine_stream_t *stream, const char *mrl) { - const char *stream_setup; + const char *stream_setup = NULL; int no_cache = 0; if (!mrl) { @@ -806,13 +807,19 @@ static int open_internal (xine_stream_t *stream, const char *mrl) { * look for a stream_setup in MRL and try finding an input plugin */ - stream_setup = mrl; - /* look for the next '#' or try the whole MRL, if none is found */ - while (*stream_setup && - (stream_setup = (strchr(stream_setup, '#') ? strchr(stream_setup, '#') : strlen(mrl) + mrl))) { - char *input_source = (char *)malloc(stream_setup - mrl + 1); - memcpy(input_source, mrl, stream_setup - mrl); - input_source[stream_setup - mrl] = '\0'; + if (isalpha (*mrl)) + { + stream_setup = mrl + 1; + while (isalnum (*stream_setup) || *stream_setup == '+' || *stream_setup == '-' || *stream_setup == '.') + ++stream_setup; + if (stream_setup[0] == ':' && stream_setup[1] == '/') + stream_setup = strchr (mrl, '#'); + else + stream_setup = NULL; + } + + { + char *input_source = strndup (mrl, stream_setup ? stream_setup - mrl : strlen (mrl)); /* * find an input plugin @@ -831,7 +838,6 @@ static int open_internal (xine_stream_t *stream, const char *mrl) { res = (stream->input_plugin->open) (stream->input_plugin); switch(res) { case 1: /* Open successfull */ - free(input_source); break; case -1: /* Open unsuccessfull, but correct plugin */ free(input_source); @@ -844,14 +850,9 @@ static int open_internal (xine_stream_t *stream, const char *mrl) { stream->input_plugin = NULL; stream->err = XINE_ERROR_INPUT_FAILED; } - if ( res ) break; } free(input_source); - /* if we fail when passing up to the first '#' to the input plugins, - * maybe the user stated a (invalid) MRL, with a '#' belonging to the - * input source -> look for the next '#' and try again */ - if (*stream_setup) stream_setup++; } if (!stream->input_plugin) { @@ -861,7 +862,7 @@ static int open_internal (xine_stream_t *stream, const char *mrl) { return 0; } - if (*stream_setup) { + if (stream_setup) { while (stream_setup && *stream_setup && *(++stream_setup)) { if (strncasecmp(stream_setup, "demux", 5) == 0) { -- cgit v1.2.3 From adae6f7ab3a15f031252fd77261f4d49fed88805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 19 Dec 2007 00:57:25 +0100 Subject: Make proxyauth a variable local to http_plugin_open() function. --HG-- extra : transplant_source : %F2%15%E8%D0%BC%EE%04Xk%21U%D2%AB%968%0F%15%8A%91E --- src/input/input_http.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/input/input_http.c b/src/input/input_http.c index 407e2045e..42f64b4a8 100644 --- a/src/input/input_http.c +++ b/src/input/input_http.c @@ -80,7 +80,6 @@ typedef struct { char proxybuf[BUFSIZE]; char auth[BUFSIZE]; - char proxyauth[BUFSIZE]; char preview[MAX_PREVIEW_SIZE]; off_t preview_size; @@ -667,6 +666,7 @@ static int http_plugin_open (input_plugin_t *this_gen ) { int use_proxy; int proxyport; int mpegurl_redirect = 0; + char proxyauth[BUFSIZE]; use_proxy = this_class->proxyhost && strlen(this_class->proxyhost); @@ -674,7 +674,7 @@ static int http_plugin_open (input_plugin_t *this_gen ) { if (this_class->proxyuser && strlen(this_class->proxyuser)) { if (http_plugin_basicauth (this_class->proxyuser, this_class->proxypassword, - this->proxyauth, BUFSIZE)) { + proxyauth, BUFSIZE)) { _x_message(this->stream, XINE_MSG_CONNECTION_REFUSED, "proxy error", NULL); return 0; } @@ -776,7 +776,7 @@ static int http_plugin_open (input_plugin_t *this_gen ) { buflen = strlen(this->buf); if (this_class->proxyuser && strlen(this_class->proxyuser)) { snprintf (this->buf + buflen, BUFSIZE - buflen, - "Proxy-Authorization: Basic %s\015\012", this->proxyauth); + "Proxy-Authorization: Basic %s\015\012", proxyauth); buflen = strlen(this->buf); } if (this->user && strlen(this->user)) { -- cgit v1.2.3 From 64596f317f7d03ed1f3e747cd2b0664b1d4f6535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 19 Dec 2007 01:03:58 +0100 Subject: Make auth also a local variable in http_plugin_open. --- src/input/input_http.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/input/input_http.c b/src/input/input_http.c index 42f64b4a8..f2e91c226 100644 --- a/src/input/input_http.c +++ b/src/input/input_http.c @@ -79,8 +79,6 @@ typedef struct { char buf[BUFSIZE]; char proxybuf[BUFSIZE]; - char auth[BUFSIZE]; - char preview[MAX_PREVIEW_SIZE]; off_t preview_size; @@ -666,6 +664,7 @@ static int http_plugin_open (input_plugin_t *this_gen ) { int use_proxy; int proxyport; int mpegurl_redirect = 0; + char auth[BUFSIZE]; char proxyauth[BUFSIZE]; use_proxy = this_class->proxyhost && strlen(this_class->proxyhost); @@ -693,7 +692,7 @@ static int http_plugin_open (input_plugin_t *this_gen ) { this->port = DEFAULT_HTTP_PORT; if (this->user && strlen(this->user)) { - if (http_plugin_basicauth (this->user, this->password, this->auth, BUFSIZE)) { + if (http_plugin_basicauth (this->user, this->password, auth, BUFSIZE)) { _x_message(this->stream, XINE_MSG_CONNECTION_REFUSED, "basic auth error", NULL); return -1; } @@ -781,7 +780,7 @@ static int http_plugin_open (input_plugin_t *this_gen ) { } if (this->user && strlen(this->user)) { snprintf (this->buf + buflen, BUFSIZE - buflen, - "Authorization: Basic %s\015\012", this->auth); + "Authorization: Basic %s\015\012", auth); buflen = strlen(this->buf); } -- cgit v1.2.3