Skip to content

Commit 159ce3f

Browse files
committed
vcomp/cmpto_j2k: j2k_compress_init improvements
- avoid goto - call _done + return NULL instead - use std::string as a container for cfg instead of alloca - in j2k_compress_done, mod must be cast directly to the state (priv_data not set at that point)
1 parent ec21f45 commit 159ce3f

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/video_compress/cmpto_j2k.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,8 @@ static struct module * j2k_compress_init(struct module *parent, const char *c_cf
651651

652652
auto *s = new state_video_compress_j2k();
653653

654-
char *tmp = (char *) alloca(strlen(c_cfg) + 1);
655-
strcpy(tmp, c_cfg);
654+
std::string cfg = c_cfg;
655+
char *tmp = &cfg[0];
656656
char *save_ptr, *item;
657657
while ((item = strtok_r(tmp, ":", &save_ptr))) {
658658
tmp = NULL;
@@ -679,13 +679,15 @@ static struct module * j2k_compress_init(struct module *parent, const char *c_cf
679679
return static_cast<module*>(INIT_NOERR);
680680
} else {
681681
log_msg(LOG_LEVEL_ERROR, "[J2K] Wrong option: %s\n", item);
682-
goto error;
682+
j2k_compress_done((struct module *) s);
683+
return nullptr;
683684
}
684685
}
685686

686687
if (s->quality < 0.0 || s->quality > 1.0) {
687688
LOG(LOG_LEVEL_ERROR) << "[J2K] Quality should be in interval [0-1]!\n";
688-
goto error;
689+
j2k_compress_done((struct module *) s);
690+
return nullptr;
689691
}
690692

691693
if (s->tech == nullptr) {
@@ -708,10 +710,6 @@ static struct module * j2k_compress_init(struct module *parent, const char *c_cf
708710
module_register(&s->module_data, parent);
709711

710712
return &s->module_data;
711-
712-
error:
713-
delete s;
714-
return NULL;
715713
}
716714

717715
static void j2k_compressed_frame_dispose(struct video_frame *frame)
@@ -840,8 +838,7 @@ static void j2k_compress_push(struct module *state, std::shared_ptr<video_frame>
840838

841839
static void j2k_compress_done(struct module *mod)
842840
{
843-
struct state_video_compress_j2k *s =
844-
(struct state_video_compress_j2k *) mod->priv_data;
841+
auto *s = (struct state_video_compress_j2k *) mod;
845842
cleanup_common(s);
846843
delete s;
847844
}

0 commit comments

Comments
 (0)