{"record":{"id":"286761b517e7dbea","repo":"Yalantis/uCrop","slug":"save-tiff-specified-filename-is-null","errorCode":null,"errorMessage":"save_tiff(): Specified filename is (null).","messagePattern":"save_tiff\\(\\): Specified filename is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":62715,"sourceCode":"          24=PIXARFILM | 25=PIXARLOG | 26=SGILOG | 27=SGILOG24 | 28=T43 | 29=T85 | 30=THUNDERSCAN |\n          31=WEBP | 32=ZSTD }</tt>\n       \\param[out] voxel_size Voxel size, to be stored in the filename.\n       \\param[out] description Description, to be stored in the filename.\n       \\param use_bigtiff Allow to save big tiff files (>4Gb).\n       \\note\n       - libtiff support is enabled by defining the precompilation\n        directive \\c cimg_use_tiff.\n       - When libtiff is enabled, 2D and 3D (multipage) several\n        channel per pixel are supported for\n        <tt>char,uchar,short,ushort,float</tt> and \\c double pixel types.\n       - If \\c cimg_use_tiff is not defined at compile time the\n        function uses CImg<T>&save_other(const char*).\n     **/\n    const CImg<T>& save_tiff(const char *const filename, const unsigned int compression_type=0,\n                             const float *const voxel_size=0, const char *const description=0,\n                             const bool use_bigtiff=true) const {\n      if (!filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_tiff(): Specified filename is (null).\",\n                                    cimg_instance);\n      if (is_empty()) { cimg::fempty(0,filename); return *this; }\n\n#ifdef cimg_use_tiff\n      const bool\n        _use_bigtiff = use_bigtiff && sizeof(ulongT)>=8 && size()*sizeof(T)>=1UL<<31; // No bigtiff for small images\n      TIFF *tif = TIFFOpen(filename,_use_bigtiff?\"w8\":\"w4\");\n      if (tif) {\n        double val_min, val_max = (double)max_min(val_min);\n        cimg_forZ(*this,z) _save_tiff(tif,z,z,compression_type,voxel_size,description,val_min,val_max);\n        TIFFClose(tif);\n      } else throw CImgIOException(_cimg_instance\n                                   \"save_tiff(): Failed to open file '%s' for writing.\",\n                                   cimg_instance,\n                                   filename);\n      return *this;\n#else","sourceCodeStart":62697,"sourceCodeEnd":62733,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L62697-L62733","documentation":"Raised by save_tiff()'s validation path when both the output FILE* and the filename are null, so no write target exists for the TIFF data; the message shows the filename argument as the literal '(null)'. This is the standard CImg sentinel guard for missing I/O arguments, not a libtiff encoding error — supply a filename or an open file handle.","triggerScenarios":"Calling img.save_tiff(NULL) or save_tiff(someNullCharPtr); passing a null const char* from a config/variable that was never set; generic save() with an empty/null resolved name routed to the TIFF path.","commonSituations":"Batch exporters where the TIFF output field is optional but the call is unconditional; null from string::c_str misuse of a released buffer; uninitialized char* in C-style glue code (JNI).","solutions":["Pass a non-null filename string to save_tiff()","Validate the path before calling save_tiff()","Skip or branch the call when no TIFF output was requested"],"exampleFix":"// before\nimg.save_tiff(tiffName); // tiffName may be NULL\n// after\nif (tiffName) img.save_tiff(tiffName);\nelse cimg::warn(\"no TIFF output requested, skipping\");","handlingStrategy":"validation","validationCode":"if (!filename || !*filename) throw std::invalid_argument(\"save_tiff requires a filename\");","typeGuard":"bool isValidFilename(const char *name) { return name != NULL && name[0] != '\\0'; }","tryCatchPattern":"try { img.save_tiff(path.c_str()); } catch (CImgArgumentException &e) { /* missing destination */ }","preventionTips":["TIFF has no FILE* overload — always supply a filename string","Check optional config fields before unconditionally saving","Avoid null char* in JNI glue; use checked jstring conversion"],"tags":["null-argument","tiff","api-misuse"],"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"}