{"record":{"id":"7718e123d64396af","repo":"Yalantis/uCrop","slug":"save-dlm-specified-filename-is-null","errorCode":null,"errorMessage":"save_dlm(): Specified filename is (null).","messagePattern":"save_dlm\\(\\): Specified filename is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":61451,"sourceCode":"      return *this;\n    }\n\n    //! Save image as a DLM file.\n    /**\n       \\param filename Filename, as a C-string.\n    **/\n    const CImg<T>& save_dlm(const char *const filename) const {\n      return _save_dlm(0,filename);\n    }\n\n    //! Save image as a DLM file \\overloading.\n    const CImg<T>& save_dlm(std::FILE *const file) const {\n      return _save_dlm(file,0);\n    }\n\n    const CImg<T>& _save_dlm(std::FILE *const file, const char *const filename) const {\n      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_dlm(): 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_dlm(): Instance is volumetric, values along Z will be unrolled in file '%s'.\",\n                   cimg_instance,\n                   filename?filename:\"(FILE*)\");\n      if (_spectrum>1)\n        cimg::warn(_cimg_instance\n                   \"save_dlm(): Instance is multispectral, values along C will be unrolled in file '%s'.\",\n                   cimg_instance,\n                   filename?filename:\"(FILE*)\");\n\n      std::FILE *const nfile = file?file:cimg::fopen(filename,\"w\");\n      const T* ptrs = _data;\n      cimg_forYZC(*this,y,z,c) {\n        cimg_forX(*this,x) std::fprintf(nfile,\"%.17g%s\",(double)*(ptrs++),(x==width() - 1)?\"\":\",\");","sourceCodeStart":61433,"sourceCodeEnd":61469,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L61433-L61469","documentation":"save_dlm() writes the image as a Matrix Market-style delimited (DLM) text file; _save_dlm() throws CImgArgumentException when both the FILE* and filename are null, i.e., no output destination was given.","triggerScenarios":"Calling img.save_dlm((std::FILE*)NULL) or img.save_dlm((const char*)NULL); passing a NULL FILE* from a failed fopen to the FILE* overload.","commonSituations":"Exporting numeric data to MATLAB-compatible text where the output path came from an unset config value; fopen failures passed through.","solutions":["Pass a valid filename (e.g., img.save_dlm(\"data.txt\")).","Ensure the FILE* from fopen is non-NULL before the FILE* overload.","Null-check file and filename at the call site.","Log errno from fopen to fix the underlying open failure."],"exampleFix":"// before\nFILE* f = fopen(path, \"w\"); img.save_dlm(f);\n// after\nFILE* f = fopen(path, \"w\");\nif (!f) { perror(\"fopen\"); return; }\nimg.save_dlm(f); fclose(f);","handlingStrategy":"type-guard","validationCode":"if (!file && (!filename || !*filename)) { /* abort or use default path */ }","typeGuard":"bool hasDestination(std::FILE* f, const char* n){ return f!=nullptr || (n!=nullptr && *n!='\\0'); }","tryCatchPattern":"try { img.save_dlm(f); } catch (CImgArgumentException& e) { fprintf(stderr,\"DLM save failed: %s\\n\", e.what()); }","preventionTips":["Verify fopen success before the FILE* overload","Resolve config-driven output paths to concrete defaults","Prefer the filename overload for simple exports"],"tags":["cimg","save","null-pointer","dlm"],"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"}