Minor fix to compiling with gcc and gcc related warning
[wordblah.git] / wordblah.h
index 48e1f28..13874dc 100644 (file)
@@ -133,7 +133,7 @@ bool verify_solution_password (Puzzle *p, const char* password)
        unsigned int len;
        digest_message ((const unsigned char *)password, strlen(password),
                                                &hashed_sol_password, &len);
-       char hashed_hex_pwd[256] = { (char) NULL };
+       char hashed_hex_pwd[256] = { '\0' };
        encode_binary (hashed_hex_pwd, hashed_sol_password, len);
        
        if (strcmp (p->hashed_solution_password, hashed_hex_pwd) == 0)
@@ -155,7 +155,7 @@ bool verify_master_password (Puzzle *p, const char* password)
        unsigned int len;
        digest_message ((const unsigned char *)password, strlen(password),
                                                &hashed_mas_password, &len);
-       char hashed_hex_pwd[256] = { (char) NULL };
+       char hashed_hex_pwd[256] = { '\0' };
        encode_binary (hashed_hex_pwd, hashed_mas_password, len);
        
        if (strcmp (p->hashed_master_password, hashed_hex_pwd) == 0)
@@ -600,19 +600,23 @@ void save_puzzle (Puzzle *puzzle, const char* file)
 /* read the puzzle from a file */
 Puzzle load_puzzle (const char* file) 
 {
+       Puzzle p;
        /* First open the GZip file */
        gzFile insourcefile = gzopen (file, "rb");
        if (insourcefile == NULL)
        {
                fprintf (stderr, "%s %s\n", ERROR_READING_FILE, COMPRESSED);
-               exit (1);
+               /* return an invalid puzzle */
+               init_puzzle (&p, 0);
+               return p;
        }
        /* Open a temporary file to uncompress the contents */
        FILE *infile = tmpfile ();
        if (infile == NULL)
        {
                fprintf (stderr, "%s\n", ERROR_READING_FILE);
-               exit (1);       
+               init_puzzle (&p, 0);
+               return p;
        }
        /* Put the uncompressed content to the temp file */
        char buf[128];
@@ -626,7 +630,9 @@ Puzzle load_puzzle (const char* file)
                        fprintf (stderr, "%s\n", ERROR_READING_FILE);
                        fclose (infile);
                        gzclose (insourcefile);
-                       exit (1);
+                       /* return an invalid puzzle */
+                       init_puzzle (&p, 0);
+                       return p;
                }
                num = gzread (insourcefile, buf, 128);
        }
@@ -637,7 +643,6 @@ Puzzle load_puzzle (const char* file)
        fseek (infile, 0, 0);
 
        /* Read the temporary file contents to the structure Puzzle */
-       Puzzle p;
        char line[MAX_CLUE_LENGTH+10];
        fgets (line, MAX_CLUE_LENGTH + 10, infile);
        p.grid_size = atoi (line);
@@ -645,6 +650,7 @@ Puzzle load_puzzle (const char* file)
           puzzle object */
        if (p.grid_size == 0)
        {
+               fprintf (stderr, "%s\n", INVALID_PUZZLE);
                init_puzzle (&p, 0);
                return p;
        }