From 7905c1b20f6ffdfeba0e63bce4fe5ec7c426deb2 Mon Sep 17 00:00:00 2001 From: nishi Date: Sun, 26 May 2024 10:36:54 +0000 Subject: [PATCH] add too many tables error git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@119 d4a5a174-5a4a-5b4b-b672-37683c10d7d5 --- Library/database.c | 2 +- Library/database_table.c | 7 +++++++ Library/dw_database.h | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Library/database.c b/Library/database.c index a18cdd7..861c850 100644 --- a/Library/database.c +++ b/Library/database.c @@ -38,7 +38,7 @@ const char sig[3] = {0x7f, 'D', 'W'}; -const char* dw_errors[] = {"Success", "Used already", "File open fail", "Invalid signature", "Invalid version", "Parser returned NULL", "Cannot call non-method", "Unknown method", "Insufficient arguments", "Too many arguments", "Not used"}; +const char* dw_errors[] = {"Success", "Used already", "File open fail", "Invalid signature", "Invalid version", "Parser returned NULL", "Cannot call non-method", "Unknown method", "Insufficient arguments", "Too many arguments", "Not used", "Too many tables"}; #ifdef M_I86 #define BUFSIZE 128 diff --git a/Library/database_table.c b/Library/database_table.c index c1815ac..41e1f4c 100644 --- a/Library/database_table.c +++ b/Library/database_table.c @@ -72,6 +72,7 @@ int dataworks_database_create_table(struct dataworks_db* db, const char* name, c int i; struct dataworks_db_v1_indexentry index; char* buf = malloc(1 + 8 + 1 + 256 + 4096); + int cnt = 0; for(i = 0; i < 256; i++) { fread(buf, 1, 1 + 8 + 1 + 256 + 4096, db->fp); __dw_buffer_to_db_v1_indexentry(buf, index); @@ -85,8 +86,14 @@ int dataworks_database_create_table(struct dataworks_db* db, const char* name, c __dw_unlockfile(db->fp); return DW_ERR_USED; } + cnt++; } } + if(cnt == 256) { + free(buf); + __dw_unlockfile(db->fp); + return DW_ERR_TOO_MANY_TABLES; + } fseek(db->fp, 3 + 10, SEEK_SET); for(i = 0; i < 256; i++) { fread(buf, 1, 1 + 8 + 1 + 256 + 4096, db->fp); diff --git a/Library/dw_database.h b/Library/dw_database.h index 244d01f..fbf9ecb 100644 --- a/Library/dw_database.h +++ b/Library/dw_database.h @@ -135,6 +135,13 @@ enum DW_ERRORS { * */ DW_ERR_NOT_USED, + + /** + * @~english + * @brief Too many tables + * + */ + DW_ERR_TOO_MANY_TABLES, }; /** -- 2.43.0