{"record":{"id":"847ad02f5112bef8","repo":"Yalantis/uCrop","slug":"load-bmp-specified-filename-is-null","errorCode":null,"errorMessage":"load_bmp(): Specified filename is (null).","messagePattern":"load_bmp\\(\\): Specified filename is \\(null\\)\\.","errorType":"validation","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":56774,"sourceCode":"\n    //! Load image from a BMP file \\newinstance.\n    static CImg<T> get_load_bmp(const char *const filename) {\n      return CImg<T>().load_bmp(filename);\n    }\n\n    //! Load image from a BMP file \\overloading.\n    CImg<T>& load_bmp(std::FILE *const file) {\n      return _load_bmp(file,0);\n    }\n\n    //! Load image from a BMP file \\newinstance.\n    static CImg<T> get_load_bmp(std::FILE *const file) {\n      return CImg<T>().load_bmp(file);\n    }\n\n    CImg<T>& _load_bmp(std::FILE *const file, const char *const filename) {\n      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"load_bmp(): Specified filename is (null).\",\n                                    cimg_instance);\n\n      const ulongT fsiz = (ulongT)(file?cimg::fsize(file):cimg::fsize(filename));\n      std::FILE *const nfile = file?file:cimg::fopen(filename,\"rb\");\n      CImg<ucharT> header(54);\n      cimg::fread(header._data,54,nfile);\n      if (*header!='B' || header[1]!='M') {\n        if (!file) cimg::fclose(nfile);\n        throw CImgIOException(_cimg_instance\n                              \"load_bmp(): Invalid BMP file '%s'.\",\n                              cimg_instance,\n                              filename?filename:\"(FILE*)\");\n      }\n\n      // Read header and pixel buffer.\n      int\n        file_size = header[0x02] + (header[0x03]<<8) + (header[0x04]<<16) + (header[0x05]<<24),","sourceCodeStart":56756,"sourceCodeEnd":56792,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L56756-L56792","documentation":"Raised by the internal _load_bmp() guard when both the std::FILE* argument and the filename string are null, meaning the caller gave no data source at all (the '(null)' in the message is how CImg prints the missing filename). It is a generic input-validation sentinel: the faulting input is the null filename/file handle. Pass either an open FILE* or a valid filename.","triggerScenarios":"Calling load_bmp(nullptr) or the file/filename dispatch overload with both arguments NULL.","commonSituations":"Path variable never initialized; upstream code that clears the filename on error then retries the load; misuse of get_load_bmp wrapper chains.","solutions":["Pass a valid filename or FILE* to load_bmp.","Null-check the path before the call and surface a domain-specific error.","Use load() with the filename and let CImg dispatch by extension/magic if format is uncertain."],"exampleFix":"// before\nimg.load_bmp(file); // file==nullptr and filename==nullptr\n// after\nif (filename) img.load_bmp(filename);\nelse if (file) img.load_bmp(file);\nelse throw std::runtime_error(\"no BMP source\");","handlingStrategy":"type-guard","validationCode":"if (!path && !file) throw std::invalid_argument(\"load_bmp requires a filename or FILE*\");","typeGuard":"bool hasBmpSource(std::FILE* f, const char* name){ return f != nullptr || name != nullptr; }","tryCatchPattern":"try { img.load_bmp(path); } catch (cimg_library::CImgArgumentException& e) { /* null source */ }","preventionTips":["Initialize path variables before loader calls","Use img.load(path) to let CImg pick the loader"],"tags":["cimg","null-argument","bmp"],"backgroundTag":"missing-required-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"}