{"record":{"id":"d765397ba5705e47","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-s-empty-exp","errorCode":null,"errorMessage":"[cimg_appname_math_parser] CImg<%s>::%s: Empty expression.","messagePattern":"\\[cimg_appname_math_parser\\] CImg<(.+?)>::(.+?): Empty expression\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":17958,"sourceCode":"      }\n\n      _cimg_math_parser(const char *const expression, const char *const funcname=0,\n                        const CImg<T>& img_input=CImg<T>::const_empty(), CImg<T> *const img_output=0,\n                        CImgList<T> *const list_images=0, const bool _is_fill=false):\n        code(_code),code_begin_t(_code_begin_t),code_end_t(_code_end_t),\n        p_break((CImg<ulongT>*)(cimg_ulong)-2),imgin(img_input),\n        imgout(img_output?*img_output:CImg<T>::empty()),imglist(list_images?*list_images:CImgList<T>::empty()),\n        img_stats(_img_stats),list_stats(_list_stats),list_median(_list_median),list_norm(_list_norm),user_macro(0),\n        mem_img_median(~0U),mem_img_norm(~0U),mem_img_index(~0U),debug_indent(0),result_dim(0),result_end_dim(0),\n        break_type(0),constcache_size(0),is_parallelizable(true),is_noncritical_run(false),is_fill(_is_fill),\n        need_input_copy(false),result_end(0),rng((cimg::_rand(),cimg::rng())),\n        calling_function(funcname?funcname:\"cimg_math_parser\") {\n\n#if cimg_use_openmp!=0\n        rng+=omp_get_thread_num();\n#endif\n        if (!expression || !*expression)\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                      \"CImg<%s>::%s: Empty expression.\",\n                                      pixel_type(),_cimg_mp_calling_function);\n        const char *_expression = expression;\n        while (*_expression && (cimg::is_blank(*_expression) || *_expression==';')) ++_expression;\n        CImg<charT>::string(_expression).move_to(expr);\n        char *ps = &expr.back() - 1;\n        while (ps>expr._data && (cimg::is_blank(*ps) || *ps==';')) --ps;\n        *(++ps) = 0; expr._width = (unsigned int)(ps - expr._data + 1);\n\n        // Ease the retrieval of previous non-space characters afterwards.\n        pexpr.assign(expr._width);\n        char c, *pe = pexpr._data;\n        for (ps = expr._data, c = ' '; *ps; ++ps) {\n          if (!cimg::is_blank(*ps)) c = *ps; else *ps = ' ';\n          *(pe++) = c;\n        }\n        *pe = 0;\n        level = get_level(expr);","sourceCodeStart":17940,"sourceCodeEnd":17976,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L17940-L17976","documentation":"CImg's built-in math-expression parser (cimg_math_parser, used by CImg<T>::fill(\"expr\"), eval(), etc.) requires a non-null, non-empty expression string. When the expression pointer is null or the string is empty, it throws CImgArgumentException tagged [cimg_appname_math_parser].","triggerScenarios":"Calling img.fill(\"\"), img.eval(\"\"), get_eval(NULL), or passing an expression from a config file/CLI that resolved to empty; also strings that contain only blanks/semicolons after trimming in some paths.","commonSituations":"Formula read from preferences/INI file where the key is missing or empty; user submitted a blank formula; a variable holding the expression was never initialized.","solutions":["Validate the expression is non-null and non-empty before passing it to fill()/eval().","Trim and check the string after loading from config or user input.","Provide a default formula when the configured one is blank.","Catch CImgArgumentException and report 'empty formula' to the user instead of crashing."],"exampleFix":"// before\nconst char* expr = cfg.get(\"formula\"); // may be NULL/empty\nimg.fill(expr); // throws: Empty expression\n// after\nconst char* expr = cfg.get(\"formula\");\nif (expr && *expr) {\n  img.fill(expr);\n} else {\n  img.fill(\"0\"); // sensible default\n}","handlingStrategy":"validation","validationCode":"if (!expr || !*expr) { /* reject before calling CImg */ return ERR_EMPTY_FORMULA; }\nimg.fill(expr);","typeGuard":"bool valid_expression(const char* s) { return s != nullptr && *s != '\\0'; }","tryCatchPattern":"try {\n  img.fill(expr);\n} catch (const CImgArgumentException& e) {\n  // e.what() contains '[appname_math_parser] ... Empty expression.'\n  showUserError(\"formula is empty\");\n}","preventionTips":["Validate expressions read from config/preferences before use.","Provide sensible default formulas when config values are blank.","Trim whitespace and reject strings that are empty after trimming.","Fail with a clear user-facing message instead of passing NULL/empty strings into eval/fill."],"tags":["cimg","math-expression","parser","empty-input"],"backgroundTag":"empty-required-field","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"}