From 791d9e09ac81cb2da06ec4c5eb3b957db136774d Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 21 Jul 2024 11:37:47 +0200 Subject: [PATCH] write check wrong, write returns number of bytes written, hence always larger than 0. Thanks to @mwalker33 for the fix --- tools/hitag2crack/crack2/ht2crack2buildtable.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tools/hitag2crack/crack2/ht2crack2buildtable.c b/tools/hitag2crack/crack2/ht2crack2buildtable.c index 29d8987d0..625a0f175 100644 --- a/tools/hitag2crack/crack2/ht2crack2buildtable.c +++ b/tools/hitag2crack/crack2/ht2crack2buildtable.c @@ -430,7 +430,7 @@ static void *sorttable(void *dd) { printf("cannot create outfile %s\n", outfile); exit(1); } - if (write(fdout, table, numentries * DATASIZE)) { + if (write(fdout, table, numentries * DATASIZE) != (numentries * DATASIZE)) { printf("writetable cannot write all of the data\n"); exit(1); } @@ -454,7 +454,7 @@ int main(int argc, char *argv[]) { // make the table of tables t = (struct table *)calloc(sizeof(struct table) * 65536, sizeof(uint8_t)); if (!t) { - printf("malloc failed\n"); + printf("calloc failed\n"); exit(1); } @@ -503,11 +503,8 @@ int main(int argc, char *argv[]) { free_tables(t); free(t); - - // now for the sorting - // start the threads for (long i = 0; i < NUM_SORT_THREADS; i++) { int ret = pthread_create(&(threads[i]), NULL, sorttable, (void *)(i));