{"record":{"id":"1b066711208377e5","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-function-1b0667","errorCode":null,"errorMessage":"\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'sort()': Arguments 'nb_elts=%g' and 'siz_elt=%g' are invalid for sorting a vector of size %u.\"","messagePattern":"\"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>: Function 'sort\\(\\)': Arguments 'nb_elts=%g' and 'siz_elt=%g' are invalid for sorting a vector of size %u\\.\"","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":29782,"sourceCode":"          m = (unsigned int)mp.opcode[6];\n        const bool use_LU = (bool)_mp_arg(7);\n        CImg<doubleT>(ptrd,m,k,1,1,true) = CImg<doubleT>(ptr2,m,l,1,1,false).\n          solve(CImg<doubleT>(ptr1,k,l,1,1,true),use_LU);\n        return cimg::type<double>::nan();\n      }\n\n      static double mp_sort(_cimg_math_parser& mp) {\n        double *const ptrd = &_mp_arg(1) + 1;\n        const double *const ptrs = &_mp_arg(2) + 1;\n        const bool is_increasing = (bool)_mp_arg(4);\n        const unsigned int\n          siz = (unsigned int)mp.opcode[3],\n          nb_elts = mp.opcode[5]==~0U?siz:(unsigned int)_mp_arg(5),\n          siz_elt = (unsigned int)_mp_arg(6),\n          sort_index = std::min((unsigned int)_mp_arg(7),siz_elt - 1);\n        const ulongT sn = siz_elt*nb_elts;\n        if (sn>siz || siz_elt<1)\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'sort()': \"\n                                      \"Arguments 'nb_elts=%g' and 'siz_elt=%g' are invalid \"\n                                      \"for sorting a vector of size %u.\",\n                                      mp.imgin.pixel_type(),_mp_arg(5),_mp_arg(6),siz);\n        CImg<doubleT>(ptrd,siz_elt,nb_elts,1,1,true) = CImg<doubleT>(ptrs,siz_elt,nb_elts,1,1,true).\n          shift(-(int)sort_index,0,0,0,2).get_sort(is_increasing,siz_elt>1?'y':0).shift((int)sort_index,0,0,0,2);\n        if (sn<siz) CImg<doubleT>(ptrd + sn,siz - sn,1,1,1,true) = CImg<doubleT>(ptrs + sn,siz - sn,1,1,1,true);\n        return cimg::type<double>::nan();\n      }\n\n      static double mp_sqr(_cimg_math_parser& mp) {\n        return cimg::sqr(_mp_arg(2));\n      }\n\n      static double mp_sqrt(_cimg_math_parser& mp) {\n        return std::sqrt(_mp_arg(2));\n      }\n\n      static double mp_srand(_cimg_math_parser& mp) {","sourceCodeStart":29764,"sourceCodeEnd":29800,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L29764-L29800","documentation":"The math parser 'sort()' function sorts a vector in blocks: nb_elts blocks of siz_elt values each. The product siz_elt*nb_elts must not exceed the vector size 'siz', and siz_elt must be >= 1; otherwise a CImgArgumentException reports the conflicting nb_elts/siz_elt values against the actual vector size.","triggerScenarios":"sort(ptr,siz,...,nb_elts,siz_elt,sort_index) where nb_elts*siz_elt > siz (e.g. sorting 10 blocks of 4 on a vector of 32) or siz_elt == 0, typically because block parameters were hard-coded and the vector dimension changed.","commonSituations":"Changing vector length (e.g. after resizing a feature vector) without updating sort block parameters; passing 0 or negative-derived siz_elt; computing nb_elts from a formula that over-estimates.","solutions":["Ensure siz_elt >= 1 and ceil-based nb_elts so that nb_elts*siz_elt <= siz: pass nb_elts = siz/siz_elt (integer division).","Recompute block parameters from the actual vector size instead of hard-coding them.","If the goal is a full sort, use the simpler one-argument sort form rather than block parameters.","Catch CImgArgumentException and log the vector size to select correct block parameters."],"exampleFix":"// before: sort(V, 10, 4)  // 40 > 32 elements\n// after:  sort(V, 8, 4)    // 8*4 = 32","handlingStrategy":"validation","validationCode":"if (siz_elt < 1 || siz_elt * nb_elts > siz)\n  throw std::runtime_error(\"sort block parameters do not fit vector size\");","typeGuard":null,"tryCatchPattern":"try { img.evaluate(sortExpr); } catch (const CImgArgumentException& e) { log(\"sort() params invalid: \" << e.what()); }","preventionTips":["Derive nb_elts = siz / siz_elt instead of hard-coding","Assert siz_elt >= 1 before building the expression","Re-derive block parameters whenever vector size changes"],"tags":["cimg","math-parser","invalid-argument-value"],"backgroundTag":"invalid-argument-value","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"}