From 31e35fcf7b1023335d4658d65d4a75be83bae0fb Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Tue, 15 Sep 2015 18:00:52 +0200 Subject: [PATCH] preventde seg fault when unknown long options and fixed ability to use USE_SYSTEM_GETOPT --- applications/codec/image_to_j2k.c | 14 ++++++++------ applications/codec/j2k_dump.c | 6 ++++-- applications/codec/j2k_to_image.c | 10 ++++++---- tests/CMakeLists.txt | 26 +++++++++++++++++++++++--- tests/conformance/CMakeLists.txt | 2 +- 5 files changed, 42 insertions(+), 16 deletions(-) diff --git a/applications/codec/image_to_j2k.c b/applications/codec/image_to_j2k.c index d9cafd6a..297d19a2 100644 --- a/applications/codec/image_to_j2k.c +++ b/applications/codec/image_to_j2k.c @@ -591,7 +591,9 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param {"POC",REQ_ARG, NULL ,'P'}, {"ROI",REQ_ARG, NULL ,'R'}, {"jpip",NO_ARG, NULL, 'J'}, - {0,0,0,0} /* GNU getopt_long requirement */ +#ifdef USE_SYSTEM_GETOPT + {0,0,0,0} /* GNU getopt_long requirement */ +#endif }; /* parse the command line */ @@ -601,7 +603,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param #endif /* USE_JPWL */ "h"; - totlen=sizeof(long_option)-1; + totlen=sizeof(long_option); img_fol->set_out_format=0; raw_cp->rawWidth = 0; @@ -1391,10 +1393,10 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param /* ------------------------------------------------------ */ - default: - fprintf(stderr, "ERROR -> Command line not valid\n"); - return 1; - } + default: + fprintf(stderr, "[WARNING] An invalid option has been ignored\n"); + break; + } }while(c != -1); /* check for possible errors */ diff --git a/applications/codec/j2k_dump.c b/applications/codec/j2k_dump.c index 63cce3a2..3b321a45 100644 --- a/applications/codec/j2k_dump.c +++ b/applications/codec/j2k_dump.c @@ -201,13 +201,15 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i int totlen, c; opj_option_t long_option[]={ {"ImgDir",REQ_ARG, NULL ,'y'}, +#ifdef USE_SYSTEM_GETOPT {0,0,0,0} /* GNU getopt_long requirement */ +#endif }; const char optlist[] = "i:o:h"; OPJ_ARG_NOT_USED(indexfilename); - totlen=sizeof(long_option)-1; + totlen=sizeof(long_option); img_fol->set_out_format = 0; do { #ifdef USE_SYSTEM_GETOPT @@ -265,7 +267,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i /* ----------------------------------------------------- */ default: - fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, opj_optarg); + fprintf(stderr,"[WARNING] An invalid option has been ignored\n"); break; } }while(c != -1); diff --git a/applications/codec/j2k_to_image.c b/applications/codec/j2k_to_image.c index 6f215a2c..43dc7c35 100644 --- a/applications/codec/j2k_to_image.c +++ b/applications/codec/j2k_to_image.c @@ -242,8 +242,10 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param int totlen, c; opj_option_t long_option[]={ {"ImgDir",REQ_ARG, NULL ,'y'}, - {"OutFor",REQ_ARG, NULL ,'O'}, - {0,0,0,0} /* GNU getopt_long requirement */ + {"OutFor",REQ_ARG, NULL ,'O'}, +#ifdef USE_SYSTEM_GETOPT + {0,0,0,0} /* GNU getopt_long requirement */ +#endif }; const char optlist[] = "i:o:r:l:x:" @@ -254,7 +256,7 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param #endif /* USE_JPWL */ /* <set_out_format = 0; do { #ifdef USE_SYSTEM_GETOPT @@ -461,7 +463,7 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param /* ----------------------------------------------------- */ default: - fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, opj_optarg); + fprintf(stderr,"[WARNING] An invalid option has been ignored\n"); break; } }while(c != -1); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index af4fbcef..feee0835 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,14 +12,34 @@ include_directories( set(compare_images_SRCS compare_images.c ${OPENJPEG_SOURCE_DIR}/applications/codec/convert.c # ${OPENJPEG_SOURCE_DIR}/applications/codec/converttif.c - ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c +# ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c ) +if(NOT USE_SYSTEM_GETOPT) + list(APPEND compare_images_SRCS + ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c + ) +endif() + set(compare_dump_files_SRCS compare_dump_files.c - ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c) + #${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c + ) + +if(NOT USE_SYSTEM_GETOPT) + list(APPEND compare_dump_files_SRCS + ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c + ) +endif() set(compare_raw_files_SRCS compare_raw_files.c - ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c) + #${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c + ) + +if(NOT USE_SYSTEM_GETOPT) + list(APPEND compare_raw_files_SRCS + ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c + ) +endif() add_executable(compare_images ${compare_images_SRCS}) target_link_libraries(compare_images diff --git a/tests/conformance/CMakeLists.txt b/tests/conformance/CMakeLists.txt index 9554e5de..8e17469c 100644 --- a/tests/conformance/CMakeLists.txt +++ b/tests/conformance/CMakeLists.txt @@ -510,7 +510,7 @@ foreach(kdu_file ${kdu_j2k_conf_files}) set( filenameInput "${kdu_file}.j2c" ) set( filenameRef "${kdu_file}.ppm" ) - if("${kdu_file}" STREQUAL "a6_mono_colr") + if("${kdu_file}" STREQUAL "a6_mono_colr") set(kdu_test_args -upsample -split-pnm ) else() set(kdu_test_args -upsample )