{"record":{"id":"4ea1c7a287979dc9","repo":"Yalantis/uCrop","slug":"save-pfm-specified-filename-is-null","errorCode":null,"errorMessage":"save_pfm(): Specified filename is (null).","messagePattern":"save_pfm\\(\\): Specified filename is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":62481,"sourceCode":"\n    //! Save image as a PFM file.\n    /**\n      \\param filename Filename, as a C-string.\n    **/\n    const CImg<T>& save_pfm(const char *const filename) const {\n      get_mirror('y')._save_pfm(0,filename);\n      return *this;\n    }\n\n    //! Save image as a PFM file \\overloading.\n    const CImg<T>& save_pfm(std::FILE *const file) const {\n      get_mirror('y')._save_pfm(file,0);\n      return *this;\n    }\n\n    const CImg<T>& _save_pfm(std::FILE *const file, const char *const filename) const {\n      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_pfm(): Specified filename is (null).\",\n                                    cimg_instance);\n      if (is_empty()) { cimg::fempty(file,filename); return *this; }\n      if (_depth>1)\n        cimg::warn(_cimg_instance\n                   \"save_pfm(): Instance is volumetric, only the first slice will be saved in file '%s'.\",\n                   cimg_instance,\n                   filename?filename:\"(FILE*)\");\n      if (_spectrum>3)\n        cimg::warn(_cimg_instance\n                   \"save_pfm(): image instance is multispectral, only the three first channels will be saved \"\n                   \"in file '%s'.\",\n                   cimg_instance,\n                   filename?filename:\"(FILE*)\");\n\n      std::FILE *const nfile = file?file:cimg::fopen(filename,\"wb\");\n      const T\n        *ptr_r = data(0,0,0,0),","sourceCodeStart":62463,"sourceCodeEnd":62499,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L62463-L62499","documentation":"Raised by _save_pfm()'s argument-validation guard when both the output FILE* and the filename are null, so the library has nowhere to write the PFM data (the '(null)' text is its way of printing the missing filename). This is a generic sentinel error, not a filesystem failure; pass either an open file handle or a destination filename.","triggerScenarios":"Calling save_pfm((std::FILE*)0) or _save_pfm(file,0) with a null file; forwarding a null filename through generic save-dispatch code.","commonSituations":"HDR pipeline where the PFM output path is optional but save_pfm is still invoked; fopen failure unchecked; null path from CLI/config defaults.","solutions":["Provide a valid filename to save_pfm()","Open a FILE* yourself and pass it to the FILE* overload","Guard the call site: only call save_pfm when a destination exists"],"exampleFix":"// before\nif (saveHdr) img.save_pfm(hdrPath.empty() ? NULL : hdrPath.c_str());\n// after\nif (saveHdr && !hdrPath.empty()) img.save_pfm(hdrPath.c_str());","handlingStrategy":"validation","validationCode":"if (!file && (!filename || !*filename)) throw std::invalid_argument(\"save_pfm requires a filename or FILE*\");","typeGuard":"bool hasDestination(std::FILE *f, const char *name) { return f != NULL || (name != NULL && name[0] != '\\0'); }","tryCatchPattern":"try { img.save_pfm(path.c_str()); } catch (CImgArgumentException &e) { /* handle */ }","preventionTips":["Only invoke optional-format saves when the destination is configured","Validate empty strings as well as nulls","Centralize output-path resolution in one checked helper"],"tags":["null-argument","image-io","api-misuse"],"backgroundTag":"null-argument","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}