{"record":{"id":"c3d1029c9e6d9b8a","repo":"Yalantis/uCrop","slug":"load-ascii-only-lu-lu-values-read-from-file","errorCode":null,"errorMessage":"load_ascii(): Only %lu/%lu values read from file '%s'.","messagePattern":"load_ascii\\(\\): Only %lu/%lu values read from file '(.+?)'\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":56682,"sourceCode":"      if (!dx || !dy || !dz || !dc) {\n        if (!file) cimg::fclose(nfile);\n        throw CImgIOException(_cimg_instance\n                              \"load_ascii(): Invalid ascii header in file '%s', image dimensions are set \"\n                              \"to (%u,%u,%u,%u).\",\n                              cimg_instance,\n                              filename?filename:\"(FILE*)\",dx,dy,dz,dc);\n      }\n      assign(dx,dy,dz,dc);\n      const ulongT siz = size();\n      ulongT off = 0;\n      double val;\n      T *ptr = _data;\n      for (err = 1, off = 0; off<siz && err==1; ++off) {\n        err = std::fscanf(nfile,\"%lf%*[^0-9.eEinfa+-]\",&val);\n        *(ptr++) = (T)val;\n      }\n      if (err!=1)\n        cimg::warn(_cimg_instance\n                   \"load_ascii(): Only %lu/%lu values read from file '%s'.\",\n                   cimg_instance,\n                   off - 1,siz,filename?filename:\"(FILE*)\");\n\n      if (!file) cimg::fclose(nfile);\n      return *this;\n    }\n\n    //! Load image from a DLM file.\n    /**\n      \\param filename Filename, as a C-string.\n    **/\n    CImg<T>& load_dlm(const char *const filename) {\n      return _load_dlm(0,filename);\n    }\n\n    //! Load image from a DLM file \\newinstance.\n    static CImg<T> get_load_dlm(const char *const filename) {","sourceCodeStart":56664,"sourceCodeEnd":56700,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L56664-L56700","documentation":"CImg::load_ascii() parses whitespace-separated numeric values from a .cimg/.ascii file using fscanf(\"%lf...\"); when fscanf stops returning 1 before the expected number of values is read, CImg warns with the count actually read (off-1 of siz) and returns the partially filled image. The image is truncated, not the correct size/content.","triggerScenarios":"Loading an ASCII CImg file whose text contains fewer parseable numbers than the header-declared size, or non-numeric garbage where a value was expected; also a mid-file I/O error.","commonSituations":"Hand-edited data files with missing values; files truncated by a failed transfer or interrupted save; locale/text issues introducing unexpected characters; wrong file passed to load_ascii.","solutions":["Verify the file contains exactly width*height*depth*spectrum numeric values matching its header","Check the file size/completeness (re-transfer or re-export the file if truncated)","Open the file and inspect the area around value off-1 for non-numeric garbage","Check the fscanf return value path: treat the partially filled image as invalid instead of using it","Regenerate the file programmatically (e.g. save in binary .cimg format) to avoid ASCII parsing issues"],"exampleFix":"// before\nCImg<float> img;\nimg.load_ascii(\"data.txt\"); // truncated file -> partial data\n// after\nstd::FILE* f = std::fopen(\"data.txt\", \"r\");\nCImg<unsigned long> dims;\ndims.load_cimg_header(f); // or validate value count beforehand\ncimg::fclose(f);\nCImg<float> img;\nimg.load_ascii(\"data.txt\");","handlingStrategy":"validation","validationCode":"bool asciiDataComplete(const char* path, unsigned long expected) {\n  std::ifstream in(path);\n  double v; unsigned long n = 0;\n  while (in >> v) ++n;\n  return n == expected;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer binary .cimg over ASCII for large data","Validate the value count against the header before load_ascii","Never hand-edit ASCII data files; regenerate programmatically","Verify file integrity (size/checksum) after transfers"],"tags":["cimg","file-io","ascii-parsing"],"backgroundTag":"file-parse-failed","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"}