{"record":{"id":"f10a178a58164020","repo":"Yalantis/uCrop","slug":"save-analyze-specified-filename-is-null","errorCode":null,"errorMessage":"save_analyze(): Specified filename is (null).","messagePattern":"save_analyze\\(\\): Specified filename is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":62898,"sourceCode":"     else if (pixel_type()==cimg::type<int>::string())\n       wtr.setup_write_int();\n     else if (pixel_type()==cimg::type<double>::string())\n       wtr.setup_write_double();\n     else\n       wtr.setup_write_float();\n     minc::save_standard_volume(wtr, this->_data);\n     return *this;\n#endif\n    }\n\n    //! Save image as an ANALYZE7.5 or NIFTI file.\n    /**\n      \\param filename Filename, as a C-string.\n      \\param voxel_size Pointer to 3 consecutive values that tell about the voxel sizes along the X,Y and Z dimensions.\n    **/\n    const CImg<T>& save_analyze(const char *const filename, const float *const voxel_size=0) const {\n      if (!filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_analyze(): Specified filename is (null).\",\n                                    cimg_instance);\n      if (is_empty()) { cimg::fempty(0,filename); return *this; }\n\n      std::FILE *file;\n      CImg<charT> hname(1024), iname(1024);\n      const char *const ext = cimg::split_filename(filename);\n      short datatype = -1;\n      if (!*ext) {\n        cimg_snprintf(hname,hname._width,\"%s.hdr\",filename);\n        cimg_snprintf(iname,iname._width,\"%s.img\",filename);\n      }\n      if (!cimg::strncasecmp(ext,\"hdr\",3)) {\n        std::strcpy(hname,filename);\n        std::strncpy(iname,filename,iname._width - 1);\n        cimg_snprintf(iname._data + std::strlen(iname) - 3,4,\"img\");\n      }\n      if (!cimg::strncasecmp(ext,\"img\",3)) {","sourceCodeStart":62880,"sourceCodeEnd":62916,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L62880-L62916","documentation":"save_analyze() validates its filename argument up front and throws CImgArgumentException when it receives a null C-string, formatting the message with the literal '(null)'. It is a precondition check inside the Analyze 7.5 writer, fired before any header is built or file opened.","triggerScenarios":"Calling CImg::save_analyze(NULL) or passing a null filename through the generic save() dispatch; typically from an uninitialized pointer or an API that returned null instead of a path string.","commonSituations":"Config or environment lookup for the output path returned NULL; a concatenation helper failed silently and returned null; caller intended to use the FILE* overload but passed a null path instead.","solutions":["Validate the filename is non-null and non-empty before calling save_analyze and report which setting/argument was missing.","Correct the producer of the path string so a valid filename reaches the call.","Write to an already-open std::FILE* if that is what the caller actually has, instead of a null path.","Wrap the call in a helper that converts a null path into a meaningful exception naming the source of the path."],"exampleFix":"// before\nchar *name = cfg_get(\"analyze_output\"); // may be NULL\nimg.save_analyze(name);\n\n// after\nchar *name = cfg_get(\"analyze_output\");\nassert(name && *name);\nimg.save_analyze(name);","handlingStrategy":"validation","validationCode":"if (!filename || !*filename)\n  throw std::invalid_argument(\"save_analyze: filename is null or empty\");","typeGuard":"bool valid_path(const char* p) { return p != nullptr && *p != '\\0'; }","tryCatchPattern":"try {\n  img.save_analyze(path.c_str());\n} catch (const CImgArgumentException& e) {\n  std::fprintf(stderr, \"Analyze save failed, no filename: %s\\n\", e.what());\n}","preventionTips":["Check config/env lookups for null before use","Prefer std::string::c_str() from a populated string","Add a save wrapper that validates every filename argument"],"tags":["cimg","analyze","null-argument","filename"],"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"}