{"record":{"id":"6b00899195ccf5d0","repo":"Yalantis/uCrop","slug":"save-pandore-specified-filename-is-null","errorCode":null,"errorMessage":"save_pandore(): Specified filename is (null).","messagePattern":"save_pandore\\(\\): Specified filename is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":63285,"sourceCode":"          else if (sizeof(unsigned int)==4) { __cimg_save_pandore_case(unsigned int); } \\\n          else if (sizeof(unsigned short)==4) { __cimg_save_pandore_case(unsigned short); } \\\n          else throw CImgIOException(_cimg_instance \\\n                                     \"save_pandore(): Unsupported datatype for file '%s'.\",\\\n                                     cimg_instance, \\\n                                     filename?filename:\"(FILE*)\"); \\\n        } else if (id==4 || id==7 || id==10 || id==18 || id==21 || id==25 || id==29 || id==33) { \\\n          if (sizeof(double)==4) { __cimg_save_pandore_case(double); } \\\n          else if (sizeof(float)==4) { __cimg_save_pandore_case(float); } \\\n          else throw CImgIOException(_cimg_instance \\\n                                     \"save_pandore(): Unsupported datatype for file '%s'.\",\\\n                                     cimg_instance, \\\n                                     filename?filename:\"(FILE*)\"); \\\n        } \\\n        saved = true; \\\n      }\n\n      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_pandore(): Specified filename is (null).\",\n                                    cimg_instance);\n      if (is_empty()) { cimg::fempty(file,filename); return *this; }\n\n      std::FILE *const nfile = file?file:cimg::fopen(filename,\"wb\");\n      unsigned char header[36] = { 'P','A','N','D','O','R','E','0','4',0,0,0,\n                                   0,0,0,0,'C','I','m','g',0,0,0,0,0,\n                                   'N','o',' ','d','a','t','e',0,0,0,0 };\n      unsigned int nbdims, dims[5] = {};\n      bool saved = false;\n      _cimg_save_pandore_case(1,1,1,\"uint8\",2);\n      _cimg_save_pandore_case(1,1,1,\"int8\",3);\n      _cimg_save_pandore_case(1,1,1,\"uint16\",3);\n      _cimg_save_pandore_case(1,1,1,\"int16\",3);\n      _cimg_save_pandore_case(1,1,1,\"uint32\",3);\n      _cimg_save_pandore_case(1,1,1,\"int32\",3);\n      _cimg_save_pandore_case(1,1,1,\"uint64\",3);\n      _cimg_save_pandore_case(1,1,1,\"int64\",3);","sourceCodeStart":63267,"sourceCodeEnd":63303,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L63267-L63303","documentation":"CImg's save_pandore() writes the image in the PANDORE file format to either a FILE* or a filename. Because it needs one of the two output targets, it throws CImgArgumentException when both are null. This is a pure caller-contract check performed before any I/O happens.","triggerScenarios":"Calling save_pandore() with no arguments (default filename is 0/null) or explicitly passing NULL as the filename while also not passing a FILE*.","commonSituations":"Passing a std::string's c_str() from a variable that was never set, propagating an empty/null path from upper layers, or accidentally calling the no-argument overload expecting a default file name.","solutions":["Pass a valid non-null filename, e.g. img.save_pandore(\"out.pan\").","If writing to an already-open stream, pass the std::FILE* instead of a filename.","Guard the path upstream: if (path && *path) img.save_pandore(path); else handle the missing path."],"exampleFix":"// before\nimg.save_pandore(); // filename defaults to 0\n// after\nimg.save_pandore(\"output.pan\");","handlingStrategy":"validation","validationCode":"if (!filename || !*filename) { /* choose default or abort */ filename = \"output.pan\"; }\nimg.save_pandore(filename);","typeGuard":"bool hasOutputTarget(std::FILE *f, const char *name) { return f != nullptr || (name != nullptr && name[0] != '\\0'); }","tryCatchPattern":"try { img.save_pandore(path.c_str()); }\ncatch (cimg_library::CImgArgumentException &e) { std::fprintf(stderr, \"bad save args: %s\\n\", e.what()); }","preventionTips":["Always pass std::string::c_str() of a checked, non-empty path.","Never rely on default arguments for output filenames.","Centralize saves in a helper that validates the path first."],"tags":["cimg","null-argument","file-save","argument-validation"],"backgroundTag":"null-argument","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}