{"record":{"id":"b7a0aecb4f53576d","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-s-s-inval-b7a0ae","errorCode":null,"errorMessage":"[cimg_appname_math_parser] CImg<%s>::%s: %s: Invalid loop variable name '%s', in expression '%s'.","messagePattern":"\\[cimg_appname_math_parser\\] CImg<(.+?)>::(.+?): (.+?): Invalid loop variable name '(.+?)', in expression '(.+?)'\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":21782,"sourceCode":"              s0 = ss5; while (s0<se1 && (*s0!=',' || level[s0 - expr._data]!=clevel1)) ++s0;\n              arg1 = compile(ss5,s0,depth1,0,block_flags); // Object to fill\n              if (is_const_scalar(arg1)) {\n                _cimg_mp_strerr;\n                throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                            \"CImg<%s>::%s: %s: Target scalar is constant, \"\n                                            \"in expression '%s'.\",\n                                            pixel_type(),_cimg_mp_calling_function,s_op,ss);\n              }\n              s1 = ++s0; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;\n              p1 = code._width;\n\n              if (s1<se1) { // Version with 3 arguments\n                variable_name.assign(s0,(unsigned int)(s1 + 1 - s0)).back() = 0;\n                cimg::strpare(variable_name,false,true);\n                if (!cimg::is_varname(variable_name)) { // Invalid variable name\n                  cimg::strellipsize(variable_name,64);\n                  _cimg_mp_strerr;\n                  throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                              \"CImg<%s>::%s: %s: Invalid loop variable name '%s', \"\n                                              \"in expression '%s'.\",\n                                              pixel_type(),_cimg_mp_calling_function,s_op,\n                                              variable_name._data,s0);\n                }\n                get_variable_pos(variable_name,arg2,arg3);\n                arg2 = arg3!=~0U?reserved_label[arg3]:arg2!=~0U?variable_pos[arg2]:~0U; // Variable slot\n                if (arg2!=~0U && (!is_scalar(arg2) ||\n                                  is_const_scalar(arg2))) { // Variable is not a vector or is a constant->error\n                  cimg::strellipsize(variable_name,64);\n                  _cimg_mp_strerr;\n                  throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                              \"CImg<%s>::%s: %s: Invalid type '%s' for variable '%s' \"\n                                              \"(expected 'scalar'), in expression '%s'.\",\n                                              pixel_type(),_cimg_mp_calling_function,s_op,\n                                              s_type(arg2)._data,variable_name._data,s0);\n                } else if (arg2==~0U) { // Variable does not exist -> create it\n                  arg2 = scalar();","sourceCodeStart":21764,"sourceCodeEnd":21800,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L21764-L21800","documentation":"Loop constructs in the math parser (`for`, `while`, `repeat`, `do`) with the 3-argument form take a loop variable name as the first argument. CImg validates the name with cimg::is_varname; if the extracted token is not a legal variable name (empty, starts with a digit, contains operators/illegal characters) it throws this error, truncating the name to 64 chars in the message.","triggerScenarios":"`repeat(1x,index,...)` style 3-argument loops where the first token is not a valid identifier, e.g. `repeat(10,2,x+y)` (expression instead of variable name), `for(0,5,i,...)` with a literal as first arg, or names like `2i`, `my-var`, or an empty string.","commonSituations":"Misremembering argument order of for/repeat (thinking first arg is the range); G'MIC-to-CImg expression porting where loop syntax differs; typos such as a missing variable and passing the iteration count first.","solutions":["Pass a valid variable name as first argument: `for(i=0, i<5, i++, ...)` or `repeat(5, i, ...)`","Ensure the name matches cimg::is_varname: letters/digits/underscore, not starting with a digit, no operators","Reorder arguments if you inverted the range and variable positions","Use the 2-argument loop form (automatic variable) if you don't need a named loop variable"],"exampleFix":"// before\nimg.fill(\"repeat(10,x+1)\"); // '10' is not a variable name in 3-arg form\n// after\nimg.fill(\"repeat(10,i,x+1)\");","handlingStrategy":"type-guard","validationCode":"static final java.util.regex.Pattern VAR = java.util.regex.Pattern.compile(\"[A-Za-z_][A-Za-z0-9_]*\");\nboolean isValidLoopVar(String name) { return name != null && VAR.matcher(name).matches(); }","typeGuard":"boolean isVarName(String s) { return s != null && s.matches(\"[A-Za-z_][A-Za-z0-9_]*\"); }","tryCatchPattern":"try { img.fill(expr); } catch (CImgArgumentException e) { if (e.getMessage().contains(\"Invalid loop variable name\")) { throw new IllegalArgumentException(\"Loop's first argument must be a valid identifier\"); } throw e; }","preventionTips":["Remember loop argument order: variable name comes first in the 3-arg form","Use only [A-Za-z_][A-Za-z0-9_]* names for loop variables","Use the 2-argument loop form when no named counter is needed"],"tags":["cimg","math-parser","loop","identifier"],"backgroundTag":"invalid-identifier-format","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"}