{"record":{"id":"a79cec97a0478879","repo":"Yalantis/uCrop","slug":"save-raw-specified-filename-is-null","errorCode":null,"errorMessage":"save_raw(): Specified filename is (null).","messagePattern":"save_raw\\(\\): Specified filename is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":63410,"sourceCode":"       \\note The .raw format does not store the image dimensions in the output file,\n       so you have to keep track of them somewhere to be able to read the file correctly afterwards.\n    **/\n    const CImg<T>& save_raw(const char *const filename, const bool is_multiplexed=false) const {\n      return _save_raw(0,filename,is_multiplexed);\n    }\n\n    //! Save image as a raw data file \\overloading.\n    /**\n       Same as save_raw(const char *,bool) const\n       with a file stream argument instead of a filename string.\n    **/\n    const CImg<T>& save_raw(std::FILE *const file, const bool is_multiplexed=false) const {\n      return _save_raw(file,0,is_multiplexed);\n    }\n\n    const CImg<T>& _save_raw(std::FILE *const file, const char *const filename, const bool is_multiplexed) const {\n      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_raw(): 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      if (pixel_type()==cimg::type<bool>::string()) { // Boolean data (bitwise)\n        ulongT siz;\n        const unsigned char *const buf = _bool2uchar(siz,is_multiplexed);\n        cimg::fwrite(buf,siz,nfile);\n        delete[] buf;\n      } else { // Non boolean data\n        if (!is_multiplexed || _spectrum==1) cimg::fwrite(_data,size(),nfile); // Non-multiplexed\n        else { // Multiplexed\n          CImg<T> buf(_spectrum);\n          cimg_forXYZ(*this,x,y,z) {\n            cimg_forC(*this,c) buf[c] = (*this)(x,y,z,c);\n            cimg::fwrite(buf._data,_spectrum,nfile);\n          }","sourceCodeStart":63392,"sourceCodeEnd":63428,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L63392-L63428","documentation":"save_raw() dumps raw pixel data to a FILE* or a filename. The internal _save_raw helper requires at least one of the two to be non-null and throws CImgArgumentException otherwise. It is an immediate argument-contract check before any data is written.","triggerScenarios":"Calling save_raw() with no filename and no FILE*, or passing NULL explicitly to _save_raw(file=0, filename=0, ...).","commonSituations":"Building the output path dynamically and passing a null pointer, or calling the FILE*-only overload believing a filename was stored internally.","solutions":["Pass a filename: img.save_raw(\"out.cimg\", false).","Or open a FILE* yourself and call img.save_raw(fp, is_multiplexed).","Validate the path string is non-null and non-empty before calling."],"exampleFix":"// before\nconst char *name = getPath(); // may be NULL\nimg.save_raw(name);\n// after\nconst char *name = getPath();\nif (!name) name = \"default.raw\";\nimg.save_raw(name);","handlingStrategy":"validation","validationCode":"if (!fname || !*fname) fname = \"data.raw\";\nimg.save_raw(fname, /*is_multiplexed*/false);","typeGuard":"bool validPath(const char *p) { return p != nullptr && p[0] != '\\0'; }","tryCatchPattern":"try { img.save_raw(file?file:path.c_str()); }\ncatch (cimg_library::CImgArgumentException &e) { std::fprintf(stderr, \"save_raw needs FILE* or filename: %s\\n\", e.what()); }","preventionTips":["Decide up front whether you write to a FILE* or a path, and pass exactly one.","Null-check dynamically built paths before the call.","Wrap save calls in a utility that enforces the contract."],"tags":["cimg","null-argument","file-save","raw-format"],"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"}