{"record":{"id":"77537ae5262e9392","repo":"Yalantis/uCrop","slug":"deriche-invalid-specified-order-d-order-c","errorCode":null,"errorMessage":"deriche(): Invalid specified order '%d' ('order' can be { 0=smoothing | 1=1st-derivative | 2=2nd-derivative }).","messagePattern":"deriche\\(\\): Invalid specified order '(.+?)' \\('order' can be (.+?)\\)\\.","errorType":"validation","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":43755,"sourceCode":"  T xp = (T)0; \\\n  if (boundary_conditions) { xp = *ptrX; yb = yp = (double)(coefp*xp); } \\\n  for (int m = 0; m<N; ++m) { \\\n    const T xc = *ptrX; ptrX+=off; \\\n    const double yc = *(ptrY++) = (double)(a0*xc + a1*xp - b1*yp - b2*yb); \\\n    xp = xc; yb = yp; yp = yc; \\\n  } \\\n  T xn = (T)0, xa = (T)0; \\\n  double yn = 0, ya = 0; \\\n  if (boundary_conditions) { xn = xa = *(ptrX - off); yn = ya = (double)coefn*xn; } \\\n  for (int n = N - 1; n>=0; --n) { \\\n    const T xc = *(ptrX-=off); \\\n    const double yc = (double)(a2*xn + a3*xa - b1*yn - b2*ya); \\\n    xa = xn; xn = xc; ya = yn; yn = yc; \\\n    *ptrX = (T)(*(--ptrY)+yc); \\\n  }\n\n      if (order>2)\n        throw CImgArgumentException(_cimg_instance\n                                    \"deriche(): Invalid specified order '%d' \"\n                                    \"('order' can be { 0=smoothing | 1=1st-derivative | 2=2nd-derivative }).\",\n                                    cimg_instance,\n                                    order);\n\n      const char naxis = cimg::lowercase(axis);\n      if (naxis!='x' && naxis!='y' && naxis!='z' && naxis!='c')\n        throw CImgArgumentException(_cimg_instance\n                                    \"deriche(): Invalid specified axis '%c'.\",\n                                    cimg_instance,\n                                    axis);\n      const double\n        nsigma = sigma>=0?sigma:-sigma*(naxis=='x'?_width:\n                                        naxis=='y'?_height:\n                                        naxis=='z'?_depth:_spectrum)/100,\n        nnsigma = nsigma<0.1f?0.1f:nsigma;\n\n      if (is_empty() || (nsigma<0.1f && !order)) return *this;","sourceCodeStart":43737,"sourceCodeEnd":43773,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L43737-L43773","documentation":"CImg's Deriche filter (deriche()) only supports order 0 (smoothing), 1 (first derivative) or 2 (second derivative). Any order value greater than 2 throws this argument-validation exception; order is checked at the top of the routine before any processing.","triggerScenarios":"Calling img.deriche(sigma, order, axis) with order >= 3, e.g. passing a derivative order taken from a loop variable that overruns, or confusing 'order' with a filter size or iteration count.","commonSituations":"Mapping an arbitrary nth-derivative request onto Deriche (which only implements up to 2nd order); copy-pasting a vanvliet/Haar call pattern with wrong semantics; unsigned underflow is not possible here (order>2 fails, not negative).","solutions":["Pass order as 0, 1 or 2","For higher derivatives, chain multiple 1st-derivative calls (deriche twice approximates 2nd order already) or use a different method","Clamp or validate the order variable before calling"],"exampleFix":"// before\nimg.deriche(2.0f, 3, 'x');\n// after\nimg.deriche(2.0f, 2, 'x'); // max supported derivative order","handlingStrategy":"validation","validationCode":"if (order > 2) order = 2; // clamp before deriche()","typeGuard":"bool validDerivativeOrder(unsigned order) { return order <= 2; }","tryCatchPattern":"try {\n  img.deriche(sigma, order, axis);\n} catch (cimg_library::CImgArgumentException& e) {\n  img.deriche(sigma, 0, axis); // fall back to smoothing\n}","preventionTips":["Treat 'order' as a 0-2 enum, not an arbitrary integer","Clamp user/config supplied orders","Note vanvliet shares this constraint"],"tags":["cimg","image-processing","deriche","argument-validation"],"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-17T15:17:12.973Z"}