From 09426b2a7ce5ceee3694b61daa579ddad25e7fa2 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Tue, 5 Oct 2021 10:26:42 +0200 Subject: [PATCH] print rather err msg on wrong unit_evaluate(_dbl) val Use an user-friendlier error message than assert. --- src/audio/codec.cpp | 8 +++++++- src/hd-rum-translator/hd-rum-translator.cpp | 5 ++++- src/main.cpp | 8 ++++++-- src/video_compress/cmpto_j2k.cpp | 8 ++++---- src/video_compress/libavcodec.cpp | 5 ++++- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/audio/codec.cpp b/src/audio/codec.cpp index 009dd13c3..acad9e114 100644 --- a/src/audio/codec.cpp +++ b/src/audio/codec.cpp @@ -137,6 +137,9 @@ static struct audio_codec_state *audio_codec_init_real(const char *audio_codec_c audio_codec_direction_t direction, bool silent) { audio_codec_t audio_codec = get_audio_codec(audio_codec_cfg); int bitrate = get_audio_codec_bitrate(audio_codec_cfg); + if (bitrate < 0) { + return nullptr; + } void *state = NULL; const struct audio_compress_info *aci = nullptr; @@ -385,7 +388,10 @@ int get_audio_codec_bitrate(const char *audio_codec_cfg) char *val = get_val_from_cfg(audio_codec_cfg, "bitrate="); if (val) { long long ret = unit_evaluate(val); - assert(ret > 0 && ret <= INT_MAX); + if (ret <= 0 && ret > INT_MAX) { + LOG(LOG_LEVEL_ERROR) << "Wrong bitrate: " << val << "\n"; + return -1; + } free(val); return ret; } else { diff --git a/src/hd-rum-translator/hd-rum-translator.cpp b/src/hd-rum-translator/hd-rum-translator.cpp index f2a65a161..29e03f175 100644 --- a/src/hd-rum-translator/hd-rum-translator.cpp +++ b/src/hd-rum-translator/hd-rum-translator.cpp @@ -658,7 +658,10 @@ static int parse_fmt(int argc, char **argv, struct cmdline_parameters *parsed) parsed->hosts[host_idx].bitrate = RATE_AUTO; } else { parsed->hosts[host_idx].bitrate = unit_evaluate(argv[i + 1]); - assert(parsed->hosts[host_idx].bitrate > 0); + if (parsed->hosts[host_idx].bitrate <= 0) { + LOG(LOG_LEVEL_FATAL) << MOD_NAME << "Error: wrong bitrate - " << argv[i + 1] << "\n"; + exit(EXIT_FAIL_USAGE); + } } break; case '4': diff --git a/src/main.cpp b/src/main.cpp index 257cc12a6..e08945c32 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -538,8 +538,12 @@ static bool parse_audio_capture_format(const char *optarg) } audio_capture_bps = bps / 8; } else if (strncmp(item, "sample_rate=", strlen("sample_rate=")) == 0) { - long long val = unit_evaluate(item + strlen("sample_rate=")); - assert(val > 0 && val <= numeric_limits::max()); + const char *sample_rate_str = item + strlen("sample_rate="); + long long val = unit_evaluate(sample_rate_str); + if (val <= 0 || val > numeric_limits::max()) { + LOG(LOG_LEVEL_ERROR) << "Invalid sample_rate " << sample_rate_str << "!\n"; + return false; + } audio_capture_sample_rate = val; } else { log_msg(LOG_LEVEL_ERROR, "Unkonwn format for --audio-capture-format!\n"); diff --git a/src/video_compress/cmpto_j2k.cpp b/src/video_compress/cmpto_j2k.cpp index 5df219a38..b9877651b 100644 --- a/src/video_compress/cmpto_j2k.cpp +++ b/src/video_compress/cmpto_j2k.cpp @@ -290,10 +290,6 @@ static struct module * j2k_compress_init(struct module *parent, const char *c_cf tmp = NULL; if (strncasecmp("rate=", item, strlen("rate=")) == 0) { bitrate = unit_evaluate(item + strlen("rate=")); - if (bitrate <= 0) { - log_msg(LOG_LEVEL_ERROR, "[J2K] Wrong bitrate!\n"); - return NULL; - } } else if (strncasecmp("quality=", item, strlen("quality=")) == 0) { quality = atof(item + strlen("quality=")); } else if (strcasecmp("mct", item) == 0 || strcasecmp("nomct", item) == 0) { @@ -311,7 +307,11 @@ static struct module * j2k_compress_init(struct module *parent, const char *c_cf log_msg(LOG_LEVEL_ERROR, "[J2K] Wrong option: %s\n", item); return NULL; } + } + if (bitrate <= 0 || mem_limit <= 0 || tile_limit <= 0) { + log_msg(LOG_LEVEL_ERROR, "[J2K] Wrong bitrate, mem_limit or tile_limit!\n"); + return NULL; } s = new state_video_compress_j2k(bitrate, pool_size, mct); diff --git a/src/video_compress/libavcodec.cpp b/src/video_compress/libavcodec.cpp index 1a2370255..0c0fc8a4f 100644 --- a/src/video_compress/libavcodec.cpp +++ b/src/video_compress/libavcodec.cpp @@ -406,7 +406,10 @@ static int parse_fmt(struct state_video_compress_libav *s, char *fmt) { } else if(strncasecmp("bpp=", item, strlen("bpp=")) == 0) { char *bpp_str = item + strlen("bpp="); s->requested_bpp = unit_evaluate_dbl(bpp_str); - assert(!std::isnan(s->requested_bpp)); + if (std::isnan(s->requested_bpp)) { + LOG(LOG_LEVEL_ERROR) << MOD_NAME "Wrong bitrate: " << bpp_str << "\n"; + return -1; + } } else if(strncasecmp("crf=", item, strlen("crf=")) == 0) { char *crf_str = item + strlen("crf="); s->requested_crf = atof(crf_str);