From d9e6d4201ce207cc52fe7b87b75dcf8997a2f830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Sun, 13 Feb 2011 12:24:48 +0100 Subject: [PATCH 3/3] Use mp_asprintf in get_metadata instead of limited stack buffer. --- mplayer.c | 19 ++++++------------- 1 files changed, 6 insertions(+), 13 deletions(-) diff --git a/mplayer.c b/mplayer.c index 28eb700..5034b98 100644 --- a/mplayer.c +++ b/mplayer.c @@ -438,7 +438,6 @@ static char *get_demuxer_info (char *tag) { } char *get_metadata (metadata_t type) { - char meta[128]; sh_audio_t * const sh_audio = mpctx->sh_audio; sh_video_t * const sh_video = mpctx->sh_video; @@ -460,18 +459,14 @@ char *get_metadata (metadata_t type) { else if (sh_video->format == 0x10000005) return strdup("h264"); else if (sh_video->format >= 0x20202020) - snprintf(meta, sizeof(meta), "%.4s", (char *) &sh_video->format); - else - snprintf(meta, sizeof(meta), "0x%08X", sh_video->format); - return strdup(meta); + return mp_asprintf("%.4s", (char *)&sh_video->format); + return mp_asprintf("0x%08X", sh_video->format); case META_VIDEO_BITRATE: - snprintf(meta, sizeof(meta), "%d kbps", (int) (sh_video->i_bps * 8 / 1024)); - return strdup(meta); + return mp_asprintf("%d kbps", (int)(sh_video->i_bps * 8 / 1024)); case META_VIDEO_RESOLUTION: - snprintf(meta, sizeof(meta), "%d x %d", sh_video->disp_w, sh_video->disp_h); - return strdup(meta); + return mp_asprintf("%d x %d", sh_video->disp_w, sh_video->disp_h); case META_AUDIO_CODEC: if (sh_audio->codec && sh_audio->codec->name) @@ -479,12 +474,10 @@ char *get_metadata (metadata_t type) { break; case META_AUDIO_BITRATE: - snprintf(meta, sizeof(meta), "%d kbps", (int)(sh_audio->i_bps * 8 / 1000)); - return strdup(meta); + return mp_asprintf("%d kbps", (int)(sh_audio->i_bps * 8 / 1000)); case META_AUDIO_SAMPLES: - snprintf(meta, sizeof(meta), "%d Hz, %d ch.", sh_audio->samplerate, sh_audio->channels); - return strdup(meta); + return mp_asprintf("%d Hz, %d ch.", sh_audio->samplerate, sh_audio->channels); /* check for valid demuxer */ case META_INFO_TITLE: -- 1.7.4.1