{"record":{"id":"55b93fddd27a560b","repo":"Yalantis/uCrop","slug":"load-specified-filename-is-null","errorCode":null,"errorMessage":"load(): Specified filename is (null).","messagePattern":"load\\(\\): Specified filename is \\(null\\)\\.","errorType":"validation","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":56447,"sourceCode":"        }\n      }\n\n      disp._normalization = old_normalization;\n      if (x1>=0 && x1<x0) cimg::swap(x0,x1);\n      if (y1<y0) cimg::swap(y0,y1);\n      disp.set_key(okey);\n      return CImg<intT>(4,1,1,1,x0,y0,x1>=0?x1 + (int)one:-1,y1);\n    }\n\n    //! Load image from a file.\n    /**\n       \\param filename Filename, as a C-string.\n       \\note The extension of \\c filename defines the file format. If no filename\n       extension is provided, CImg<T>::get_load() will try to load the file as a .cimg or .cimgz file.\n    **/\n    CImg<T>& load(const char *const filename) {\n      if (!filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"load(): Specified filename is (null).\",\n                                    cimg_instance);\n\n      if (!cimg::strncasecmp(filename,\"http://\",7) || !cimg::strncasecmp(filename,\"https://\",8)) {\n        CImg<charT> filename_local(256);\n        load(cimg::load_network(filename,filename_local));\n        std::remove(filename_local);\n        return *this;\n      }\n\n      const char *const ext = cimg::split_filename(filename);\n      const unsigned int omode = cimg::exception_mode();\n      cimg::exception_mode(0);\n      bool is_loaded = true;\n      try {\n#ifdef cimg_load_plugin\n        cimg_load_plugin(filename);\n#endif","sourceCodeStart":56429,"sourceCodeEnd":56465,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L56429-L56465","documentation":"CImg<T>::load(filename) loads an image from disk or network, dispatching on the filename extension. A null filename pointer cannot be inspected, so the method immediately throws CImgArgumentException before attempting any I/O.","triggerScenarios":"Calling load(NULL) directly, or passing a char* filename variable that was never assigned or was freed/set to null after a failed path lookup.","commonSituations":"Filename built conditionally with one path leaving it null; getConfig-style helpers returning null when a key is missing; passing the result of a failed string conversion straight into load().","solutions":["Check for null before calling: if (filename) img.load(filename);","Ensure the filename string is initialized/allocated before the call.","Load into a std::string first, then pass .c_str() so it can never be null."],"exampleFix":"// before\nconst char* filename = getenvOptional(\"IMG\"); // may be NULL\nimg.load(filename);\n// after\nconst char* env = getenvOptional(\"IMG\");\nif (env) img.load(env);","handlingStrategy":"validation","validationCode":"if (!filename || !*filename) {\n  std::cerr << \"No filename provided for load\" << std::endl;\n  return;\n}\nimg.load(filename);","typeGuard":"bool hasFilename(const char* f) { return f != nullptr && f[0] != '\\0'; }","tryCatchPattern":"try {\n  img.load(filename);\n} catch (const cimg_library::CImgArgumentException& e) {\n  std::cerr << \"load() rejected arguments: \" << e.what() << std::endl;\n}","preventionTips":["Store filenames in std::string and pass .c_str() to guarantee non-null","Null-check outputs of config/env lookups before use","Centralize image loading in one helper that validates the path argument"],"tags":["cimg","file-loading","null-argument"],"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"}