{"record":{"id":"edda7c414e4d5b4a","repo":"Yalantis/uCrop","slug":"load-magick-specified-filename-is-null","errorCode":null,"errorMessage":"load_magick(): Specified filename is (null).","messagePattern":"load_magick\\(\\): Specified filename is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":57266,"sourceCode":"            if (ptr_a) *(ptr_a++) = (T)*(ptrs++);\n          }\n        }\n      } break;\n      }\n      JxlDecoderDestroy(decoder);\n      return *this;\n#endif\n    }\n\n    //! Load image from a file, using Magick++ library.\n    /**\n       \\param filename Filename, as a C-string.\n    **/\n    // Added April/may 2006 by Christoph Hormann <chris_hormann@gmx.de>.\n    // This is experimental code, not much tested, use with care.\n    CImg<T>& load_magick(const char *const filename) {\n      if (!filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"load_magick(): Specified filename is (null).\",\n                                    cimg_instance);\n\n#ifdef cimg_use_magick\n      Magick::Image image(filename);\n      const unsigned int W = image.size().width(), H = image.size().height();\n      switch (image.type()) {\n      case Magick::PaletteMatteType :\n      case Magick::TrueColorMatteType :\n      case Magick::ColorSeparationType : {\n        assign(W,H,1,4);\n        T *ptr_r = data(0,0,0,0), *ptr_g = data(0,0,0,1), *ptr_b = data(0,0,0,2), *ptr_a = data(0,0,0,3);\n        Magick::PixelPacket *pixels = image.getPixels(0,0,W,H);\n        for (ulongT off = (ulongT)W*H; off; --off) {\n          *(ptr_r++) = (T)(pixels->red);\n          *(ptr_g++) = (T)(pixels->green);\n          *(ptr_b++) = (T)(pixels->blue);\n          *(ptr_a++) = (T)(pixels->opacity);","sourceCodeStart":57248,"sourceCodeEnd":57284,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L57248-L57284","documentation":"load_magick() validates its filename argument first: a NULL pointer cannot name any file, so CImg throws CImgArgumentException immediately. This is a caller programming error caught by defensive argument checking, thrown regardless of whether libMagick++ is enabled.","triggerScenarios":"Calling CImg<T>::load_magick(NULL), or passing the result of a lookup function that returned NULL (e.g. getenv of an unset var, failed path resolution).","commonSituations":"Path taken from a missing environment variable or failed string conversion; uninitialized char* members; C APIs returning NULL for 'not found' passed straight through.","solutions":["Ensure a non-NULL filename string is passed; check the source of the path before calling.","Provide a default path when the lookup can fail (e.g. getenv fallback).","Switch to std::string-based handling so empty/absent paths are caught before the C-string boundary."],"exampleFix":"// before\nconst char* p = getenv(\"IMG_PATH\");\nimg.load_magick(p); // NULL if unset\n// after\nconst char* p = getenv(\"IMG_PATH\");\nif (p) img.load_magick(p); else img.load_magick(\"/default/img.png\");","handlingStrategy":"validation","validationCode":"bool validPath(const char* p) { return p != nullptr && p[0] != '\\0'; }","typeGuard":null,"tryCatchPattern":"try { img.load_magick(path); } catch (CImgArgumentException& e) { log(\"null filename passed to load_magick\"); }","preventionTips":["Never pass C-strings from lookups (getenv, find) without a NULL check","Prefer std::string in your API and .c_str() only at the boundary","Assert non-null filenames in debug builds before image loads"],"tags":["null-argument","image-loading","imagemagick","cimg"],"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"}