{"record":{"id":"c53591d1d5787ec0","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-function-c53591","errorCode":null,"errorMessage":"\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'da_remove()': Invalid starting (%d) and ending (%d) positions (not ordered, in range -%d...%d).\"","messagePattern":"\"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>: Function 'da_remove\\(\\)': Invalid starting \\((.+?)\\) and ending \\((.+?)\\) positions \\(not ordered, in range -(.+?)\\.\\.\\.(.+?)\\)\\.\"","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":26416,"sourceCode":"        CImg<T> &img = mp.imglist[ind];\n        int siz = img?(int)cimg::float2uint((float)img[img._height - 1]):0;\n        if (img && (img._width!=1 || img._depth!=1 || siz<0 || siz>img.height() - 1))\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'da_remove()': \"\n                                      \"Specified image #%u of size (%d,%d,%d,%d) cannot be used as dynamic array%s.\",\n                                      mp.imgout.pixel_type(),ind,\n                                      img.width(),img.height(),img.depth(),img.spectrum(),\n                                      img._width==1 && img._depth==1?\"\":\" (contains invalid element counter)\");\n        if (!siz)\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'da_remove()': \"\n                                      \"Dynamic array is empty.\",\n                                      mp.imgout.pixel_type());\n        int\n          start0 = mp.opcode[3]==~0U?siz - 1:_mp_arg(3),\n          end0 = mp.opcode[4]==~0U?start0:_mp_arg(4),\n          start = start0<0?start0 + siz:start0,\n          end = end0<0?end0 + siz:end0;\n        if (start<0 || start>=siz || end<0 || end>=siz || start>end)\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'da_remove()': \"\n                                      \"Invalid starting (%d) and ending (%d) positions \"\n                                      \"(not ordered, in range -%d...%d).\",\n                                      mp.imgout.pixel_type(),start0,end0,siz,siz - 1);\n        if (end<siz - 1) // Move remaining data in dynamic array\n          cimg_forC(img,c) std::memmove(img.data(0,start,0,c),img.data(0,end + 1,0,c),(siz - 1 - end)*sizeof(T));\n        siz-=end - start + 1;\n        if (img.height()>32 && siz<img.height()/8) // Reduce size of dynamic array\n          img.resize(1,std::max(2*siz + 1,32),1,-100,0);\n        img[img._height - 1] = (T)cimg::uint2float(siz);\n        return cimg::type<double>::nan();\n      }\n\n      static double mp_da_size(_cimg_math_parser& mp) {\n        mp_check_list(mp,\"da_size\");\n        const unsigned int ind = (unsigned int)cimg::mod((int)_mp_arg(2),mp.imglist.width());\n        CImg<T> &img = mp.imglist[ind];\n        const int siz = img?(int)cimg::float2uint((float)img[img._height - 1]):0;\n        if (img && (img._width!=1 || img._depth!=1 || siz<0 || siz>img.height() - 1))","sourceCodeStart":26398,"sourceCodeEnd":26434,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L26398-L26434","documentation":"mp_da_remove() validates that the start/end positions of the removal range lie inside the array (0..siz-1 after negative-index normalization) and that start<=end. This error is thrown when the given range is out of bounds, reversed, or otherwise not an ordered valid range.","triggerScenarios":"Calling da_remove(#ind,start,end) with start>end, with positions >= siz, or with negative values whose magnitude exceeds siz (e.g. siz=3 and start=-5).","commonSituations":"Off-by-one errors in computed ranges; assuming the array is larger than it is; passing unsorted user-supplied indices; using -1 expecting 'last element' when the default (~0U) sentinel was intended.","solutions":["Clamp/validate start and end to 0..da_size(#ind)-1 before calling.","Ensure start<=end (swap or sort the arguments if computed dynamically).","Use the default sentinel (omit arguments) instead of hand-computed last-index values.","Print da_size(#ind) in the expression to debug the actual array length."],"exampleFix":"// before: start > end\n da_remove(#0,5,2)\n// after\n da_remove(#0,2,5)","handlingStrategy":"validation","validationCode":"// Clamp and order the removal range before calling\ndef clampRange(s, e, siz) { s = Math.max(0, Math.min(s, siz - 1)); e = Math.max(s, Math.min(e, siz - 1)); return [s, e]; }","typeGuard":"function isValidRange(s, e, siz) { return s >= 0 && e >= 0 && s <= e && s < siz && e < siz; }","tryCatchPattern":"try { evalMath(expr); } catch (e) { if (String(e).includes('Invalid starting') && String(e).includes('da_remove')) { [s,e] = clampRange(s,e,siz); retry(); } else throw e; }","preventionTips":["Compute ranges from da_size, never from assumed lengths","Sort (start,end) before passing","Normalize negative indices explicitly with siz + i","Prefer omitting arguments (sentinel defaults) for 'remove last element'"],"tags":["cimg","math-parser","dynamic-array","value-out-of-range"],"backgroundTag":"value-out-of-range","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"}