From: Harlan Stenn Date: Wed, 26 Aug 2009 08:14:45 +0000 (-0400) Subject: The 2nd fopen in write_kod_db() must be inside the block. From Dave Hart. X-Git-Tag: NTP_4_2_5P206~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49ccd00d9e9d644731483449971bf78cb6ed2738;p=thirdparty%2Fntp.git The 2nd fopen in write_kod_db() must be inside the block. From Dave Hart. bk: 4a94eef57nSEwQlIu343XAIEXm2uEg --- diff --git a/sntp/kod_management.c b/sntp/kod_management.c index ca0bc2977..dcb336ea8 100644 --- a/sntp/kod_management.c +++ b/sntp/kod_management.c @@ -43,7 +43,7 @@ search_entry ( register int a, b, resc = 0; for (a = 0; a < kod_db_cnt; a++) - if (!strcmp(kod_db[a]->hostname, hostname)) + if (!strcmp(kod_db[a]->hostname, hostname)) resc++; if (!resc) @@ -62,7 +62,7 @@ search_entry ( } -void +void add_entry( char *hostname, char *type /* 4 bytes not \0 terminated */ @@ -85,7 +85,7 @@ add_entry( } -void +void delete_entry( char *hostname, char *type @@ -105,12 +105,12 @@ delete_entry( kod_db_cnt--; if (a < kod_db_cnt) - memmove(&kod_db[a], &kod_db[a + 1], + memmove(&kod_db[a], &kod_db[a + 1], (kod_db_cnt - a) * sizeof(kod_db[0])); } -void +void write_kod_db(void) { FILE *db_s; @@ -135,14 +135,13 @@ write_kod_db(void) *pch = DIR_SEP; pch = strchr(pch + 1, DIR_SEP); } + db_s = fopen(kod_db_file, "w"); } - - db_s = fopen(kod_db_file, "w"); if (NULL == db_s) { char msg[80]; - snprintf(msg, sizeof(msg), + snprintf(msg, sizeof(msg), "Can't open KOD db file %s for writing!", kod_db_file); #ifdef DEBUG @@ -152,7 +151,7 @@ write_kod_db(void) return; } - + for (a = 0; a < kod_db_cnt; a++) { fprintf(db_s, "%16.16llx %s %s\n", (unsigned long long) kod_db[a]->timestamp, kod_db[a]->type, @@ -164,7 +163,7 @@ write_kod_db(void) } -void +void kod_init_kod_db( const char *db_file ) @@ -173,7 +172,7 @@ kod_init_kod_db( * Max. of 254 characters for hostname, 10 for timestamp, 4 for * kisscode, 2 for spaces, 1 for \n, and 1 for \0 */ - char fbuf[272]; + char fbuf[254+10+4+2+1+1]; FILE *db_s; int a, b, sepc; unsigned long long ull; @@ -204,7 +203,7 @@ kod_init_kod_db( return; } - if(ENABLED_OPT(NORMALVERBOSE)) + if(ENABLED_OPT(NORMALVERBOSE)) printf("Starting to read KoD file %s...\n", db_file); /* First let's see how many entries there are and check for right syntax */ @@ -214,12 +213,12 @@ kod_init_kod_db( /* ignore blank lines */ if ('\n' == fbuf[0]) continue; - + sepc = 0; for(a=0; a