{"record":{"id":"bd3d567fcef0c576","repo":"Yalantis/uCrop","slug":"save-rgba-specified-filename-is-null","errorCode":null,"errorMessage":"save_rgba(): Specified filename is (null).","messagePattern":"save_rgba\\(\\): Specified filename is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":62631,"sourceCode":"      return *this;\n    }\n\n    //! Save image as a RGBA file.\n    /**\n       \\param filename Filename, as a C-string.\n    **/\n    const CImg<T>& save_rgba(const char *const filename) const {\n      return _save_rgba(0,filename);\n    }\n\n    //! Save image as a RGBA file \\overloading.\n    const CImg<T>& save_rgba(std::FILE *const file) const {\n      return _save_rgba(file,0);\n    }\n\n    const CImg<T>& _save_rgba(std::FILE *const file, const char *const filename) const {\n      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_rgba(): Specified filename is (null).\",\n                                    cimg_instance);\n      if (is_empty()) { cimg::fempty(file,filename); return *this; }\n      if (_spectrum!=4)\n        cimg::warn(_cimg_instance\n                   \"save_rgba(): image instance has not exactly 4 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[4*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        *ptr4 = _spectrum>3?data(0,0,0,3):0;\n      switch (_spectrum) {","sourceCodeStart":62613,"sourceCodeEnd":62649,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L62613-L62649","documentation":"_save_rgba() throws CImgArgumentException when both the output FILE* and the filename are null, since the raw RGBA writer has nowhere to write. Like the sibling guards, it fails fast before image processing.","triggerScenarios":"Calling save_rgba((std::FILE*)0); a null filename propagated from save()/generic dispatch; forwarding a FILE* that is null because fopen failed.","commonSituations":"Framebuffer/texture dump code with an unset output file; null path from optional CLI argument; failed stream open not checked.","solutions":["Pass a valid filename to save_rgba()","Pass an opened, non-null FILE*","Check stream open success before the call"],"exampleFix":"// before\nstd::FILE *f = std::fopen(out, \"wb\");\nimg.save_rgba(f);\n// after\nstd::FILE *f = out ? std::fopen(out, \"wb\") : NULL;\nif (!f) throw std::runtime_error(\"cannot open rgba output\");\nimg.save_rgba(f);","handlingStrategy":"validation","validationCode":"if (!file && (!filename || !*filename)) throw std::invalid_argument(\"save_rgba 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_rgba(path.c_str()); } catch (CImgArgumentException &e) { /* handle */ }","preventionTips":["Verify streams are non-null before passing","Fail early when output path is empty","Use RAII file wrappers so null FILE* cannot propagate"],"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"}