{"record":{"id":"a4dfc468916f5430","repo":"Yalantis/uCrop","slug":"save-medcon-external-specified-filename-is-nul","errorCode":null,"errorMessage":"save_medcon_external(): Specified filename is (null).","messagePattern":"save_medcon_external\\(\\): Specified filename is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":63828,"sourceCode":"                              \"save_imagemagick_external(): Failed to save file '%s' with \"\n                              \"external command 'magick/convert'.\",\n                              cimg_instance,\n                              filename);\n\n      std::remove(filename_tmp);\n      return *this;\n    }\n\n    //! Save image as a Dicom file.\n    /**\n       \\param filename Filename, as a C-string.\n       \\note This method uses \\c medcon, an external executable binary provided by\n         <a href=\"http://xmedcon.sourceforge.net\">(X)Medcon</a>.\n       It must be installed for the method to succeed.\n    **/\n    const CImg<T>& save_medcon_external(const char *const filename) const {\n      if (!filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_medcon_external(): Specified filename is (null).\",\n                                    cimg_instance);\n      if (is_empty()) { cimg::fempty(0,filename); return *this; }\n\n      CImg<charT> command(1024), filename_tmp(256), body(256);\n      do {\n        cimg_snprintf(filename_tmp,filename_tmp._width,\"%s.hdr\",cimg::filenamerand());\n      } while (cimg::path_exists(filename_tmp));\n      save_analyze(filename_tmp);\n      cimg_snprintf(command,command._width,\"\\\"%s\\\" -w -c dicom -o \\\"%s\\\" -f \\\"%s\\\"\",\n                    cimg::medcon_path(),\n                    CImg<charT>::string(filename)._system_strescape().data(),\n                    CImg<charT>::string(filename_tmp)._system_strescape().data());\n      if (cimg::system(command,cimg::medcon_path())!=0)\n        throw CImgIOException(_cimg_instance\n                                \"save_medcon_external(): Failed to save file '%s' with external command 'medcon'.\",\n                                cimg_instance,\n                                filename);","sourceCodeStart":63810,"sourceCodeEnd":63846,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L63810-L63846","documentation":"Argument guard in CImg<T>::save_medcon_external(): both the FILE* and the filename are null, so there is no path to pass to the external '(x)medcon' executable that performs the actual Dicom conversion.","triggerScenarios":"Calling save_medcon_external(nullptr) or passing a char* that was never initialized or was set to NULL by a failed path lookup.","commonSituations":"DICOM export pipelines where the output filename comes from user input or config that resolved to null; forgetting to check getenv()/config results before the save call.","solutions":["Validate the filename is non-NULL before calling save_medcon_external().","Fix the code path that produced a NULL filename.","Supply a default DICOM output path when none is configured.","Use std::string and pass .c_str() only when non-empty."],"exampleFix":"// before\nconst char* dicomPath = cfg.get(\"dicom_out\"); // may return NULL\nimg.save_medcon_external(dicomPath);\n// after\nconst char* dicomPath = cfg.get(\"dicom_out\");\nif (!dicomPath) dicomPath = \"out.dcm\";\nimg.save_medcon_external(dicomPath);","handlingStrategy":"type-guard","validationCode":"if (!filename || !*filename) { /* substitute default or fail fast */ }","typeGuard":"bool validPath(const char* p) { return p != nullptr && *p != '\\0'; }","tryCatchPattern":"try {\n  img.save_medcon_external(filename);\n} catch (CImgArgumentException& e) {\n  std::fprintf(stderr, \"null filename: %s\", e.what());\n}","preventionTips":["Validate all path inputs at the pipeline boundary before they reach CImg.","Never pass through raw getenv()/config results without a NULL check.","Centralize filename resolution so NULL cannot reach save calls."],"tags":["null-pointer","argument-validation","dicom","medcon"],"backgroundTag":"null-argument","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}