{"record":{"id":"2f26ccd2926400fb","repo":"Yalantis/uCrop","slug":"sort-invalid-specified-axis-c-should-be-x","errorCode":null,"errorMessage":"sort(): Invalid specified axis '%c' (should be { x | y | z | c }).","messagePattern":"sort\\(\\): Invalid specified axis '%c' \\(should be (.+?)\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":33347,"sourceCode":"        perm.assign(_height);\n        get_crop(0,0,0,0,0,_height - 1,0,0).sort(perm,is_increasing);\n        CImg<T> img(*this,false);\n        cimg_forXYZC(*this,x,y,z,c) (*this)(x,y,z,c) = img(x,perm[y],z,c);\n      } break;\n      case 'z' : {\n        perm.assign(_depth);\n        get_crop(0,0,0,0,0,0,_depth - 1,0).sort(perm,is_increasing);\n        CImg<T> img(*this,false);\n        cimg_forXYZC(*this,x,y,z,c) (*this)(x,y,z,c) = img(x,y,perm[z],c);\n      } break;\n      case 'c' : {\n        perm.assign(_spectrum);\n        get_crop(0,0,0,0,0,0,0,_spectrum - 1).sort(perm,is_increasing);\n        CImg<T> img(*this,false);\n        cimg_forXYZC(*this,x,y,z,c) (*this)(x,y,z,c) = img(x,y,z,perm[c]);\n      } break;\n      default :\n        throw CImgArgumentException(_cimg_instance\n                                    \"sort(): Invalid specified axis '%c' \"\n                                    \"(should be { x | y | z | c }).\",\n                                    cimg_instance,axis);\n      }\n      return *this;\n    }\n\n    //! Sort pixel values \\newinstance.\n    CImg<T> get_sort(const bool is_increasing=true, const char axis=0) const {\n      return (+*this).sort(is_increasing,axis);\n    }\n\n    template<typename t>\n    CImg<T>& _quicksort(const long indm, const long indM, CImg<t>& permutations,\n                        const bool is_increasing, const bool is_permutations) {\n      if (indm<indM) {\n        const long mid = (indm + indM)/2;\n        if (is_increasing) {","sourceCodeStart":33329,"sourceCodeEnd":33365,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L33329-L33365","documentation":"CImg<T>::sort(axis) sorts pixel values along one of the four image axes identified by the characters 'x','y','z','c'. Any other axis character is rejected by CImgArgumentException at the switch default.","triggerScenarios":"Calling sort(axis, is_increasing) with axis not in {'x','y','z','c'} — e.g. 'X', 'w', 0, or a variable holding an unexpected char.","commonSituations":"Typo or case mismatch ('X' vs 'x'); passing an axis taken from user config or CLI without validation; confusion between axis chars and axis indices in other APIs.","solutions":["Pass exactly one of 'x','y','z','c' (lowercase)","Validate/normalize the axis character before the call and reject invalid input early","Map indices 0-3 to 'x','y','z','c' if your config stores numeric axes"],"exampleFix":"// before\nimg.sort(userAxis); // userAxis == 'X'\n// after\nchar ax = std::tolower(userAxis);\nif (ax!='x' && ax!='y' && ax!='z' && ax!='c') throw std::invalid_argument(\"axis\");\nimg.sort(ax, true);","handlingStrategy":"validation","validationCode":"if (axis!='x' && axis!='y' && axis!='z' && axis!='c') throw std::invalid_argument(\"sort axis must be x, y, z or c\");","typeGuard":"bool isValidAxis(char a) { return a=='x' || a=='y' || a=='z' || a=='c'; }","tryCatchPattern":"try { img.sort(axis, true); } catch (CImgArgumentException& e) { /* normalize axis or report invalid axis */ }","preventionTips":["Always pass lowercase axis chars","Whitelist axis chars when they come from config or CLI","Map numeric axes 0-3 to 'x','y','z','c' explicitly"],"tags":["cimg","sort","invalid-argument","axis"],"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"}