- cp->comment = (char*)opj_malloc(strlen(parameters->cp_comment) + 1);
- if(cp->comment) {
- strcpy(cp->comment, parameters->cp_comment);
- }
- }
+ cp->comment = (char*)opj_malloc(strlen(parameters->cp_comment) + 1U);
+ if(!cp->comment) {
+ opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate copy of comment string\n");
+ return OPJ_FALSE;
+ }
+ strcpy(cp->comment, parameters->cp_comment);
+ } else {
+ /* Create default comment for codestream */
+ const char comment[] = "Created by OpenJPEG version ";
+ const size_t clen = strlen(comment);
+ const char *version = opj_version();
+
+ /* UniPG>> */
+#ifdef USE_JPWL
+ cp->comment = (char*)opj_malloc(clen+strlen(version)+11);
+ if(!cp->comment) {
+ opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate comment string\n");
+ return OPJ_FALSE;
+ }
+ sprintf(cp->comment,"%s%s with JPWL", comment, version);
+#else
+ cp->comment = (char*)opj_malloc(clen+strlen(version)+1);
+ if(!cp->comment) {
+ opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate comment string\n");
+ return OPJ_FALSE;
+ }
+ sprintf(cp->comment,"%s%s", comment, version);
+#endif
+ /* <<UniPG */
+ }