{"record":{"id":"ff9aeb341cc1ed0c","repo":"Yalantis/uCrop","slug":"load-pnm-specified-filename-is-null","errorCode":null,"errorMessage":"load_pnm(): Specified filename is (null).","messagePattern":"load_pnm\\(\\): Specified filename is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":57560,"sourceCode":"\n    //! Load image from a PNM file \\newinstance.\n    static CImg<T> get_load_pnm(const char *const filename) {\n      return CImg<T>().load_pnm(filename);\n    }\n\n    //! Load image from a PNM file \\overloading.\n    CImg<T>& load_pnm(std::FILE *const file) {\n      return _load_pnm(file,0);\n    }\n\n    //! Load image from a PNM file \\newinstance.\n    static CImg<T> get_load_pnm(std::FILE *const file) {\n      return CImg<T>().load_pnm(file);\n    }\n\n    CImg<T>& _load_pnm(std::FILE *const file, const char *const filename) {\n      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"load_pnm(): Specified filename is (null).\",\n                                    cimg_instance);\n\n      std::FILE *const nfile = file?file:cimg::fopen(filename,\"rb\");\n      unsigned int ppm_type, W, H, D = 1, colormax = 255;\n      CImg<charT> item(16384,1,1,1,0);\n      int err, rval, gval, bval;\n      const longT cimg_iobuffer = (longT)24*1024*1024;\n      while ((err=std::fscanf(nfile,\"%16383[^\\n]\",item.data()))!=EOF && (*item=='#' || !err)) std::fgetc(nfile);\n      if (cimg_sscanf(item,\" P%u\",&ppm_type)!=1) {\n        if (!file) cimg::fclose(nfile);\n        throw CImgIOException(_cimg_instance\n                              \"load_pnm(): PNM header not found in file '%s'.\",\n                              cimg_instance,\n                              filename?filename:\"(FILE*)\");\n      }\n      while ((err=std::fscanf(nfile,\" %16383[^\\n]\",item.data()))!=EOF && (*item=='#' || !err)) std::fgetc(nfile);\n      if ((err=cimg_sscanf(item,\" %u %u %u %u\",&W,&H,&D,&colormax))<2) {","sourceCodeStart":57542,"sourceCodeEnd":57578,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L57542-L57578","documentation":"CImg's _load_pnm() throws CImgArgumentException when both the FILE* and filename are null — there is no input for the PNM/PPM/PGM loader. This is an argument-validation guard, analogous to the load_png null check.","triggerScenarios":"Calling load_pnm(nullptr) / load_pnm((const char*)0), or a wrapper passing an uninitialized/NULL filename with a null FILE* into _load_pnm.","commonSituations":"Filename built from an unset environment variable or missing config entry; a lookup function returning const char* NULL passed straight to load_pnm.","solutions":["Pass a valid path: img.load_pnm(\"image.ppm\").","Or pass an open FILE*: img.load_pnm(file).","Null-check/configure the source of the filename before calling."],"exampleFix":"// before\nconst char *p = cfg.get(\"pnm_path\"); // may be NULL\nimg.load_pnm(p);\n// after\nconst char *p = cfg.get(\"pnm_path\");\nif (!p) throw std::runtime_error(\"pnm_path not configured\");\nimg.load_pnm(p);","handlingStrategy":"validation","validationCode":"if (!filename && !file) throw std::invalid_argument(\"load_pnm requires a filename or FILE*\");\nimg.load_pnm(filename);","typeGuard":"bool hasSource(const char *f, std::FILE *h) { return f != nullptr || h != nullptr; }","tryCatchPattern":null,"preventionTips":["Validate config/argv-derived paths for null before loader calls","Use std::string to eliminate null filename states","Initialize filename pointers at declaration"],"tags":["cimg","argument-validation","null-pointer"],"backgroundTag":"null-argument","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}