Skip to content

Commit 84ff831

Browse files
measure file size with SEEK_END
I thought that's not portable but the rest of the codebase uses it so no reason not to
1 parent 1cd0c20 commit 84ff831

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

features/FEATURE_BLE/source/generic/FileSecurityDb.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,9 @@ FILE* FileSecurityDb::open_db_file(const char *db_path) {
112112

113113
if ((fread(&version, sizeof(version), 1, db_file) == 1) &&
114114
(version == DB_VERSION)) {
115-
/* version checks out, try the size */
116-
fseek(db_file, DB_SIZE - 1, SEEK_SET);
117-
/* read one byte and expect to hit EOF */
118-
if ((fread(&version, 1, 1, db_file) != 1) || !feof(db_file)) {
115+
/* if file size differs from database size init the file */
116+
fseek(db_file, 0, SEEK_END);
117+
if (ftell(db_file) != DB_SIZE) {
119118
init = true;
120119
}
121120
} else {

0 commit comments

Comments
 (0)