From 3fab71345b327e03c84d2cf67419f61a3e252b60 Mon Sep 17 00:00:00 2001 From: Peter Howkins Date: Mon, 5 Jan 2015 16:54:12 +0000 Subject: [PATCH] dtsr: resolve all 12 compiler warnings. --- cde/programs/dtsr/dtsrclean.c | 11 ++++++++--- cde/programs/dtsr/dtsrhan.c | 5 +++-- cde/programs/dtsr/dtsrindex.c | 4 ++-- cde/programs/dtsr/dtsrload.c | 4 ++-- cde/programs/dtsr/huffcode.c | 5 ++++- cde/programs/dtsr/tomita.c | 19 +++++++++++++++---- 6 files changed, 34 insertions(+), 14 deletions(-) diff --git a/cde/programs/dtsr/dtsrclean.c b/cde/programs/dtsr/dtsrclean.c index fdd5d9d3..2bc3e403 100644 --- a/cde/programs/dtsr/dtsrclean.c +++ b/cde/programs/dtsr/dtsrclean.c @@ -691,6 +691,8 @@ static void copy_new_d99 (long keyfield) */ done = FALSE; while (!done) { /* loop on each block in this word */ + int ret = 0; + if (num_holes > MAX_REC_READ) { num_reads = MAX_REC_READ; num_holes -= MAX_REC_READ; @@ -700,8 +702,8 @@ static void copy_new_d99 (long keyfield) num_reads = num_holes; } errno = 0; - fread (word_addrs, sizeof(DB_ADDR), (size_t)num_reads, fp_d99_old); - if (errno) { + ret = fread (word_addrs, sizeof(DB_ADDR), (size_t)num_reads, fp_d99_old); + if (errno || -1 == ret) { TERMINATE_LINE (); fprintf (aa_stderr, catgets(dtsearch_catd, MS_dtsrclean, 657, "%s Read error on %s: %s.\n"), @@ -1138,7 +1140,10 @@ int main (int argc, char *argv[]) aa_stderr); *readbuf = '\0'; - fgets (readbuf, sizeof(readbuf), stdin); + if(NULL == fgets (readbuf, sizeof(readbuf), stdin)) { + fprintf (aa_stderr, "Failed to read from stdin\n"); + end_of_job (2, SHOW_EXITCODE); + } if (strlen(readbuf) && readbuf[strlen(readbuf)-1] == '\n') readbuf[strlen(readbuf)-1] = '\0'; diff --git a/cde/programs/dtsr/dtsrhan.c b/cde/programs/dtsr/dtsrhan.c index 76f7f0db..c7e7055d 100644 --- a/cde/programs/dtsr/dtsrhan.c +++ b/cde/programs/dtsr/dtsrhan.c @@ -578,9 +578,10 @@ void process_profile () } /*-- Get next line --*/ do { - fgets (prof_line, 200, prof); + char *ret = NULL; + ret = fgets (prof_line, 200, prof); line_num++; - if (feof (prof)) + if (ret == NULL || feof (prof) ) break; if (prof_line[0] == '#' || is_blank (prof_line)) continue; diff --git a/cde/programs/dtsr/dtsrindex.c b/cde/programs/dtsr/dtsrindex.c index c94c9cc8..2f1ff3e8 100644 --- a/cde/programs/dtsr/dtsrindex.c +++ b/cde/programs/dtsr/dtsrindex.c @@ -1089,7 +1089,7 @@ void write_new_word_2_dtbs (void) got_word.or_hwoffset = ftell (dtbs_addr_fp); got_word.or_hwfree = 0; if (debugging & (DEBUG_n | DEBUG_N)) - printf ("APPEND ofs=%ld, fre=0\n", got_word.or_hwoffset); + printf ("APPEND ofs=%ld, fre=0\n", (long int) got_word.or_hwoffset); } else { ret_fseek = fseek (dtbs_addr_fp, @@ -1099,7 +1099,7 @@ void write_new_word_2_dtbs (void) num_addrs_for_word; if (debugging & (DEBUG_n | DEBUG_N)) printf (" REUSE slot ofs=%ld, fre=%ld\n", - got_word.or_hwoffset, got_word.or_hwfree); + (long int) got_word.or_hwoffset, (long int) got_word.or_hwfree); } /***** Write new database addresses to d99 file *********/ diff --git a/cde/programs/dtsr/dtsrload.c b/cde/programs/dtsr/dtsrload.c index b633199b..abe0b090 100644 --- a/cde/programs/dtsr/dtsrload.c +++ b/cde/programs/dtsr/dtsrload.c @@ -703,7 +703,7 @@ static void create_object (char *key) UPDATE_MAXDBA (objdba); if (debug_mode) printf ("---> new rec: inrecno %6ld, slot %6ld, key '%s'\n", - input_reccount, objdba & 0xffffff, objrec.or_objkey); + (long int) input_reccount, (long int) objdba & 0xffffff, objrec.or_objkey); /* Make current object record the owner of all its sets */ SETOR (PROGNAME "376", OR_OBJ_BLOBS, 0); @@ -762,7 +762,7 @@ static void update_object (char *key) UPDATE_MAXDBA (objdba); if (debug_mode) printf ("----> update: inrecno %6ld, slot %6ld, key '%s'\n", - input_reccount, objdba & 0xffffff, key); + (long int) input_reccount, (long int) objdba & 0xffffff, key); /* Reinit certain fields. * Objsize will be rewritten after new text size determined. diff --git a/cde/programs/dtsr/huffcode.c b/cde/programs/dtsr/huffcode.c index 5449c33b..c5f3b710 100644 --- a/cde/programs/dtsr/huffcode.c +++ b/cde/programs/dtsr/huffcode.c @@ -467,7 +467,10 @@ static void init_treebase (void) */ else { no_huffcode_file = FALSE; - fgets (filebuf, sizeof (filebuf) - 1, instream_huf); + if(NULL == fgets (filebuf, sizeof (filebuf) - 1, instream_huf)) { + fprintf (stderr, "No first line in file\n"); + exit(2); + } /* discard this first line (don't need id stamp) */ while (fgets (filebuf, sizeof (filebuf) - 1, instream_huf) != NULL) { diff --git a/cde/programs/dtsr/tomita.c b/cde/programs/dtsr/tomita.c index 91aad3ba..92076405 100644 --- a/cde/programs/dtsr/tomita.c +++ b/cde/programs/dtsr/tomita.c @@ -89,6 +89,7 @@ #include #include #include +#include #define PRINT_MESSAGES \ { puts (DtSearchGetMessages()); DtSearchFreeMessages(); } @@ -475,7 +476,10 @@ DISPLAY_RECORD: "\n...push ENTER to continue... ") ); *userbuf = '\0'; - fgets (userbuf, sizeof (userbuf), stdin); + if(NULL == fgets (userbuf, sizeof (userbuf), stdin)) { + fprintf(stderr, "Failed to read from stdin\n"); + exit(EXIT_FAILURE); + } if (strlen(userbuf) && userbuf[strlen(userbuf)-1] == '\n') userbuf[strlen(userbuf)-1] = '\0'; @@ -504,8 +508,12 @@ DISPLAY_RECORD: "\n...push ENTER to continue... ") ); *userbuf = '\0'; - fgets (userbuf, sizeof (userbuf), stdin); - if (strlen(userbuf) && + if(NULL == fgets (userbuf, sizeof (userbuf), stdin)) { + fprintf(stderr, "Failed to read from stdin 2\n"); + exit(EXIT_FAILURE); + } + + if (strlen(userbuf) && userbuf[strlen(userbuf)-1] == '\n') userbuf[strlen(userbuf)-1] = '\0'; @@ -677,7 +685,10 @@ static void deleter (char *infname) "If you are sure you are ready to start deleting, enter 'y' now... ") , infname, OE_prodname); - fgets (buf, sizeof(buf)-1, stdin); + if(NULL == fgets (buf, sizeof(buf)-1, stdin)) { + fprintf(stderr, "no input\n"); + return; + } if (tolower (*buf) != 'y') return; } -- 2.25.1