{"record":{"id":"42aea72e00ed7ba2","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-s-s-inval","errorCode":null,"errorMessage":"[cimg_appname_math_parser] CImg<%s>::%s: %s: Invalid assignment of %sconst variable '%s'%s, in expression '%s'.","messagePattern":"\\[cimg_appname_math_parser\\] CImg<(.+?)>::(.+?): (.+?): Invalid assignment of (.+?)const variable '(.+?)'(.+?), in expression '(.+?)'\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":18700,"sourceCode":"                  if (is_const) arg1 = arg3;\n                  else {\n                    arg1 = is_sth || is_comp_scalar(arg3)?arg3:scalar1(mp_copy,arg3);\n                    memtype[arg1] = -1;\n                  }\n                }\n\n                if (arg2!=~0U) reserved_label[arg2] = arg1;\n                  else {\n                    if (variable_def._width>=variable_pos._width) variable_pos.resize(-200,1,1,1,0);\n                    variable_pos[variable_def._width] = arg1;\n                    variable_name.move_to(variable_def);\n                  }\n\n              } else { // Variable already exists -> assign a new value\n                if (is_const || is_const_scalar(arg1)) {\n                  cimg::strellipsize(variable_name,64);\n                  _cimg_mp_strerr;\n                  throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                              \"CImg<%s>::%s: %s: Invalid assignment of %sconst variable '%s'%s, \"\n                                              \"in expression '%s'.\",\n                                              pixel_type(),_cimg_mp_calling_function,s_op,\n                                              is_const_scalar(arg1)?\"\":\"non-\",\n                                              variable_name._data,\n                                              !is_const_scalar(arg1) && is_const?\" as a const variable\":\"\",\n                                              s0);\n                }\n                _cimg_mp_check_type(arg3,2,is_vector(arg1)?3:1,size(arg1));\n                if (is_vector(arg1)) { // Vector\n                  if (is_vector(arg3)) // From vector\n                    CImg<ulongT>::vector((ulongT)mp_vector_copy,arg1,arg3,(ulongT)size(arg1)).\n                      move_to(code);\n                  else // From scalar\n                    CImg<ulongT>::vector((ulongT)mp_vector_init,arg1,1,(ulongT)size(arg1),arg3).\n                      move_to(code);\n                } else // Scalar\n                  CImg<ulongT>::vector((ulongT)mp_copy,arg1,arg3).move_to(code);","sourceCodeStart":18682,"sourceCodeEnd":18718,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L18682-L18718","documentation":"CImg allows variables to be declared const (e.g. 'const x = ...'). Assigning a new value to a variable that is already const, or to a const scalar slot, is rejected by the expression compiler with this error.","triggerScenarios":"Using assignment ('=', '+=', etc.) on a variable that was previously defined with 'const', or assigning to a memory slot holding a constant scalar (is_const_scalar(arg1)).","commonSituations":"Reusing a const variable name as a loop accumulator, mixing const declarations with later reassignments in long expressions.","solutions":["Remove the 'const' keyword from the original declaration","Use a different variable name for the new value","Restructure the expression so const variables are write-once"],"exampleFix":"// before\nconst x = 3; x = x + 1;\n// after\nx = 3; x = x + 1;  // or keep const and use y = x + 1","handlingStrategy":"validation","validationCode":"// Track const declarations in your expression strings\nfunction findConstReassign(expr) {\n  const consts = [...expr.matchAll(/const\\s+([A-Za-z_]\\w*)\\s*=/g)].map(m => m[1]);\n  return consts.filter(name =>\n    new RegExp(`(?<!const\\\\s)\\\\b${name}\\\\s*(=[^=]|\\\\+=|-=|\\\\*=|/=)`).test(expr)\n  );\n}\n","typeGuard":null,"tryCatchPattern":"try {\n  img.evaluate(expr);\n} catch (e) {\n  if (/Invalid assignment of .*const variable/.test(String(e))) {\n    // remove const or rename the assignment target\n  } else throw e;\n}\n","preventionTips":["Treat const variables as write-once","Use distinct names for derived values instead of reassigning consts","Search expressions for 'const' declarations before adding assignments"],"tags":["cimg","math-parser","const","assignment"],"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-14T05:17:10.506Z"}