{"record":{"id":"bc9fa3e308d1eaa2","repo":"Yalantis/uCrop","slug":"data-invalid-pointer-request-at-position-u","errorCode":null,"errorMessage":"data(): Invalid pointer request, at position [%u].","messagePattern":"data\\(\\): Invalid pointer request, at position \\[%u\\]\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":64900,"sourceCode":"    **/\n    CImg<T> *data() {\n      return _data;\n    }\n\n    //! Return pointer to the first image of the list \\const.\n    const CImg<T> *data() const {\n      return _data;\n    }\n\n    //! Return pointer to the pos-th image of the list.\n    /**\n       \\param pos Index of the image element to access.\n       \\note <tt>list.data(n);</tt> is equivalent to <tt>list.data + n;</tt>.\n    **/\n#if cimg_verbosity>=3\n    CImg<T> *data(const unsigned int pos) {\n      if (pos>=size())\n        cimg::warn(_cimglist_instance\n                   \"data(): Invalid pointer request, at position [%u].\",\n                   cimglist_instance,\n                   pos);\n      return _data + pos;\n    }\n\n    const CImg<T> *data(const unsigned int l) const {\n      return const_cast<CImgList<T>*>(this)->data(l);\n    }\n#else\n    CImg<T> *data(const unsigned int l) {\n      return _data + l;\n    }\n\n    //! Return pointer to the pos-th image of the list \\const.\n    const CImg<T> *data(const unsigned int l) const {\n      return _data + l;\n    }","sourceCodeStart":64882,"sourceCodeEnd":64918,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L64882-L64918","documentation":"CImgList<T>::data(pos) returns a pointer to the pos-th image in the list (equivalent to list.data + pos). If pos >= size(), a warning is emitted (when cimg_verbosity>=3) and an out-of-bounds pointer is still returned. Dereferencing that pointer is undefined behavior.","triggerScenarios":"Calling list.data(n) where n >= list.size(); reading the raw pointer array after the list was shrunk or assign()ed; deriving a pointer from a frame index returned by a partially-successful load.","commonSituations":"Interfacing with C APIs that need a raw array of CImg pointers, custom loops over list internals, or accessing frames after a failed/truncated file load.","solutions":["Validate pos < list.size() before calling data(pos)","Use list[pos] or list(pos), which at least warns and returns _data, rather than raw pointer arithmetic","Re-check list.size() after any load/assign operation before touching raw pointers","Avoid caching the pointer returned by data() across calls that may modify the list"],"exampleFix":"// before\nCImg<T>* img = list.data(i);\n// after\nCImg<T>* img = (i < list.size()) ? list.data(i) : nullptr;\nif (!img) { /* handle */ }","handlingStrategy":"validation","validationCode":"CImg<T>* p = (pos < list.size()) ? list.data(pos) : nullptr;","typeGuard":"bool validPtr(const CImgList<T>& l, unsigned pos) { return pos < l.size(); }","tryCatchPattern":null,"preventionTips":["Never cache data() pointers across list mutations","Use operator[] instead of raw pointer arithmetic","Validate pos against size() first"],"tags":["cimg","index-out-of-bounds","pointer"],"backgroundTag":"index-out-of-bounds","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"}