[MPlayer-cvslog] r38234 - in trunk: command.c libmenu/menu.c libmenu/menu_console.c libmenu/menu_filesel.c libmpcodecs/vf.c libmpdemux/demux_film.c libmpdemux/demux_mov.c libvo/vo_gif89a.c libvo/vo_md5sum.c m_confi...
reimar
subversion at mplayerhq.hu
Sat Jan 23 20:22:14 EET 2021
Author: reimar
Date: Sat Jan 23 20:22:13 2021
New Revision: 38234
Log:
Remove usage of variable-length stack arrays.
They have a couple of issues like complicating
stack hardening, stack sizes can be very different
and thus failures particularly unpredictable but
also compiler support is not universal.
In particular MSVC does not support it.
As a side benefit, at least some of the
code becomes easier to understand.
Modified:
trunk/command.c
trunk/libmenu/menu.c
trunk/libmenu/menu_console.c
trunk/libmenu/menu_filesel.c
trunk/libmpcodecs/vf.c
trunk/libmpdemux/demux_film.c
trunk/libmpdemux/demux_mov.c
trunk/libvo/vo_gif89a.c
trunk/libvo/vo_md5sum.c
trunk/m_config.c
trunk/m_option.c
trunk/m_property.c
trunk/mplayer.c
trunk/stream/freesdp/parser.c
Modified: trunk/command.c
==============================================================================
--- trunk/command.c Sat Jan 23 20:22:09 2021 (r38233)
+++ trunk/command.c Sat Jan 23 20:22:13 2021 (r38234)
@@ -1314,10 +1314,10 @@ static int mp_property_gamma(m_option_t
#ifdef CONFIG_TV
if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
- int l = strlen(prop->name);
- char tv_prop[3 + l + 1];
- sprintf(tv_prop, "tv_%s", prop->name);
- return mp_property_do(tv_prop, action, arg, mpctx);
+ char *tv_prop = av_asprintf("tv_%s", prop->name);
+ r = mp_property_do(tv_prop, action, arg, mpctx);
+ av_freep(&tv_prop);
+ return r;
}
#endif
Modified: trunk/libmenu/menu.c
==============================================================================
--- trunk/libmenu/menu.c Sat Jan 23 20:22:09 2021 (r38233)
+++ trunk/libmenu/menu.c Sat Jan 23 20:22:13 2021 (r38234)
@@ -747,17 +747,14 @@ void menu_draw_box(mp_image_t* mpi,unsig
{
int stride = (w+15)&(~15); // round to 16
-#if HAVE_LOCAL_ALIGNED
- DECLARE_ALIGNED(16, char, pic)[stride];
- DECLARE_ALIGNED(16, char, pic_alpha)[stride];
-#else
- char pic[stride],pic_alpha[stride];
-#endif
+ char *pic = av_malloc(2*stride);
+ char *pic_alpha = pic + stride;
memset(pic,g,stride);
memset(pic_alpha,alpha,stride);
draw_alpha(w,h,pic,pic_alpha,0,
mpi->planes[0] + y * mpi->stride[0] + x * (mpi->bpp>>3),
mpi->stride[0]);
+ av_freep(&pic);
}
}
Modified: trunk/libmenu/menu_console.c
==============================================================================
--- trunk/libmenu/menu_console.c Sat Jan 23 20:22:09 2021 (r38233)
+++ trunk/libmenu/menu_console.c Sat Jan 23 20:22:13 2021 (r38234)
@@ -32,6 +32,8 @@
#include <unistd.h>
#include <errno.h>
+#include "libavutil/mem.h"
+#include "libavutil/avstring.h"
#include "libmpcodecs/img_format.h"
#include "libmpcodecs/mp_image.h"
@@ -217,12 +219,12 @@ static void draw(menu_t* menu, mp_image_
menu_draw_box(mpi,mpriv->bg,mpriv->bg_alpha,0,0,mpi->w,h);
if(!mpriv->child || !mpriv->raw_child){
- char input[strlen(mpriv->cur_history->buffer) + strlen(mpriv->prompt) + 1];
- sprintf(input,"%s%s",mpriv->prompt,mpriv->cur_history->buffer);
+ char *input = av_asprintf("%s%s",mpriv->prompt,mpriv->cur_history->buffer);
menu_text_size(input,w,mpriv->vspace,1,&lw,&lh);
menu_draw_text_full(mpi,input,x,y,w,h,mpriv->vspace,1,
MENU_TEXT_BOT|MENU_TEXT_LEFT,
MENU_TEXT_BOT|MENU_TEXT_LEFT);
+ av_freep(&input);
y -= lh + mpriv->vspace;
}
@@ -342,10 +344,9 @@ static int run_shell_cmd(menu_t* menu, c
static void enter_cmd(menu_t* menu) {
history_t* h;
- char input[strlen(mpriv->cur_history->buffer) + strlen(mpriv->prompt) + 1];
-
- sprintf(input,"%s%s",mpriv->prompt,mpriv->cur_history->buffer);
+ char *input = av_asprintf("%s%s",mpriv->prompt,mpriv->cur_history->buffer);
add_line(mpriv,input);
+ av_freep(&input);
if(mpriv->history == mpriv->cur_history) {
if(mpriv->history_size >= mpriv->history_max) {
Modified: trunk/libmenu/menu_filesel.c
==============================================================================
--- trunk/libmenu/menu_filesel.c Sat Jan 23 20:22:09 2021 (r38233)
+++ trunk/libmenu/menu_filesel.c Sat Jan 23 20:22:13 2021 (r38234)
@@ -142,12 +142,13 @@ static char* replace_path(char* title ,
}
static int mylstat(char *dir, char *file,struct stat* st) {
- int l = strlen(dir) + strlen(file);
- char s[l+2];
+ int res;
+ char *s = av_asprintf("%s/%s",dir,file);
+ int l = strlen(s);
if (!strcmp("..", file)) {
char *slash;
l -= 3;
- strcpy(s, dir);
+ s[l+1] = 0;
#if HAVE_DOS_PATHS
if (s[l] == '/' || s[l] == '\\')
#else
@@ -159,13 +160,12 @@ static int mylstat(char *dir, char *file
if (!slash)
slash = strrchr(s,'\\');
#endif
- if (!slash)
- return stat(dir,st);
- slash[1] = '\0';
- return stat(s,st);
+ if (slash)
+ slash[1] = '\0';
}
- sprintf(s,"%s/%s",dir,file);
- return stat(s,st);
+ res = stat(s,st);
+ av_freep(&s);
+ return res;
}
static int compare(const void *av, const void *bv){
@@ -373,26 +373,22 @@ static void read_cmd(menu_t* menu,int cm
}
free(p);
} else { // File and directory dealt with action string.
- int fname_len = strlen(mpriv->dir) + strlen(mpriv->p.current->p.txt) + 1;
- char filename[fname_len];
- char *str;
char *action = mpriv->p.current->d ? mpriv->dir_action:mpriv->file_action;
- sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt);
- str = replace_path(action, filename,1);
+ char *filename = av_asprintf("%s%s",mpriv->dir,mpriv->p.current->p.txt);
+ char *str = replace_path(action, filename,1);
mp_input_parse_and_queue_cmds(str);
if (str != action)
free(str);
+ av_freep(&filename);
}
} break;
case MENU_CMD_ACTION: {
- int fname_len = strlen(mpriv->dir) + strlen(mpriv->p.current->p.txt) + 1;
- char filename[fname_len];
- char *str;
- sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt);
- str = replace_path(action, filename,1);
+ char *filename = av_asprintf("%s%s",mpriv->dir,mpriv->p.current->p.txt);
+ char *str = replace_path(action, filename,1);
mp_input_parse_and_queue_cmds(str);
if(str != action)
free(str);
+ av_freep(&filename);
} break;
default:
menu_list_read_cmd(menu,cmd);
Modified: trunk/libmpcodecs/vf.c
==============================================================================
--- trunk/libmpcodecs/vf.c Sat Jan 23 20:22:09 2021 (r38233)
+++ trunk/libmpcodecs/vf.c Sat Jan 23 20:22:13 2021 (r38234)
@@ -513,12 +513,13 @@ vf_instance_t* vf_open_filter(vf_instanc
l += 1 + strlen(args[2*i]) + 1 + strlen(args[2*i+1]);
l += strlen(name);
{
- char str[l+1];
+ char *str = malloc(l+1);
char* p = str;
p += sprintf(str,"%s",name);
for(i = 0 ; args && args[2*i] ; i++)
p += sprintf(p," %s=%s",args[2*i],args[2*i+1]);
mp_msg(MSGT_VFILTER,MSGL_INFO,MSGTR_OpeningVideoFilter "[%s]\n",str);
+ free(str);
}
} else if(strcmp(name,"vo")) {
if(args && strcmp(args[0],"_oldargs_") == 0)
Modified: trunk/libmpdemux/demux_film.c
==============================================================================
--- trunk/libmpdemux/demux_film.c Sat Jan 23 20:22:09 2021 (r38233)
+++ trunk/libmpdemux/demux_film.c Sat Jan 23 20:22:13 2021 (r38234)
@@ -148,21 +148,23 @@ static int demux_film_fill_buffer(demuxe
if (sh_audio->wf->nChannels == 2) {
if (sh_audio->wf->wBitsPerSample == 8) {
unsigned char* tmp = dp->buffer;
- unsigned char buf[film_chunk.chunk_size];
+ unsigned char* buf = malloc(film_chunk.chunk_size);
for(i = 0; i < film_chunk.chunk_size/2; i++) {
buf[i*2] = tmp[i];
buf[i*2+1] = tmp[film_chunk.chunk_size/2+i];
}
memcpy( tmp, buf, film_chunk.chunk_size );
+ free(buf);
}
else {/* for 16bit */
unsigned short* tmp = dp->buffer;
- unsigned short buf[film_chunk.chunk_size/2];
+ unsigned short* buf = malloc(film_chunk.chunk_size);
for(i = 0; i < film_chunk.chunk_size/4; i++) {
buf[i*2] = tmp[i];
buf[i*2+1] = tmp[film_chunk.chunk_size/4+i];
}
memcpy( tmp, buf, film_chunk.chunk_size );
+ free(buf);
}
}
Modified: trunk/libmpdemux/demux_mov.c
==============================================================================
--- trunk/libmpdemux/demux_mov.c Sat Jan 23 20:22:09 2021 (r38233)
+++ trunk/libmpdemux/demux_mov.c Sat Jan 23 20:22:13 2021 (r38234)
@@ -1527,8 +1527,9 @@ static void lschunks(demuxer_t* demuxer,
case MOV_FOURCC(0xa9,'s','w','r'):
{
off_t text_len = stream_read_word(demuxer->stream);
- char text[text_len+2+1];
- stream_read(demuxer->stream, (char *)&text, text_len+2);
+ if (text_len >> 16) { udta_size = 0; break; } // eof
+ char *text = malloc(text_len+2+1);
+ stream_read(demuxer->stream, text, text_len+2);
text[text_len+2] = 0x0;
switch(udta_id)
{
@@ -1581,6 +1582,7 @@ static void lschunks(demuxer_t* demuxer,
mp_msg(MSGT_DEMUX, MSGL_V, " Source providers: %s\n", &text[2]);
break;
}
+ free(text);
udta_size -= 4+text_len;
break;
}
Modified: trunk/libvo/vo_gif89a.c
==============================================================================
--- trunk/libvo/vo_gif89a.c Sat Jan 23 20:22:09 2021 (r38233)
+++ trunk/libvo/vo_gif89a.c Sat Jan 23 20:22:13 2021 (r38234)
@@ -268,9 +268,9 @@ static void check_events(void) {}
static int gif_reduce(int width, int height, uint8_t *src, uint8_t *dst, GifColorType *colors)
{
- unsigned char Ra[width * height];
- unsigned char Ga[width * height];
- unsigned char Ba[width * height];
+ unsigned char *Ra = malloc(3*width * height);
+ unsigned char *Ga = Ra + width * height;
+ unsigned char *Ba = Ga + width * height;
unsigned char *R, *G, *B;
int size = 256;
int i;
@@ -284,7 +284,9 @@ static int gif_reduce(int width, int hei
}
R = Ra; G = Ga; B = Ba;
- return QuantizeBuffer(width, height, &size, R, G, B, dst, colors);
+ i = QuantizeBuffer(width, height, &size, R, G, B, dst, colors);
+ free(Ra);
+ return i;
}
static void flip_page(void)
Modified: trunk/libvo/vo_md5sum.c
==============================================================================
--- trunk/libvo/vo_md5sum.c Sat Jan 23 20:22:09 2021 (r38233)
+++ trunk/libvo/vo_md5sum.c Sat Jan 23 20:22:13 2021 (r38234)
@@ -66,6 +66,7 @@ const LIBVO_EXTERN (md5sum)
char *md5sum_outfile = NULL;
+struct AVMD5 *md5_context;
FILE *md5sum_fd;
int framenum = 0;
@@ -153,6 +154,8 @@ static int config(uint32_t width, uint32
exit_player(EXIT_ERROR);
}
+ md5_context = av_md5_alloc();
+
return 0;
}
@@ -195,8 +198,6 @@ static uint32_t draw_image(mp_image_t *m
uint32_t strideU = mpi->stride[1];
uint32_t strideV = mpi->stride[2];
- uint8_t md5_context_memory[av_md5_size];
- struct AVMD5 *md5_context = (struct AVMD5*) md5_context_memory;
unsigned int i;
if (mpi->flags & MP_IMGFLAG_PLANAR) { /* Planar */
@@ -266,6 +267,7 @@ static void uninit(void)
free(md5sum_outfile);
md5sum_outfile = NULL;
if (md5sum_fd && md5sum_fd != stdout) fclose(md5sum_fd);
+ av_freep(&md5_context);
}
/* ------------------------------------------------------------------------- */
Modified: trunk/m_config.c
==============================================================================
--- trunk/m_config.c Sat Jan 23 20:22:09 2021 (r38233)
+++ trunk/m_config.c Sat Jan 23 20:22:13 2021 (r38234)
@@ -29,6 +29,7 @@
#include <assert.h>
#endif
+#include "libavutil/common.h"
#include "libavutil/avstring.h"
#include "m_config.h"
#include "m_option.h"
@@ -110,10 +111,9 @@ static int show_profile(m_option_t *opt,
p->desc ? p->desc : "");
config->profile_depth++;
for (i = 0; i < p->num_opts; i++) {
- char spc[config->profile_depth + 1];
- for (j = 0; j < config->profile_depth; j++)
- spc[j] = ' ';
- spc[config->profile_depth] = '\0';
+ char spc[MAX_PROFILE_DEPTH + 1];
+ memset(spc, ' ', MAX_PROFILE_DEPTH);
+ spc[FFMIN(config->profile_depth, MAX_PROFILE_DEPTH)] = '\0';
mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s%s=%s\n", spc,
p->opts[2 * i], p->opts[2 * i + 1]);
@@ -123,12 +123,11 @@ static int show_profile(m_option_t *opt,
char *e, *list = p->opts[2 * i + 1];
while ((e = strchr(list, ','))) {
int l = e-list;
- char tmp[l+1];
if (!l)
continue;
- memcpy(tmp, list, l);
- tmp[l] = '\0';
+ char *tmp = av_strndup(list, l);
show_profile(opt, name, tmp);
+ av_freep(&tmp);
list = e+1;
}
if (list[0] != '\0')
@@ -449,9 +448,9 @@ m_config_parse_option(const m_config_t *
int l = strlen(co->name) + 1 + strlen(lst[2*i]) + 1;
if(r >= 0) {
// Build the full name
- char n[l];
- sprintf(n,"%s:%s",co->name,lst[2*i]);
+ char *n = av_asprintf("%s:%s",co->name,lst[2*i]);
sr = m_config_parse_option(config,n,lst[2*i+1],set);
+ av_freep(&n);
if(sr < 0){
if(sr == M_OPT_UNKNOWN){
mp_msg(MSGT_CFGPARSER, MSGL_ERR,MSGTR_InvalidSuboption,co->name,lst[2*i]);
Modified: trunk/m_option.c
==============================================================================
--- trunk/m_option.c Sat Jan 23 20:22:09 2021 (r38233)
+++ trunk/m_option.c Sat Jan 23 20:22:13 2021 (r38234)
@@ -36,6 +36,7 @@
#include "stream/url.h"
#include "libavutil/avstring.h"
#include "libavutil/attributes.h"
+#include "libavutil/mem.h"
// Don't free for 'production' atm
#ifndef MP_DEBUG
@@ -1813,9 +1814,7 @@ static int parse_obj_settings_list(const
else if(av_strcasecmp(n,"-clr") == 0)
op = OP_CLR;
else {
- char prefix[len];
- strncpy(prefix,opt->name,len-1);
- prefix[len-1] = '\0';
+ char *prefix = av_strndup(opt->name, len-1);
mp_msg(MSGT_VFILTER,MSGL_ERR, "Option %s: unknown postfix %s\n"
"Supported postfixes are:\n"
" %s-add\n"
@@ -1827,6 +1826,7 @@ static int parse_obj_settings_list(const
" Negative index can be used (i.e. -1 is the last element)\n\n"
" %s-clr\n"
" Clear the current list.\n",name,n,prefix,prefix,prefix,prefix);
+ av_freep(&prefix);
return M_OPT_UNKNOWN;
}
@@ -2196,10 +2196,9 @@ static int parse_custom_url(const m_opti
mp_msg(MSGT_CFGPARSER, MSGL_WARN, "Option %s: This URL doesn't have a hostname part.\n",name);
// skip
} else {
- char tmp[pos2-pos1+1];
- strncpy(tmp,ptr1, pos2-pos1);
- tmp[pos2-pos1] = '\0';
+ char *tmp = av_strndup(ptr1, pos2-pos1);
r = m_struct_set(desc,dst,"hostname",tmp);
+ av_freep(&tmp);
if(r < 0) {
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %s: Error while setting hostname.\n",name);
return r;
Modified: trunk/m_property.c
==============================================================================
--- trunk/m_property.c Sat Jan 23 20:22:09 2021 (r38233)
+++ trunk/m_property.c Sat Jan 23 20:22:13 2021 (r38234)
@@ -27,6 +27,7 @@
#include <inttypes.h>
#include <unistd.h>
+#include "libavutil/mem.h"
#include "m_option.h"
#include "m_property.h"
#include "mp_msg.h"
@@ -41,10 +42,9 @@ static int do_action(const m_option_t* p
int r;
if((sep = strchr(name,'/')) && sep[1]) {
int len = sep-name;
- char base[len+1];
- memcpy(base,name,len);
- base[len] = 0;
+ char *base = av_strndup(name, len);
prop = m_option_list_find(prop_list, base);
+ av_freep(&base);
ka.key = sep+1;
ka.action = action;
ka.arg = arg;
@@ -150,29 +150,27 @@ char* m_properties_expand_string(const m
lvl--, str++, l = 0;
} else if(str[0] == '$' && str[1] == '{' && (e = strchr(str+2,'}'))) {
int pl = e-str-2;
- char pname[pl+1];
- memcpy(pname,str+2,pl);
- pname[pl] = 0;
+ char *pname = av_strndup(str+2, pl);
if(m_property_do(prop_list, pname,
M_PROPERTY_PRINT, &p, ctx) >= 0 && p)
l = strlen(p), fr = 1;
else
l = 0;
+ av_freep(&pname);
str = e+1;
} else if(str[0] == '?' && str[1] == '(' && (e = strchr(str+2,':'))) {
lvl++;
if(!skip) {
int is_not = str[2] == '!';
int pl = e - str - (is_not ? 3 : 2);
- char pname[pl+1];
- memcpy(pname, str + (is_not ? 3 : 2), pl);
- pname[pl] = 0;
+ char *pname = av_strndup(str + (is_not ? 3 : 2), pl);
if(m_property_do(prop_list,pname,M_PROPERTY_GET,NULL,ctx) < 0) {
if (!is_not)
skip = 1, skip_lvl = lvl;
}
else if (is_not)
skip = 1, skip_lvl = lvl;
+ av_freep(&pname);
}
str = e+1, l = 0;
} else
Modified: trunk/mplayer.c
==============================================================================
--- trunk/mplayer.c Sat Jan 23 20:22:09 2021 (r38233)
+++ trunk/mplayer.c Sat Jan 23 20:22:13 2021 (r38234)
@@ -890,7 +890,7 @@ static void parse_cfgfiles(m_config_t *c
static void load_per_protocol_config(m_config_t *conf, const char *const file)
{
char *str;
- char protocol[strlen(PROFILE_CFG_PROTOCOL) + strlen(file) + 1];
+ char *protocol;
m_profile_t *p;
/* does filename actually uses a protocol ? */
@@ -898,13 +898,14 @@ static void load_per_protocol_config(m_c
if (!str)
return;
- sprintf(protocol, "%s%s", PROFILE_CFG_PROTOCOL, file);
- protocol[strlen(PROFILE_CFG_PROTOCOL) + strlen(file) - strlen(str)] = '\0';
+ protocol = av_asprintf("%s%s", PROFILE_CFG_PROTOCOL, file);
+ *strstr(protocol, "://") = 0;
p = m_config_get_profile(conf, protocol);
if (p) {
mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_LoadingProtocolProfile, protocol);
m_config_set_profile(conf, p);
}
+ av_freep(&protocol);
}
#define PROFILE_CFG_EXTENSION "extension."
@@ -912,7 +913,7 @@ static void load_per_protocol_config(m_c
static void load_per_extension_config(m_config_t *conf, const char *const file)
{
char *str;
- char extension[strlen(PROFILE_CFG_EXTENSION) + 8];
+ char extension[sizeof(PROFILE_CFG_EXTENSION) + 7];
m_profile_t *p;
/* does filename actually have an extension ? */
@@ -920,8 +921,7 @@ static void load_per_extension_config(m_
if (!str)
return;
- sprintf(extension, PROFILE_CFG_EXTENSION);
- strncat(extension, ++str, 7);
+ snprintf(extension, sizeof(extension), "%s%s", PROFILE_CFG_EXTENSION, ++str);
p = m_config_get_profile(conf, extension);
if (p) {
mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_LoadingExtensionProfile, extension);
@@ -934,15 +934,15 @@ static void load_per_extension_config(m_
static void load_per_output_config(m_config_t *conf, char *cfg, char *out)
{
- char profile[strlen(cfg) + strlen(out) + 1];
m_profile_t *p;
- sprintf(profile, "%s%s", cfg, out);
+ char *profile = av_asprintf("%s%s", cfg, out);
p = m_config_get_profile(conf, profile);
if (p) {
mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_LoadingExtensionProfile, profile);
m_config_set_profile(conf, p);
}
+ av_freep(&profile);
}
/**
Modified: trunk/stream/freesdp/parser.c
==============================================================================
--- trunk/stream/freesdp/parser.c Sat Jan 23 20:22:09 2021 (r38233)
+++ trunk/stream/freesdp/parser.c Sat Jan 23 20:22:13 2021 (r38234)
@@ -67,10 +67,10 @@ fsdp_parse (const char *text_description
const char *p = text_description, *p2;
unsigned int j;
/* temps for sscanf */
- const unsigned int TEMPCHARS = 6;
+#define TEMPCHARS 6
char fsdp_buf[TEMPCHARS][MAXSHORTFIELDLEN];
char longfsdp_buf[MAXLONGFIELDLEN];
- const unsigned int TEMPINTS = 2;
+#define TEMPINTS 2
unsigned long int wuint[TEMPINTS];
if ((NULL == text_description) || (NULL == dsc))
@@ -912,7 +912,8 @@ fsdp_parse_c (const char **p, fsdp_netwo
fsdp_address_type_t * atype,
fsdp_connection_address_t * address)
{
- const unsigned int TEMPCHARS = 3;
+#undef TEMPCHARS
+#define TEMPCHARS 3
char fsdp_buf[TEMPCHARS][MAXSHORTFIELDLEN];
if (!strncmp (*p, "c=", 2))
More information about the MPlayer-cvslog
mailing list