{"record":{"id":"6554779426a77a82","repo":"Yalantis/uCrop","slug":"save-rgb-specified-filename-is-null","errorCode":null,"errorMessage":"save_rgb(): Specified filename is (null).","messagePattern":"save_rgb\\(\\): Specified filename is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":62569,"sourceCode":"      return *this;\n    }\n\n    //! Save image as a RGB file.\n    /**\n      \\param filename Filename, as a C-string.\n    **/\n    const CImg<T>& save_rgb(const char *const filename) const {\n      return _save_rgb(0,filename);\n    }\n\n    //! Save image as a RGB file \\overloading.\n    const CImg<T>& save_rgb(std::FILE *const file) const {\n      return _save_rgb(file,0);\n    }\n\n    const CImg<T>& _save_rgb(std::FILE *const file, const char *const filename) const {\n      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_rgb(): Specified filename is (null).\",\n                                    cimg_instance);\n      if (is_empty()) { cimg::fempty(file,filename); return *this; }\n      if (_spectrum!=3)\n        cimg::warn(_cimg_instance\n                   \"save_rgb(): image instance has not exactly 3 channels, for file '%s'.\",\n                   cimg_instance,\n                   filename?filename:\"(FILE*)\");\n\n      std::FILE *const nfile = file?file:cimg::fopen(filename,\"wb\");\n      const ulongT wh = (ulongT)_width*_height;\n      unsigned char *const buffer = new unsigned char[3*wh], *nbuffer = buffer;\n      const T\n        *ptr1 = data(0,0,0,0),\n        *ptr2 = _spectrum>1?data(0,0,0,1):0,\n        *ptr3 = _spectrum>2?data(0,0,0,2):0;\n      switch (_spectrum) {\n      case 1 : { // Scalar image","sourceCodeStart":62551,"sourceCodeEnd":62587,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L62551-L62587","documentation":"Raised by _save_rgb()'s guard when both the FILE* and filename arguments are null, meaning no output destination was specified for the RGB data (the library prints the missing filename as '(null)'). It is a generic validation check that fires before any bytes are written; give the call a valid filename or open stream.","triggerScenarios":"Calling save_rgb((std::FILE*)0); passing a null FILE* from a failed fopen; generic save() dispatch reaching the rgb path with a null name.","commonSituations":"Unchecked fopen result in raw-dump utilities; empty filename variables in batch conversion scripts; incorrect overload selection passing 0 as filename.","solutions":["Pass a non-null filename to save_rgb()","Pass a valid opened FILE* instead of a null one","Validate the destination path/FILE* before invoking save_rgb()"],"exampleFix":"// before\nimg.save_rgb(name ? name.c_str() : NULL);\n// after\nif (name.empty()) throw std::invalid_argument(\"rgb output path required\");\nimg.save_rgb(name.c_str());","handlingStrategy":"validation","validationCode":"if (!file && (!filename || !*filename)) throw std::invalid_argument(\"save_rgb 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_rgb(path.c_str()); } catch (CImgArgumentException &e) { /* handle */ }","preventionTips":["Check fopen() results","Never pass literal NULL/0 as filename in raw-format saves","Sanitize CLI/config paths before use"],"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"}