Yalantis/uCrop · error · CImgArgumentException
load_parrec(): Specified filename is (null).
Error message
load_parrec(): Specified filename is (null).
What it means
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.
Source
Thrown at ucrop/src/main/jni/CImg.h:67025
_cimg_load_cimg_case2("float64","double",0,cimg_float64);
if (!loaded) {
if (!file) cimg::fclose(nfile);
throw CImgIOException(_cimglist_instance
"load_cimg(): Unsupported pixel type '%s' for file '%s'.",
cimglist_instance,
str_pixeltype._data,filename?filename:"(FILE*)");
}
if (!file) cimg::fclose(nfile);
return *this;
}
//! Load a list from a PAR/REC (Philips) file.
/**
\param filename Filename to read data from.
**/
CImgList<T>& load_parrec(const char *const filename) {
if (!filename)
throw CImgArgumentException(_cimglist_instance
"load_parrec(): Specified filename is (null).",
cimglist_instance);
CImg<charT> body(1024), filenamepar(1024), filenamerec(1024);
*body = *filenamepar = *filenamerec = 0;
const char *const ext = cimg::split_filename(filename,body);
if (!std::strcmp(ext,"par")) {
std::strncpy(filenamepar,filename,filenamepar._width - 1);
cimg_snprintf(filenamerec,filenamerec._width,"%s.rec",body._data);
}
if (!std::strcmp(ext,"PAR")) {
std::strncpy(filenamepar,filename,filenamepar._width - 1);
cimg_snprintf(filenamerec,filenamerec._width,"%s.REC",body._data);
}
if (!std::strcmp(ext,"rec")) {
std::strncpy(filenamerec,filename,filenamerec._width - 1);
cimg_snprintf(filenamepar,filenamepar._width,"%s.par",body._data);
}View on GitHub (pinned to f788b534b4)
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
Example fix
// before
imgs.load_parrec(getenv("PAR_FILE")); // NULL if unset
// after
const char* par = getenv("PAR_FILE");
if (!par) { fprintf(stderr, "PAR_FILE not set\n"); return 1; }
imgs.load_parrec(par); Defensive patterns
Strategy: type-guard
Validate before calling
if (filename == nullptr || filename[0] == '\0') { /* fail fast with app-level error */ } Type guard
bool validPath(const char* p) { return p != nullptr && p[0] != '\0'; } Try / catch
try { imgs.load_parrec(path); }
catch (CImgArgumentException& e) { fprintf(stderr, "PAR/REC path missing: %s\n", e.what()); } Prevention
- 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
When it happens
Trigger: 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().
Common situations: 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.
Related errors
- load(): Specified filename is (null).
- save_pandore(): Specified filename is (null).
- cimg::ftype(): Specified filename is (null).
- cimg::fopen(): Specified file path is (null).
- cimg::fopen(): File '%s', specified mode is (null).
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/68c6d0b1b35833c9.
Report an issue: GitHub.