Yalantis/uCrop · error · CImgArgumentException

save_medcon_external(): Specified filename is (null).

Error message

save_medcon_external(): Specified filename is (null).

What it means

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.

Source

Thrown at ucrop/src/main/jni/CImg.h:63828

                              "save_imagemagick_external(): Failed to save file '%s' with "
                              "external command 'magick/convert'.",
                              cimg_instance,
                              filename);

      std::remove(filename_tmp);
      return *this;
    }

    //! Save image as a Dicom file.
    /**
       \param filename Filename, as a C-string.
       \note This method uses \c medcon, an external executable binary provided by
         <a href="http://xmedcon.sourceforge.net">(X)Medcon</a>.
       It must be installed for the method to succeed.
    **/
    const CImg<T>& save_medcon_external(const char *const filename) const {
      if (!filename)
        throw CImgArgumentException(_cimg_instance
                                    "save_medcon_external(): Specified filename is (null).",
                                    cimg_instance);
      if (is_empty()) { cimg::fempty(0,filename); return *this; }

      CImg<charT> command(1024), filename_tmp(256), body(256);
      do {
        cimg_snprintf(filename_tmp,filename_tmp._width,"%s.hdr",cimg::filenamerand());
      } while (cimg::path_exists(filename_tmp));
      save_analyze(filename_tmp);
      cimg_snprintf(command,command._width,"\"%s\" -w -c dicom -o \"%s\" -f \"%s\"",
                    cimg::medcon_path(),
                    CImg<charT>::string(filename)._system_strescape().data(),
                    CImg<charT>::string(filename_tmp)._system_strescape().data());
      if (cimg::system(command,cimg::medcon_path())!=0)
        throw CImgIOException(_cimg_instance
                                "save_medcon_external(): Failed to save file '%s' with external command 'medcon'.",
                                cimg_instance,
                                filename);

View on GitHub (pinned to f788b534b4)

Solutions

  1. Validate the filename is non-NULL before calling save_medcon_external().
  2. Fix the code path that produced a NULL filename.
  3. Supply a default DICOM output path when none is configured.
  4. Use std::string and pass .c_str() only when non-empty.

Example fix

// before
const char* dicomPath = cfg.get("dicom_out"); // may return NULL
img.save_medcon_external(dicomPath);
// after
const char* dicomPath = cfg.get("dicom_out");
if (!dicomPath) dicomPath = "out.dcm";
img.save_medcon_external(dicomPath);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!filename || !*filename) { /* substitute default or fail fast */ }

Type guard

bool validPath(const char* p) { return p != nullptr && *p != '\0'; }

Try / catch

try {
  img.save_medcon_external(filename);
} catch (CImgArgumentException& e) {
  std::fprintf(stderr, "null filename: %s", e.what());
}

Prevention

When it happens

Trigger: Calling save_medcon_external(nullptr) or passing a char* that was never initialized or was set to NULL by a failed path lookup.

Common situations: 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.

Related errors


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/a4dfc468916f5430. Report an issue: GitHub.