Yalantis/uCrop · error · CImgArgumentException

[cimg_appname_math_parser] CImg<%s>::%s: %s%s Missing %s, in

Error message

[cimg_appname_math_parser] CImg<%s>::%s: %s%s Missing %s, in expression '%s'.

What it means

While compiling the expression, the parser reached the end of the token stream while an operator/function (s_op) still expected an operand. It throws CImgArgumentException stating whether a missing argument (function) or item (operator) was expected, with the position where parsing stopped.

Source

Thrown at ucrop/src/main/jni/CImg.h:18128

            while (*ss && (cimg::is_blank(*ss) || *ss==';')) ++ss; // Remove leading blanks and ';'
            while (se>ss && (cimg::is_blank(c1 = *(se - 1)) || c1==';')) --se; // Remove trailing blanks and ';'
          }
          while (*ss=='(' && *(se - 1)==')' && std::strchr(ss,')')==se - 1) { // Remove useless start/end parentheses
            ++ss; --se; c2 = 1;
          }
          if (*ss=='_' && ss + 1<se && ss[1]=='(') { // Remove leading '_(something)' comment
            const unsigned int clevel = level[ss - expr._data];
            ss+=2;
            while (ss<se && (*ss!=')' || level[ss - expr._data]!=clevel)) ++ss;
            if (ss<se) ++ss;
            if (ss>=se) return _cimg_mp_slot_nan;
            c2 = 1;
          }
        } while (c2 && ss<se);

        if (se<=ss || !*ss) {
          cimg::strellipsize(expr,64);
          throw CImgArgumentException("[" cimg_appname "_math_parser] "
                                      "CImg<%s>::%s: %s%s Missing %s, in expression '%s'.",
                                      pixel_type(),_cimg_mp_calling_function,s_op,*s_op?":":"",
                                      *s_op=='F'?"argument":"item",
                                      ss_op);
        }

        static const size_t siz_ref = 7*sizeof(unsigned int);
        const char *const previous_s_op = s_op, *const previous_ss_op = ss_op;
        const unsigned int depth1 = depth + 1;
        unsigned int pos, p1, p2, p3, arg1, arg2, arg3, arg4, arg5, arg6;
        char
          *const se1 = se - 1, *const se2 = se - 2, *const se3 = se - 3, *const se4 = se - 4,
          *const ss1 = ss + 1, *const ss2 = ss + 2, *const ss3 = ss + 3, *const ss4 = ss + 4,
          *const ss5 = ss + 5, *const ss6 = ss + 6, *const ss7 = ss + 7, *const ss8 = ss + 8,
          *s, *ps, *ns, *s0, *s1, *s2, *s3, sep = 0, end = 0;
        double val = 0, val1, val2, val3;
        mp_func op;
        return_comp = false;

View on GitHub (pinned to f788b534b4)

Solutions

  1. Complete the expression: supply the missing operand/argument before the end of the string.
  2. Check for empty variable/parameter interpolation when building expressions dynamically.
  3. Print the expression (the error truncates it to 64 chars via strellipsize) and verify balanced parentheses and operators.
  4. Validate expressions with a lint/parse step before passing to fill()/eval().

Example fix

// before
img.fill("sin(x) + "); // Missing argument/item
// after
img.fill("sin(x) + cos(y)");
Defensive patterns

Strategy: validation

Validate before calling

// quick balance check: operators/functions must not end the string
std::string s = trim(expr);
if (s.empty() || is_trailing_operator(s)) return ERR_INCOMPLETE_EXPRESSION;
img.fill(s.c_str());

Try / catch

try {
  img.fill(expr);
} catch (const CImgArgumentException& e) {
  if (strstr(e.what(), "Missing")) {
    // report incomplete formula, show position excerpt from e.what()
  }
}

Prevention

When it happens

Trigger: Expressions like "1+", "sin(", "max(1,", or a trailing binary operator; a macro invocation with fewer arguments than declared; truncation of a long expression when passed through a length-limited config key or buffer.

Common situations: Hand-edited formula strings in config files with a missing operand; expressions built by string concatenation where a variable interpolated to empty; copy-paste that cut off the tail of the formula.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/c5b58cc3ca478ecc. Report an issue: GitHub.