{"record":{"id":"d1479112564a0a09","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-s-funct","errorCode":null,"errorMessage":"[\" cimg_appname \"_math_parser] CImg<%s>::%s: Function '%s()': Number of specified arguments (%u) does not match macro declaration (defined for %s or %u arguments), in expression '%s'.","messagePattern":"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>::(.+?): Function '(.+?)\\(\\)': Number of specified arguments \\(%u\\) does not match macro declaration \\(defined for (.+?) or %u arguments\\), in expression '(.+?)'\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":24465,"sourceCode":"              user_macro = s0;\n              level.swap(_level);\n              pexpr.swap(_pexpr);\n              expr.swap(_expr);\n              _cimg_mp_return(pos);\n            }\n\n            if (arg3) { // Macro name matched but number of arguments does not\n              CImg<uintT> sig_nargs(arg3);\n              arg1 = 0;\n              cimglist_for(macro_def,l) if (!std::strcmp(macro_def[l],variable_name))\n                sig_nargs[arg1++] = (unsigned int)macro_def[l].back();\n              _cimg_mp_strerr;\n              cimg::strellipsize(variable_name,64);\n              if (sig_nargs._width>1) {\n                sig_nargs.sort();\n                arg1 = sig_nargs.back();\n                --sig_nargs._width;\n                throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                            \"CImg<%s>::%s: Function '%s()': Number of specified arguments (%u) \"\n                                            \"does not match macro declaration (defined for %s or %u arguments), \"\n                                            \"in expression '%s'.\",\n                                            pixel_type(),_cimg_mp_calling_function,variable_name._data,\n                                            p1,sig_nargs.value_string()._data,arg1,s0);\n              } else {\n                throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                            \"CImg<%s>::%s: Function '%s()': Number of specified arguments (%u) \"\n                                            \"does not match macro declaration (defined for %u argument%s), \"\n                                            \"in expression '%s'.\",\n                                            pixel_type(),_cimg_mp_calling_function,variable_name._data,\n                                            p1,*sig_nargs,*sig_nargs!=1?\"s\":\"\",s0);\n              }\n            }\n          }\n        } // if (se1==')')\n\n        // Char / string initializer.","sourceCodeStart":24447,"sourceCodeEnd":24483,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L24447-L24483","documentation":"CImg's built-in math expression parser compiles user expressions (formulas passed to functions like fill(), get_math(), etc.). When the expression calls a named macro/function, the parser checks the argument count against the macro's declared signature. This error is thrown when a macro is declared to accept one of two possible argument counts (a variable-arity signature), and the call supplies a count matching neither.","triggerScenarios":"Evaluating a CImg math expression that invokes a user-defined macro (via cimg_math macro injection or fill()) with an argument count that does not match the macro's declared dual signature (e.g. macro defined for 2-or-3 arguments but called with 1 or 4). The branch executes when sig_nargs._width>1, i.e. the macro declares more than one accepted arity.","commonSituations":"Hand-written fill() expressions reusing copy-pasted macros after editing their signature; library-version changes where built-in macro arities changed; dynamically generated expressions where argument counts are computed at runtime.","solutions":["Count the arguments in the offending call and compare with the macro declaration shown in the message (%s or %u arguments).","Add or remove arguments so the call matches one of the declared arities.","Check the macro definition (or CImg version docs) for the exact accepted signatures.","If building expressions programmatically, assert the arity before substitution.","Pin/verify the CImg version if a previously working expression stopped compiling."],"exampleFix":"// before\ndimg.fill(mymacro(a,b,c)); // mymacro declared for 2 or 3 args\n// after\ndimg.fill(mymacro(a,b));   // matches declared 2-or-3 argument signature","handlingStrategy":"validation","validationCode":"boolean validArity = (macroArityA == callArgCount) || (macroArityB == callArgCount);\nif (!validArity) throw new IllegalArgumentException(\"mymacro expects \" + macroArityA + \" or \" + macroArityB + \" args, got \" + callArgCount);","typeGuard":null,"tryCatchPattern":"try {\n    img.fill(expression);\n} catch (CImgInstantiationException e) {\n    if (e.getMessage().contains(\"does not match macro declaration\")) {\n        // log expression + expected arities from message, fix expression\n    }\n    throw e;\n}","preventionTips":["Keep a table mapping each macro to its accepted arities and validate generated expressions against it.","Unit-test every macro invocation pattern used in production expressions.","Avoid hand-editing macro signatures without grepping all call sites.","Pin the CImg version and re-test expressions after upgrades."],"tags":["cimg","math-parser","macro","argument-count"],"backgroundTag":"missing-required-argument","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"}