From a77afb9b7d8d3e0977d95a35a76ae2e55cbdde18 Mon Sep 17 00:00:00 2001 From: Anatoli Arkhipenko Date: Sat, 12 Aug 2023 21:55:55 -0400 Subject: [PATCH] fix: division by zero. header read validation --- EDB.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/EDB.cpp b/EDB.cpp index a4c4115..c63a3a3 100644 --- a/EDB.cpp +++ b/EDB.cpp @@ -86,7 +86,7 @@ EDB_Status EDB::open(unsigned long head_ptr) // Thanks to Steve Kelly for the next line... EDB_table_ptr = sizeof(EDB_Header) + EDB_head_ptr; // this line was originally missing in the downloaded library readHead(); - return EDB_OK; + return (EDB_head.flag == EDB_FLAG ? EDB_OK : EDB_ERROR); } // writes a record to a given recno @@ -172,6 +172,9 @@ unsigned long EDB::count() // returns the maximum number of items that will fit into the queue unsigned long EDB::limit() { + + // in case of currept db, the record len could be a zero + if ( EDB_head.rec_size == 0 ) return 0; // Thanks to oleh.sok...@gmail.com for the next line return (EDB_head.table_size - sizeof(EDB_Header)) / EDB_head.rec_size; }