Yalantis/uCrop · error · CImgArgumentException
[cimg_appname_math_parser] CImg<%s>::%s: %s: Too much specif
Error message
[cimg_appname_math_parser] CImg<%s>::%s: %s: Too much specified arguments (>24), in macro definition '%s()', in expression '%s'.
What it means
The CImg math parser supports user-defined macros with at most 24 formal arguments. During macro definition parsing, if more than 24 arguments are declared, it throws CImgArgumentException. This is a hard compile-time limit of the expression compiler.
Source
Thrown at ucrop/src/main/jni/CImg.h:18587
++s; while (*s && cimg::is_blank(*s)) ++s;
CImg<charT>(s,(unsigned int)(se - s + 1)).move_to(macro_body,0);
bool is_variadic = false;
p1 = 1; // Index of current parsed argument
for (s = s0 + 1; s<=s1; ++p1, s = ns + 1) { // Parse function arguments
if (is_variadic && p1>1) {
_cimg_mp_strerr;
cimg::strellipsize(variable_name,64);
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Multiple arguments not allowed when first one is "
"variadic, in macro definition '%s()', in expression '%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
variable_name._data,s0);
}
if (p1>24) {
_cimg_mp_strerr;
cimg::strellipsize(variable_name,64);
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Too much specified arguments (>24), in macro "
"definition '%s()', in expression '%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
variable_name._data,s0);
}
while (*s && cimg::is_blank(*s)) ++s;
if (*s==')' && p1==1) break; // Function has no arguments
s2 = s; // Start of the argument name
is_sth = true; // is_valid_argument_name?
if (*s2>='0' && *s2<='9') is_sth = false;
else for (ns = s2; ns<s1 && *ns!=',' && *ns!='.' && !cimg::is_blank(*ns); ++ns)
if (!cimg::is_varchar(*ns)) { is_sth = false; break; }
s3 = ns; // End of the argument name
if (is_sth && ns>s2 && *ns=='.' && ns[1]=='.' && ns[2]=='.') { is_variadic = true; ns+=3; }
else if (*ns=='.') is_sth = false;
while (*ns && cimg::is_blank(*ns)) ++ns;
if (!is_sth || s2==s3 || (*ns!=',' && ns!=s1)) {View on GitHub (pinned to f788b534b4)
Solutions
- Reduce the number of macro arguments to 24 or fewer
- Split the macro into two smaller macros and compose them
- Precompute parts of the formula outside the math expression
- Inline the formula at call sites instead of using a macro
Example fix
// before myfunc(a1,...,a25) = a1+a2+...+a25; // after myfunc(a1,...,a24) = a1+...+a24; // split into two macros if more needed
Defensive patterns
Strategy: validation
Validate before calling
const MAX_MACRO_ARGS = 24;
function checkMacroArgCount(expr) {
const m = expr.match(/^\s*\w+\s*\(([^)]*)\)\s*=/);
if (!m) return;
const n = m[1].split(',').filter(s => s.trim() !== '').length;
if (n > MAX_MACRO_ARGS) throw new Error(`Macro has ${n} args; CImg allows max ${MAX_MACRO_ARGS}`);
}
Try / catch
try {
img.evaluate(expr);
} catch (e) {
if (/Too much specified arguments \(>24\)/.test(String(e))) {
// refactor macro into smaller macros
} else throw e;
}
Prevention
- Keep macro signatures at or below 24 parameters
- Compose small macros instead of one mega-macro
- Unit-test macro definitions with a parser sanity check
When it happens
Trigger: Defining a math-parser macro via 'name(arg1,...,arg25) = expression' (or via the 'mdef'/'macros' mechanisms) where p1, the argument count, exceeds 24.
Common situations: Auto-generating macro definitions from data or code, porting huge formulas into CImg expressions, or copy-pasting long macro parameter lists.
Related errors
- [cimg_appname_math_parser] CImg<%s>::%s: %s: %s name specifi
- [cimg_appname_math_parser] CImg<%s>::%s: %s: Invalid assignm
- [cimg_appname_math_parser] CImg<%s>::%s: %s: Invalid %slvalu
- [cimg_appname_math_parser] CImg<%s>::%s: %s: Array brackets
- [cimg_appname_math_parser] CImg<%s>::%s: Out-of-bounds refer
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/bf2481c0db8b8b87.
Report an issue: GitHub.