Skip to content

Commit e6e5a95

Browse files
authored
Merge pull request #4487 from neiljohari/adhoc/dictionary-file-counting
make DiB_fileStats skip invalid files (fileSize <= 0) to prevent negative totals and bogus allocation
2 parents d190b38 + 236e44f commit e6e5a95

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

programs/dibio.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,15 @@ static fileStats DiB_fileStats(const char** fileNamesTable, int nbFiles, size_t
280280
for (n=0; n<nbFiles; n++) {
281281
S64 const fileSize = DiB_getFileSize(fileNamesTable[n]);
282282
/* TODO: is there a minimum sample size? What if the file is 1-byte? */
283-
if (fileSize == 0) {
284-
DISPLAYLEVEL(3, "Sample file '%s' has zero size, skipping...\n", fileNamesTable[n]);
283+
/* Skip empty or invalid files */
284+
if (fileSize <= 0) {
285+
if (fileSize < 0) {
286+
DISPLAYLEVEL(3, "Sample file '%s' is unreadable or stat failed, skipping...\n",
287+
fileNamesTable[n]);
288+
} else {
289+
DISPLAYLEVEL(3, "Sample file '%s' has zero size, skipping...\n",
290+
fileNamesTable[n]);
291+
}
285292
continue;
286293
}
287294

0 commit comments

Comments
 (0)