summaryrefslogtreecommitdiffstats
path: root/mplayer.c
diff options
context:
space:
mode:
authorharklu <harklu@wat>2011-08-08 10:07:17 +0200
committerUoti Urpala <uau@mplayer2.org>2011-08-09 03:28:58 +0300
commitd4b8d1486a69ee5bbd96a2758f56c1bbc6242bfb (patch)
tree943c14a454c9961f7bf7f9fbcdc1ac3da32e4917 /mplayer.c
parentfada084499a33a4a1d7ef79f3ac72364a55e0c17 (diff)
downloadmpv-d4b8d1486a69ee5bbd96a2758f56c1bbc6242bfb.tar.bz2
mpv-d4b8d1486a69ee5bbd96a2758f56c1bbc6242bfb.tar.xz
core: allocate OSD text buffers dynamically
The OSD text buffers (mp_osd_msg_t.text and osd_state.text) used to be static arrays, with the buffer sizes spread all over the code as magic constants. Make the buffers dynamically allocated and remove the arbitrary length limits.
Diffstat (limited to 'mplayer.c')
-rw-r--r--mplayer.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/mplayer.c b/mplayer.c
index 3b8f588c0e..b77acb3088 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -1471,7 +1471,7 @@ struct mp_osd_msg {
/// Previous message on the stack.
mp_osd_msg_t *prev;
/// Message text.
- char msg[128];
+ char *msg;
int id, level, started;
/// Display duration in ms.
unsigned time;
@@ -1491,14 +1491,13 @@ static void set_osd_msg_va(int id, int level, int time, const char *fmt,
va_list ap)
{
mp_osd_msg_t *msg, *last = NULL;
- int r;
// look if the id is already in the stack
for (msg = osd_msg_stack; msg && msg->id != id;
last = msg, msg = msg->prev) ;
// not found: alloc it
if (!msg) {
- msg = calloc(1, sizeof(mp_osd_msg_t));
+ msg = talloc_zero(NULL, mp_osd_msg_t);
msg->prev = osd_msg_stack;
osd_msg_stack = msg;
} else if (last) { // found, but it's not on top of the stack
@@ -1506,10 +1505,9 @@ static void set_osd_msg_va(int id, int level, int time, const char *fmt,
msg->prev = osd_msg_stack;
osd_msg_stack = msg;
}
+ talloc_free(msg->msg);
// write the msg
- r = vsnprintf(msg->msg, 128, fmt, ap);
- if (r >= 128)
- msg->msg[127] = 0;
+ msg->msg = talloc_vasprintf(msg, fmt, ap);
// set id and time
msg->id = id;
msg->level = level;
@@ -1533,7 +1531,6 @@ void set_osd_tmsg(int id, int level, int time, const char *fmt, ...)
va_end(ap);
}
-
/**
* \brief Remove a message from the OSD stack
*
@@ -1556,7 +1553,7 @@ void rm_osd_msg(int id)
last->prev = msg->prev;
else
osd_msg_stack = msg->prev;
- free(msg);
+ talloc_free(msg);
}
/**
@@ -1569,7 +1566,7 @@ static void clear_osd_msgs(void)
mp_osd_msg_t *msg = osd_msg_stack, *prev = NULL;
while (msg) {
prev = msg->prev;
- free(msg);
+ talloc_free(msg);
msg = prev;
}
osd_msg_stack = NULL;
@@ -1630,7 +1627,7 @@ static mp_osd_msg_t *get_osd_msg(struct MPContext *mpctx)
continue;
}
// kill the message
- free(msg);
+ talloc_free(msg);
if (last) {
last->prev = prev;
msg = last;
@@ -1720,7 +1717,7 @@ static void update_osd_msg(struct MPContext *mpctx)
// Look if we have a msg
if ((msg = get_osd_msg(mpctx))) {
if (strcmp(osd->osd_text, msg->msg)) {
- strncpy(osd->osd_text, msg->msg, 127);
+ osd_set_text(osd, msg->msg);
if (mpctx->sh_video)
vo_osd_changed(OSDTYPE_OSD);
else if (opts->term_osd)
@@ -1774,20 +1771,21 @@ static void update_osd_msg(struct MPContext *mpctx)
}
if (opts->osd_level == 3)
- snprintf(osd_text_timer, 63,
+ snprintf(osd_text_timer, sizeof(osd_text_timer),
"%c %02d:%02d:%02d%s / %02d:%02d:%02d%s",
mpctx->osd_function, pts / 3600, (pts / 60) % 60, pts % 60,
fractions_text, len / 3600, (len / 60) % 60, len % 60,
percentage_text);
else
- snprintf(osd_text_timer, 63, "%c %02d:%02d:%02d%s%s",
+ snprintf(osd_text_timer, sizeof(osd_text_timer),
+ "%c %02d:%02d:%02d%s%s",
mpctx->osd_function, pts / 3600, (pts / 60) % 60,
pts % 60, fractions_text, percentage_text);
} else
osd_text_timer[0] = 0;
if (strcmp(osd->osd_text, osd_text_timer)) {
- strncpy(osd->osd_text, osd_text_timer, 63);
+ osd_set_text(osd, osd_text_timer);
vo_osd_changed(OSDTYPE_OSD);
}
return;