summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-12-22 23:13:59 +0100
committerwm4 <wm4@nowhere>2013-12-22 23:25:10 +0100
commit88fd763e18b42fbcaaa7738212cfeb1b6b37e8f3 (patch)
treea66ca2bac130e8e042b4d4a2a829f9277a467466
parentffcf4ece6e69764dde0ee6a4e796e97151259cd9 (diff)
downloadmpv-88fd763e18b42fbcaaa7738212cfeb1b6b37e8f3.tar.bz2
mpv-88fd763e18b42fbcaaa7738212cfeb1b6b37e8f3.tar.xz
player: simplify mp_load_per_file_config
Get rid of the stupid and error-prone buffer size calculations, use snprintf instead of strcpy.
-rw-r--r--player/configfiles.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/player/configfiles.c b/player/configfiles.c
index b3804c0bd0..e506d0453e 100644
--- a/player/configfiles.c
+++ b/player/configfiles.c
@@ -89,23 +89,22 @@ static void mp_load_per_file_config(struct MPContext *mpctx)
{
struct MPOpts *opts = mpctx->opts;
char *confpath;
- char cfg[MP_PATH_MAX];
- const char *name;
+ char cfg[512];
const char *file = mpctx->filename;
- if (strlen(file) > MP_PATH_MAX - 14) {
+ if (snprintf(cfg, sizeof(cfg), "%s.conf", file) >= sizeof(cfg)) {
MP_WARN(mpctx, "Filename is too long, "
"can not load file or directory specific config files\n");
return;
}
- sprintf(cfg, "%s.conf", file);
- name = mp_basename(cfg);
+ char *name = mp_basename(cfg);
+
if (opts->use_filedir_conf) {
- char dircfg[MP_PATH_MAX];
- strcpy(dircfg, cfg);
- strcpy(dircfg + (name - cfg), "mpv.conf");
+ bstr dir = mp_dirname(cfg);
+ char *dircfg = mp_path_join(NULL, dir, bstr0("mpv.conf"));
try_load_config(mpctx, dircfg, FILE_LOCAL_FLAGS);
+ talloc_free(dircfg);
if (try_load_config(mpctx, cfg, FILE_LOCAL_FLAGS))
return;