{"record":{"id":"5dd46932d7b37a6a","repo":"Yalantis/uCrop","slug":"save-yuv-specified-filename-is-null","errorCode":null,"errorMessage":"save_yuv(): Specified filename is (null).","messagePattern":"save_yuv\\(\\): Specified filename is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":68095,"sourceCode":"    }\n\n    //! Save image sequence into a YUV file.\n    /**\n      \\param file File to write data to.\n      \\param chroma_subsampling Type of chroma subsampling. Can be <tt>{ 420 | 422 | 444 }</tt>.\n      \\param is_rgb Tells if the RGB to YUV conversion must be done for saving.\n    **/\n    const CImgList<T>& save_yuv(std::FILE *const file,\n                                const unsigned int chroma_subsampling=444,\n                                const bool is_rgb=true) const {\n      return _save_yuv(file,0,chroma_subsampling,is_rgb);\n    }\n\n    const CImgList<T>& _save_yuv(std::FILE *const file, const char *const filename,\n                                 const unsigned int chroma_subsampling,\n                                 const bool is_rgb) const {\n      if (!file && !filename)\n        throw CImgArgumentException(_cimglist_instance\n                                    \"save_yuv(): Specified filename is (null).\",\n                                    cimglist_instance);\n      if (chroma_subsampling!=420 && chroma_subsampling!=422 && chroma_subsampling!=444)\n        throw CImgArgumentException(_cimglist_instance\n                                    \"save_yuv(): Specified chroma subsampling %u is invalid, for file '%s'.\",\n                                    cimglist_instance,\n                                    chroma_subsampling,filename?filename:\"(FILE*)\");\n      if (is_empty()) { cimg::fempty(file,filename); return *this; }\n      const unsigned int\n        cfx = chroma_subsampling==420 || chroma_subsampling==422?2:1,\n        cfy = chroma_subsampling==420?2:1,\n        w0 = (*this)[0]._width, h0 = (*this)[0]._height,\n        width0 = w0 + (w0%cfx), height0 = h0 + (h0%cfy);\n      std::FILE *const nfile = file?file:cimg::fopen(filename,\"wb\");\n      cimglist_for(*this,l) {\n        const CImg<T> &frame = (*this)[l];\n        cimg_forZ(frame,z) {\n          CImg<ucharT> YUV;","sourceCodeStart":68077,"sourceCodeEnd":68113,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L68077-L68113","documentation":"CImgList::_save_yuv() throws CImgArgumentException when both the FILE* and the filename are null — at least one output target must be provided. (A subsequent check in the same function separately validates the chroma_subsampling value.) This is the yuv equivalent of the null-filename guards in other save methods.","triggerScenarios":"Calling save_yuv(filename,...) with a null filename and no open FILE*; a wrapper that forwards an optional FILE* and optional path where both ended up unset.","commonSituations":"Config/CLI supplying neither an output file nor a stream; optional argument plumbing where a default output path was removed; JNI bridge passing null for both file handle and path.","solutions":["Provide either a valid filename string or an opened std::FILE* to save_yuv().","Validate output parameters (file or path) at the call site before invoking.","Default to a standard output filename when neither is configured."],"exampleFix":"// before\nconst char *path = cfg.output; // may be NULL\nlist.save_yuv(path, 420); // throws when both null\n// after\nlist.save_yuv(cfg.output ? cfg.output : \"out.yuv\", 420);","handlingStrategy":"validation","validationCode":"if (!file && !filename) {\n  fprintf(stderr, \"save_yuv needs a FILE* or a filename\\n\");\n  return false;\n}","typeGuard":"bool hasYuvTarget(std::FILE *f, const char *name) { return f != nullptr || (name != nullptr && *name != '\\0'); }","tryCatchPattern":"try { list.save_yuv(file_or_name, subsampling); }\ncatch (CImgArgumentException &e) { fprintf(stderr, \"Provide an output file for YUV save\\n\"); }","preventionTips":["Always supply either an open FILE* or a path.","Validate output configuration before the save call.","Also validate chroma subsampling is 420/422/444 at the same time."],"tags":["yuv","save","null"],"backgroundTag":"null-argument","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"}