{"record":{"id":"68c6d0b1b35833c9","repo":"Yalantis/uCrop","slug":"load-parrec-specified-filename-is-null","errorCode":null,"errorMessage":"load_parrec(): Specified filename is (null).","messagePattern":"load_parrec\\(\\): Specified filename is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":67025,"sourceCode":"      _cimg_load_cimg_case2(\"float64\",\"double\",0,cimg_float64);\n      if (!loaded) {\n        if (!file) cimg::fclose(nfile);\n        throw CImgIOException(_cimglist_instance\n                              \"load_cimg(): Unsupported pixel type '%s' for file '%s'.\",\n                              cimglist_instance,\n                              str_pixeltype._data,filename?filename:\"(FILE*)\");\n      }\n      if (!file) cimg::fclose(nfile);\n      return *this;\n    }\n\n    //! Load a list from a PAR/REC (Philips) file.\n    /**\n      \\param filename Filename to read data from.\n    **/\n    CImgList<T>& load_parrec(const char *const filename) {\n      if (!filename)\n        throw CImgArgumentException(_cimglist_instance\n                                    \"load_parrec(): Specified filename is (null).\",\n                                    cimglist_instance);\n\n      CImg<charT> body(1024), filenamepar(1024), filenamerec(1024);\n      *body = *filenamepar = *filenamerec = 0;\n      const char *const ext = cimg::split_filename(filename,body);\n      if (!std::strcmp(ext,\"par\")) {\n        std::strncpy(filenamepar,filename,filenamepar._width - 1);\n        cimg_snprintf(filenamerec,filenamerec._width,\"%s.rec\",body._data);\n      }\n      if (!std::strcmp(ext,\"PAR\")) {\n        std::strncpy(filenamepar,filename,filenamepar._width - 1);\n        cimg_snprintf(filenamerec,filenamerec._width,\"%s.REC\",body._data);\n      }\n      if (!std::strcmp(ext,\"rec\")) {\n        std::strncpy(filenamerec,filename,filenamerec._width - 1);\n        cimg_snprintf(filenamepar,filenamepar._width,\"%s.par\",body._data);\n      }","sourceCodeStart":67007,"sourceCodeEnd":67043,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L67007-L67043","documentation":"CImgList::load_parrec() loads Philips PAR/REC MRI data from a file path, so a null filename is unusable. CImg validates the argument up front and throws CImgArgumentException instead of dereferencing null.","triggerScenarios":"Calling load_parrec(nullptr), or passing a char* string variable that is null (e.g. an unset config value or the result of a failed lookup) directly to load_parrec().","commonSituations":"Config/env variable holding the PAR file path never set; a failed getenv or dictionary lookup returning null passed straight through; C API interop where an optional path defaulted to null.","solutions":["Ensure a valid non-null filename string is passed (check before calling)","Guard the call site: skip or raise an application-level error when the path is missing","Fix the source of the null path (config key, env var, argv) and validate it at startup"],"exampleFix":"// before\nimgs.load_parrec(getenv(\"PAR_FILE\")); // NULL if unset\n// after\nconst char* par = getenv(\"PAR_FILE\");\nif (!par) { fprintf(stderr, \"PAR_FILE not set\\n\"); return 1; }\nimgs.load_parrec(par);","handlingStrategy":"type-guard","validationCode":"if (filename == nullptr || filename[0] == '\\0') { /* fail fast with app-level error */ }","typeGuard":"bool validPath(const char* p) { return p != nullptr && p[0] != '\\0'; }","tryCatchPattern":"try { imgs.load_parrec(path); }\ncatch (CImgArgumentException& e) { fprintf(stderr, \"PAR/REC path missing: %s\\n\", e.what()); }","preventionTips":["Validate config/env paths at startup, not at call time","Never pass getenv() results directly without a null check","Use std::string for paths and pass .c_str() only after validation"],"tags":["cimg","null-argument","file-loading","argument-validation"],"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"}