otrx: avoid unneeded fseek() when calculating CRC32
authorRafał Miłecki <rafal@milecki.pl>
Fri, 26 Nov 2021 06:23:10 +0000 (07:23 +0100)
committerRafał Miłecki <rafal@milecki.pl>
Fri, 26 Nov 2021 06:23:10 +0000 (07:23 +0100)
Just use already read data.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
src/otrx.c

index b5cd70d6c8e26209c76d2f327211a064506f26b2..aa81c96c5475843a31b25e31ae0fd47a4d713fc4 100644 (file)
@@ -193,8 +193,8 @@ static int otrx_check(int argc, char **argv) {
        }
 
        crc32 = 0xffffffff;
        }
 
        crc32 = 0xffffffff;
-       fseek(trx, trx_offset + TRX_FLAGS_OFFSET, SEEK_SET);
-       length -= TRX_FLAGS_OFFSET;
+       crc32 = otrx_crc32(crc32, (uint8_t *)&hdr + TRX_FLAGS_OFFSET, sizeof(hdr) - TRX_FLAGS_OFFSET);
+       length -= sizeof(hdr);
        while ((bytes = fread(buf, 1, otrx_min(sizeof(buf), length), trx)) > 0) {
                crc32 = otrx_crc32(crc32, buf, bytes);
                length -= bytes;
        while ((bytes = fread(buf, 1, otrx_min(sizeof(buf), length), trx)) > 0) {
                crc32 = otrx_crc32(crc32, buf, bytes);
                length -= bytes;