Yalantis/uCrop · warning

data(): Invalid pointer request, at position [%u].

Error message

data(): Invalid pointer request, at position [%u].

What it means

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.

Solutions

  1. Validate pos < list.size() before calling data(pos)
  2. Use list[pos] or list(pos), which at least warns and returns _data, rather than raw pointer arithmetic
  3. Re-check list.size() after any load/assign operation before touching raw pointers
  4. Avoid caching the pointer returned by data() across calls that may modify the list

Example fix

// before
CImg<T>* img = list.data(i);
// after
CImg<T>* img = (i < list.size()) ? list.data(i) : nullptr;
if (!img) { /* handle */ }
Defensive patterns

Strategy: validation

Validate before calling

CImg<T>* p = (pos < list.size()) ? list.data(pos) : nullptr;

Type guard

bool validPtr(const CImgList<T>& l, unsigned pos) { return pos < l.size(); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/bc9fa3e308d1eaa2. Report an issue: GitHub.

Appendix: source

Thrown at ucrop/src/main/jni/CImg.h:64900

    **/
    CImg<T> *data() {
      return _data;
    }

    //! Return pointer to the first image of the list \const.
    const CImg<T> *data() const {
      return _data;
    }

    //! Return pointer to the pos-th image of the list.
    /**
       \param pos Index of the image element to access.
       \note <tt>list.data(n);</tt> is equivalent to <tt>list.data + n;</tt>.
    **/
#if cimg_verbosity>=3
    CImg<T> *data(const unsigned int pos) {
      if (pos>=size())
        cimg::warn(_cimglist_instance
                   "data(): Invalid pointer request, at position [%u].",
                   cimglist_instance,
                   pos);
      return _data + pos;
    }

    const CImg<T> *data(const unsigned int l) const {
      return const_cast<CImgList<T>*>(this)->data(l);
    }
#else
    CImg<T> *data(const unsigned int l) {
      return _data + l;
    }

    //! Return pointer to the pos-th image of the list \const.
    const CImg<T> *data(const unsigned int l) const {
      return _data + l;
    }

View on GitHub (pinned to f788b534b4)