{"record":{"id":"ece2c6ff76b25e46","repo":"Yalantis/uCrop","slug":"haar-invalid-specified-axis-c-should-be-x","errorCode":null,"errorMessage":"haar(): Invalid specified axis '%c' (should be { x | y | z }).","messagePattern":"haar\\(\\): Invalid specified axis '%c' \\(should be (.+?)\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":47462,"sourceCode":"\n            res.assign(_width,_height,_depth,_spectrum);\n            if (invert) cimg_forXYC(*this,x,y,c) { // Inverse transform along Z\n              for (unsigned int z = 0, zd = d, z2 = 0; z<d; ++z, ++zd) {\n                const Tfloat val0 = (Tfloat)(*this)(x,y,z,c), val1 = (Tfloat)(*this)(x,y,zd,c);\n                res(x,y,z2++,c) = (val0 - val1)/sqrt2;\n                res(x,y,z2++,c) = (val0 + val1)/sqrt2;\n              }\n            } else cimg_forXYC(*this,x,y,c) {\n              for (unsigned int z = 0, zd = d, z2 = 0; z<d; ++z, ++zd) { // Direct transform along Z\n                const Tfloat val0 = (Tfloat)(*this)(x,y,z2++,c), val1 = (Tfloat)(*this)(x,y,z2++,c);\n                res(x,y,z,c)  = (val0 + val1)/sqrt2;\n                res(x,y,zd,c) = (val1 - val0)/sqrt2;\n              }\n            }\n          } else return *this;\n        } break;\n        default :\n          throw CImgArgumentException(_cimg_instance\n                                      \"haar(): Invalid specified axis '%c' \"\n                                      \"(should be { x | y | z }).\",\n                                      cimg_instance,\n                                      axis);\n        }\n      } else { // Multi-scale version\n        if (invert) {\n          res.assign(*this,false);\n          switch (cimg::lowercase(axis)) {\n          case 'x' : {\n            unsigned int w = _width;\n            for (unsigned int s = 1; w && s<nb_scales; ++s) w/=2;\n            for (w = w?w:1; w<=_width; w*=2) res.draw_image(res.get_crop(0,w - 1).get_haar('x',true,1));\n          } break;\n          case 'y' : {\n            unsigned int h = _width;\n            for (unsigned int s = 1; h && s<nb_scales; ++s) h/=2;\n            for (h = h?h:1; h<=_height; h*=2) res.draw_image(res.get_crop(0,0,_width - 1,h - 1).get_haar('y',true,1));","sourceCodeStart":47444,"sourceCodeEnd":47480,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L47444-L47480","documentation":"In the single-scale branch of CImg::haar(), the axis argument (lowercased) is dispatched with a switch over 'x', 'y', 'z'. Any other character reaches the default case and raises CImgArgumentException, because the transform can only run along one of the three spatial axes.","triggerScenarios":"Calling img.get_haar(axis, invert, 1) with axis not in {'x','X','y','Y','z','Z'} — e.g. 'w' for width, '0', '\\0' (uninitialized char), or a variable set from misparsed user input.","commonSituations":"Mapping a user-facing string ('horizontal'/'width') to an axis char incorrectly; passing the dimension index instead of a char; uninitialized or defaulted axis variables in wrapper code.","solutions":["Pass exactly 'x', 'y' or 'z' (case-insensitive) as the axis argument.","Sanitize/validate user input to a whitelisted axis before calling.","Clamp a dimension index to an axis: {0:'x',1:'y',2:'z'} mapping.","Initialize the axis variable to a valid default such as 'x'."],"exampleFix":"// before\nimg.get_haar('w', false, 1); // invalid axis\n// after\nimg.get_haar('x', false, 1);","handlingStrategy":"validation","validationCode":"if (axis!='x' && axis!='y' && axis!='z') throw std::invalid_argument(\"haar axis must be x, y or z\");","typeGuard":"bool isHaarAxis(char axis) {\n  char a = std::tolower((unsigned char)axis);\n  return a=='x' || a=='y' || a=='z';\n}","tryCatchPattern":"try {\n  res = img.get_haar(axis, invert, nb_scales);\n} catch (const CImgArgumentException& e) {\n  axis = 'x'; // safe default, log the bad input\n  res = img.get_haar(axis, invert, nb_scales);\n}","preventionTips":["Whitelist user-supplied axis strings to {x,y,z}.","Never pass dimension indices or strings where a char axis is expected.","Initialize axis variables to a valid default."],"tags":["cimg","haar","invalid-argument","enum"],"backgroundTag":"invalid-enum-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"}