{"record":{"id":"061b63d63d408d6f","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-s-s-s-061b63","errorCode":null,"errorMessage":"[\" cimg_appname \"_math_parser] CImg<%s>::%s: %s%s %s%s (of type '%s' and value %g) is not a%s constant, in expression '%s'.","messagePattern":"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>::(.+?): (.+?)(.+?) (.+?)(.+?) \\(of type '(.+?)' and value %g\\) is not a(.+?) constant, in expression '(.+?)'\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":25167,"sourceCode":"        _cimg_mp_check_type(arg,n_arg,1,0);\n        if (!is_const_scalar(arg)) {\n          const char *const s_arg = s_argth(n_arg);\n          char *s0;\n          _cimg_mp_strerr;\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                      \"CImg<%s>::%s: %s%s %s%s (of type '%s') is not a constant, \"\n                                      \"in expression '%s'.\",\n                                      pixel_type(),_cimg_mp_calling_function,s_op,*s_op?\":\":\"\",\n                                      s_arg,*s_arg?\" argument\":\" Argument\",s_type(arg)._data,s0);\n        }\n        const double val = mem[arg];\n\n        if (!((!mode || (double)(int)mem[arg]==mem[arg]) &&\n              (mode<2 || mem[arg]>=(mode==3)))) {\n          const char *const s_arg = s_argth(n_arg);\n          char *s0;\n          _cimg_mp_strerr;\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                      \"CImg<%s>::%s: %s%s %s%s (of type '%s' and value %g) is not a%s constant, \"\n                                      \"in expression '%s'.\",\n                                      pixel_type(),_cimg_mp_calling_function,s_op,*s_op?\":\":\"\",\n                                      s_arg,*s_arg?\" argument\":\" Argument\",s_type(arg)._data,val,\n                                      !mode?\"\":mode==1?\"n integer\":\n                                      mode==2?\" positive integer\":\" strictly positive integer\",s0);\n        }\n      }\n\n      // Check if an image index is a constant value.\n      void check_const_index(const unsigned int arg,\n                             char *const ss, char *const se, const char saved_char) {\n        if (arg!=~0U && !is_const_scalar(arg)) {\n          char *s0;\n          _cimg_mp_strerr;\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                      \"CImg<%s>::%s: %s%s Specified image index is not a constant, \"\n                                      \"in expression '%s'.\",","sourceCodeStart":25149,"sourceCodeEnd":25185,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L25149-L25185","documentation":"This is a stricter constant check in the CImg math parser: the argument must not only be a compile-time constant but must satisfy a mode-specific constraint - mode 0/1 require an integer value, mode 2 requires a non-negative integer, and mode 3 requires a strictly positive integer. If mem[arg] fails the check, the error reports the argument's type and actual value %g so the offending value is visible.","triggerScenarios":"Calling a CImg math-expression function whose argument must be an integer constant (e.g. axis, dimension, count, or index) with a fractional value like 2.5, a negative value where positivity is required, or zero where a strictly positive value is required.","commonSituations":"Computing sizes or counts with floating-point arithmetic and passing the result directly (3.0000001 from a division); using negative offsets; hard-coding 0 for a 1-based index; rounding errors from float math making an 'integer' value non-integral.","solutions":["Pass a whole-number literal (e.g. 3 not 3.0 computed) in the required position","Round the value in C++ before embedding it: use cimg::round() or (int) cast, then format into the expression string","Ensure sign constraints: use an absolute value or max(1,...) when a strictly positive integer is needed","Read the error's reported value and mode suffix ('integer', 'positive integer', 'strictly positive integer') to see which constraint was violated"],"exampleFix":"// before\nimg.fill(\"mirror(2.5)\"); // not an integer constant\n// after\nimg.fill(\"mirror(3)\"); // integer constant\n// or compute in C++:\nchar expr[64];\nsnprintf(expr, sizeof(expr), \"mirror(%d)\", (int)cimg::round(v,1));\nimg.fill(expr);","handlingStrategy":"validation","validationCode":"// C++: clamp/round values to the required integer class before embedding\nint check_positive_int(double v) {\n  int i = (int)std::llround(v);\n  if (i < 1) throw std::invalid_argument(\"need strictly positive integer\");\n  return i;\n}\nchar buf[64];\nstd::snprintf(buf, sizeof(buf), \"mirror(%d)\", check_positive_int(user_value));","typeGuard":"bool is_positive_integer(double v) { return v == (double)(long long)v && v > 0; }","tryCatchPattern":"try {\n  img.fill(expr.c_str());\n} catch (const cimg_library::CImgArgumentException& e) {\n  std::cerr << \"Integer-constant constraint violated: \" << e.what() << std::endl;\n}","preventionTips":["Round floating results before using them as counts/axes/indices","Use integer types (int/unsigned) for these parameters end to end","Read the error suffix (integer / positive / strictly positive) to pick the right constraint check"],"tags":["cimg","math-parser","constant-expression","integer-constraint"],"backgroundTag":"argument-out-of-range","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}