vf_psnr/ssim: don't crash if stats_file is NULL.

This commit is contained in:
Ronald S. Bultje 2015-10-22 18:00:40 -04:00
parent a60539bb5e
commit 0c7b44a01c
2 changed files with 26 additions and 22 deletions

View File

@ -193,17 +193,19 @@ static av_cold int init(AVFilterContext *ctx)
s->min_mse = +INFINITY; s->min_mse = +INFINITY;
s->max_mse = -INFINITY; s->max_mse = -INFINITY;
if (!strcmp(s->stats_file_str, "-")) { if (s->stats_file_str) {
s->stats_file = stdout; if (!strcmp(s->stats_file_str, "-")) {
} else if (s->stats_file_str) { s->stats_file = stdout;
s->stats_file = fopen(s->stats_file_str, "w"); } else {
if (!s->stats_file) { s->stats_file = fopen(s->stats_file_str, "w");
int err = AVERROR(errno); if (!s->stats_file) {
char buf[128]; int err = AVERROR(errno);
av_strerror(err, buf, sizeof(buf)); char buf[128];
av_log(ctx, AV_LOG_ERROR, "Could not open stats file %s: %s\n", av_strerror(err, buf, sizeof(buf));
s->stats_file_str, buf); av_log(ctx, AV_LOG_ERROR, "Could not open stats file %s: %s\n",
return err; s->stats_file_str, buf);
return err;
}
} }
} }

View File

@ -223,17 +223,19 @@ static av_cold int init(AVFilterContext *ctx)
{ {
SSIMContext *s = ctx->priv; SSIMContext *s = ctx->priv;
if (!strcmp(s->stats_file_str, "-")) { if (s->stats_file_str) {
s->stats_file = stdout; if (!strcmp(s->stats_file_str, "-")) {
} else if (s->stats_file_str) { s->stats_file = stdout;
s->stats_file = fopen(s->stats_file_str, "w"); } else {
if (!s->stats_file) { s->stats_file = fopen(s->stats_file_str, "w");
int err = AVERROR(errno); if (!s->stats_file) {
char buf[128]; int err = AVERROR(errno);
av_strerror(err, buf, sizeof(buf)); char buf[128];
av_log(ctx, AV_LOG_ERROR, "Could not open stats file %s: %s\n", av_strerror(err, buf, sizeof(buf));
s->stats_file_str, buf); av_log(ctx, AV_LOG_ERROR, "Could not open stats file %s: %s\n",
return err; s->stats_file_str, buf);
return err;
}
} }
} }