Skip to content

Commit b7fda0b

Browse files
committed
Patched error counting bytes when using -T and -f1 or -f is not indicated
1 parent 3b55ded commit b7fda0b

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

statistics.c

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int main ( int argc, char *argv[] ) {
4242
bool bShowGlobalFileStatistics=false;
4343
unsigned long long slice_size = 0ULL;
4444
unsigned long long slice_number = 0ULL;
45-
unsigned long long from_byte = 0ULL;
45+
unsigned long long from_byte = 1ULL;
4646
unsigned long long to_byte = 0ULL;
4747
unsigned long long to_byte_increment = 0ULL;
4848

@@ -351,12 +351,13 @@ int analyze_file(
351351

352352
}
353353

354+
if ( from_byte > file_size ) {
355+
fprintf(stderr, "Error: file '%s' smaller than `-f %llu`.\n", szFile, from_byte);
356+
return 2;
357+
}
358+
354359
// seek to from_byte position
355-
if ( from_byte > 0ULL ) {
356-
if ( from_byte > file_size ) {
357-
fprintf(stderr, "Error: file '%s' smaller than `-f %llu`.\n", szFile, from_byte);
358-
return 2;
359-
}
360+
if ( from_byte > 1ULL ) {
360361
if ( 0 != fseeko( hFile, from_byte - 1, SEEK_SET) ) {
361362
fprintf(stderr, "Error: cannot seek file '%s' to position '%llu'.\n", szFile, from_byte);
362363
return 2;
@@ -369,7 +370,7 @@ int analyze_file(
369370
if ( 0 == strlen(szFile) ) {
370371
// adjust buffer_length with STDIN if from_byte
371372
// before entering the processing loop
372-
if ( from_byte > 0ULL ) {
373+
if ( from_byte > 1ULL ) {
373374
buffer_length = BUFFER_LENGTH;
374375
do {
375376

@@ -385,8 +386,8 @@ int analyze_file(
385386
bytes_read > 0 );
386387
}
387388
// from_byte may has been too big for STDIN input
388-
if ( from_byte > 0ULL &&
389-
total_bytes_read < (from_byte - 1)
389+
if ( from_byte > 1ULL &&
390+
total_bytes_read < from_byte
390391
) {
391392
fprintf(stderr, "Error: data input smaller (%llu bytes) than -f %llu\n", (unsigned long long)total_bytes_read, from_byte);
392393
return 2;
@@ -522,9 +523,7 @@ int analyze_file(
522523
&sigma,
523524
&mean,
524525
&number_of_byte_buckets,
525-
( from_byte > 0ULL )?
526-
( total_bytes_read - from_byte + 1 ):
527-
total_bytes_read
526+
total_bytes_read - from_byte + 1
528527
);
529528

530529
// fill circle's container matrix with zeros
@@ -548,12 +547,8 @@ int analyze_file(
548547
list_bytes,
549548
number_of_byte_buckets,
550549
szFile,
551-
( from_byte > 0ULL )?
552-
( total_bytes_read - from_byte + 1 ):
553-
total_bytes_read,
554-
( from_byte > 0ULL )?
555-
( total_bytes_read - from_byte + 1 ):
556-
total_bytes_read,
550+
total_bytes_read - from_byte + 1,
551+
total_bytes_read - from_byte + 1,
557552
0ULL,
558553
0ULL,
559554
from_byte,
@@ -742,15 +737,19 @@ void print_circle_on_screen(
742737
printf("file =\t%s", szFile);
743738
}
744739

745-
if ( slice_size > 0 ) {
740+
if ( slice_size > 0ULL ) {
746741
printf( " , [%llu-%llu] bytes, (slice %llu)",
747742
total_bytes_read + 1, total_bytes_read + total_size, slice_actual_number );
748743
} else {
749-
if ( from_byte > 0 ||
750-
to_byte > 0 ) {
751-
// always consider the first byte as '1', not '0'
752-
// (0==slice_actual_number used as `-g` indicator)
753-
printf( " , [%llu-%llu] bytes", ( (from_byte>0ULL)? from_byte: 1ULL ), (0==slice_actual_number)?( (0==to_byte)?(from_byte + total_bytes_read - 1):to_byte ):(total_bytes_read + total_size) );
744+
if ( from_byte > 1ULL ||
745+
to_byte > 0ULL ) {
746+
// first byte is 1, not 0
747+
printf( " , [%llu-%llu] bytes",
748+
from_byte,
749+
(0ULL==slice_actual_number)? // 0ULL==slice_actual_number used as `-g` indicator
750+
( (0ULL==to_byte)?(from_byte + total_bytes_read - 1):to_byte ):
751+
(total_bytes_read + total_size)
752+
);
754753
}
755754
}
756755
printf("\n");

0 commit comments

Comments
 (0)