{"record":{"id":"174c5da81ae4a814","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-function-174c5d","errorCode":null,"errorMessage":"\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'store()': Specified image dimensions (%d,%d,%d,%d) are invalid.\"","messagePattern":"\"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>: Function 'store\\(\\)': Specified image dimensions \\((.+?),(.+?),(.+?),(.+?)\\) are invalid\\.\"","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":29843,"sourceCode":"      }\n\n#ifdef cimg_mp_func_store\n      static double mp_store(_cimg_math_parser& mp) {\n        const double\n          *ptr1 = &_mp_arg(2),\n          *ptr2 = &_mp_arg(4) + 1;\n        const unsigned int\n          siz1 = (unsigned int)mp.opcode[3],\n          siz2 = (unsigned int)mp.opcode[5];\n        const int\n          w = (int)_mp_arg(6),\n          h = (int)_mp_arg(7),\n          d = (int)_mp_arg(8),\n          s = (int)_mp_arg(9);\n\n        const bool is_compressed = (bool)_mp_arg(10);\n        if (w<0 || h<0 || d<0 || s<0)\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'store()': \"\n                                      \"Specified image dimensions (%d,%d,%d,%d) are invalid.\",\n                                      pixel_type(),w,h,d,s);\n        CImg<charT> ss(siz2 + 1);\n        cimg_for_inX(ss,0,ss.width() - 2,i) ss[i] = (char)ptr2[i];\n        ss.back() = 0;\n        if (siz1) cimg_mp_func_store(ptr1 + 1,siz1,\n                                     (unsigned int)w,(unsigned int)h,(unsigned int)d,(unsigned int)s,\n                                     is_compressed,ss._data);\n        else cimg_mp_func_store(ptr1,1,(unsigned int)w,(unsigned int)h,(unsigned int)d,(unsigned int)s,\n                                is_compressed,ss._data);\n        return cimg::type<double>::nan();\n      }\n#endif\n\n      static double mp_s2v(_cimg_math_parser& mp) {\n        const double *ptrs = &_mp_arg(2);\n        const ulongT siz = (ulongT)mp.opcode[3];\n        longT ind = (longT)_mp_arg(4);","sourceCodeStart":29825,"sourceCodeEnd":29861,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L29825-L29861","documentation":"The math parser 'store()' function serializes an image into a memory buffer using caller-provided dimensions w,h,d,s. If any dimension is negative the geometry is meaningless, so a CImgArgumentException is thrown with the four requested dimensions before any serialization happens.","triggerScenarios":"store(...,w,h,d,s,is_compressed) where one of _mp_arg(7..9) evaluates to a negative value — e.g. computing dimensions as a difference like w2-w1 that underflows, or a variable that was initialized to a negative sentinel.","commonSituations":"Dimension arithmetic bugs (end-before-start subtraction); formula parameterization errors where a user passes -1 as 'auto' sentinel but store() doesn't support sentinels; mismatches when storing cropped sub-images.","solutions":["Clamp each dimension with max(0, expr) or validate w,h,d,s >= 0 before calling store().","Fix the arithmetic producing negative dimensions (check start/end ordering in differences).","Pass the actual image's dimensions (w,h,d,s) directly instead of computed values.","Catch CImgArgumentException and report the requested geometry to the caller."],"exampleFix":"// before: store(buf, w2-w1, h2-h1, d, s)\n// after:  store(buf, max(0,w2-w1), max(0,h2-h1), d, s)","handlingStrategy":"validation","validationCode":"if (w < 0 || h < 0 || d < 0 || s < 0)\n  throw std::runtime_error(\"store() dimensions must be non-negative\");","typeGuard":null,"tryCatchPattern":"try { img.evaluate(storeExpr); } catch (const CImgArgumentException& e) { log(\"store() geometry invalid: \" << e.what()); }","preventionTips":["Clamp computed dimensions with max(0, expr)","Avoid -1 'auto' sentinels — store() requires literal non-negative dims","Unit-test dimension arithmetic with edge inputs"],"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"}