{"record":{"id":"a401184fa11d9dda","repo":"Yalantis/uCrop","slug":"load-inr-specified-filename-is-null","errorCode":null,"errorMessage":"load_inr(): Specified filename is (null).","messagePattern":"load_inr\\(\\): Specified filename is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":58709,"sourceCode":"        throw CImgIOException(\"CImg<%s>::load_inr(): Big/Little Endian coding type undefined in header.\",\n                              pixel_type());\n    }\n\n    CImg<T>& _load_inr(std::FILE *const file, const char *const filename, float *const voxel_size) {\n#define _cimg_load_inr_case(Tf,sign,pixsize,Ts) \\\n     if (!loaded && fopt[6]==pixsize && fopt[4]==Tf && fopt[5]==sign) { \\\n        Ts *xval, *const val = new Ts[(size_t)fopt[0]*fopt[3]]; \\\n        cimg_forYZ(*this,y,z) { \\\n            cimg::fread(val,fopt[0]*fopt[3],nfile); \\\n            if (fopt[7]!=endian) cimg::invert_endianness(val,fopt[0]*fopt[3]); \\\n            xval = val; cimg_forX(*this,x) cimg_forC(*this,c) (*this)(x,y,z,c) = (T)*(xval++); \\\n          } \\\n        delete[] val; \\\n        loaded = true; \\\n      }\n\n      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"load_inr(): Specified filename is (null).\",\n                                    cimg_instance);\n\n      std::FILE *const nfile = file?file:cimg::fopen(filename,\"rb\");\n      int fopt[8], endian = cimg::endianness()?1:0;\n      bool loaded = false;\n      if (voxel_size) voxel_size[0] = voxel_size[1] = voxel_size[2] = 1;\n      _load_inr_header(nfile,fopt,voxel_size);\n      assign(fopt[0],fopt[1],fopt[2],fopt[3]);\n      _cimg_load_inr_case(0,0,8,unsigned char);\n      _cimg_load_inr_case(0,1,8,char);\n      _cimg_load_inr_case(0,0,16,unsigned short);\n      _cimg_load_inr_case(0,1,16,short);\n      _cimg_load_inr_case(0,0,32,unsigned int);\n      _cimg_load_inr_case(0,1,32,int);\n      _cimg_load_inr_case(1,0,32,float);\n      _cimg_load_inr_case(1,1,32,float);\n      _cimg_load_inr_case(1,0,64,double);","sourceCodeStart":58691,"sourceCodeEnd":58727,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L58691-L58727","documentation":"CImg's load_inr() loads INRIMAGE (.inr) volumetric image files. The library throws CImgArgumentException when both the std::FILE* handle and the filename C-string are null, because there is no source to read from. This is a pure API-misuse guard raised before any I/O happens.","triggerScenarios":"Calling load_inr(nullptr) on a default-constructed path, or passing a null filename with no open FILE*, e.g. CImg<float> img; img.load_inr(getenv(\"INR_FILE\")) when the env var is unset.","commonSituations":"Env vars or config values holding the file path are empty/null; a caller computed a path dynamically and it came back NULL; bindings passing null through from another language.","solutions":["Check the filename for null/empty before calling load_inr() and return an error early","Verify the variable or config value that supplies the path is actually populated","If using a FILE* variant, ensure the stream was successfully fopen-ed before passing it"],"exampleFix":"// before\nCImg<float> img;\nimg.load_inr(path); // path may be NULL\n// after\nif (!path || !*path) { fprintf(stderr, \"no INR file given\\n\"); return 1; }\nCImg<float> img;\nimg.load_inr(path);","handlingStrategy":"validation","validationCode":"if (!filename || !*filename) { throw std::invalid_argument(\"filename required for load_inr\"); }","typeGuard":"bool is_valid_path(const char *p) { return p != nullptr && *p != '\\0'; }","tryCatchPattern":"try { img.load_inr(path); } catch (const cimg_library::CImgArgumentException &e) { /* null/invalid argument */ log(e.what()); }","preventionTips":["Never pass raw getenv()/lookup results straight into loaders; check for null/empty first","Centralize path resolution in one helper that guarantees a valid string or throws","Prefer std::string over const char* in your code and only call c_str() after validation"],"tags":["cimg","image-loading","null-argument","inr"],"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"}