Commits

Shlomi Fish committed c7d7268

Fix some warnings.

  • Participants
  • Parent commits 4b32c78

Comments (0)

Files changed (3)

File src/ChangeLog

   information about every single change.
   ___________________________________________________________________________
 
+  *) Fix some compiler warnings that gcc emitted by default.
+       [Shlomi Fish <shlomif@cpan.org>]
+
   Changes between 2.0.12 to 2.2.0:
 
   *) Convert the build system to CMake.

File src/wml_backend/p3_eperl/eperl_http.c

     sprintf(cmd+strlen(cmd), "\r\n");
 
     /* send the request */
-    write(s, cmd, strlen(cmd));
+    {
+        ssize_t expected_num_written = strlen(cmd);
+        ssize_t got_num_written;
+        
+        got_num_written = write(s, cmd, expected_num_written);
+        if (got_num_written != expected_num_written)
+        {
+            return NULL;
+        }
+    }
     free(cmd);
 
     /* convert the file descriptor to a FILE pointer */

File src/wml_backend/p3_eperl/eperl_main.c

 **  eperl_main.c -- ePerl main procedure 
 */
 
+#include <errno.h>
+
 #include "eperl_config.h"
 #include "eperl_global.h"
 #include "eperl_security.h"
     if (mode == MODE_NPHCGI)
         HTTP_PrintResponseHeaders("");
     printf("Content-Type: image/gif\r\n\r\n");
-    fwrite(ePerl_POWERED_data, ePerl_POWERED_size, 1, stdout);
+    if (fwrite(ePerl_POWERED_data, ePerl_POWERED_size, 1, stdout) != 1) {
+        exit(-1);
+    }
 }
 
 void give_usage(char *name)
                 }
 
                 /* restore original cwd */
-                chdir(cwd2);
+                if (chdir(cwd2) != 0)
+                {
+                    PrintError(mode, source, NULL, NULL, "chdir failed with errno: %li\n", (long)errno);
+                }
         
                 free(cwd2);
             }
     /* optionally run the ePerl preprocessor */
     if (fPP) {
         /* switch to directory where script stays */
-        getcwd(cwd, MAXPATHLEN);
+        if (! getcwd(cwd, MAXPATHLEN) ) {
+            PrintError(mode, source, NULL, NULL, "getcwd failed with errno %ld", (long)errno);
+            CU(mode == MODE_FILTER ? EX_IOERR : EX_OK);
+        }
         strncpy(sourcedir, source, sizeof(sourcedir));
         sourcedir[sizeof(sourcedir)-1] = NUL;
         for (cp = sourcedir+strlen(sourcedir); cp > sourcedir && *cp != '/'; cp--)
             ;
         *cp = NUL;
-        chdir(sourcedir);
+        if (chdir(sourcedir) != 0) {
+            PrintError(mode, source, NULL, NULL, "chdir failed with errno %ld", (long)errno);
+            CU(mode == MODE_FILTER ? EX_IOERR : EX_OK);
+        }
         /* run the preprocessor */
         if ((cpBuf3 = ePerl_PP(cpScript, RememberedINC)) == NULL) {
             PrintError(mode, source, NULL, NULL, "Preprocessing failed for `%s': %s", source, ePerl_PP_GetError());
         }
         cpScript = cpBuf3;
         /* switch to previous dir */
-        chdir(cwd);
+        if (chdir(cwd) != 0) {
+            PrintError(mode, source, NULL, NULL, "chdir failed with errno %ld", (long)errno);
+            CU(mode == MODE_FILTER ? EX_IOERR : EX_OK);
+        }
     }
 
     /* convert bristled source to valid Perl code */
         PrintError(mode, source, NULL, NULL, "Cannot open Perl script file `%s' for writing", perlscript);
         CU(mode == MODE_FILTER ? EX_IOERR : EX_OK);
     }
-    fwrite(cpScript, strlen(cpScript), 1, fp);
+    if (fwrite(cpScript, strlen(cpScript), 1, fp) != 1) {
+        PrintError(mode, source, NULL, NULL, "Cannot write to Perl script file `%s'", perlscript);
+        CU(mode == MODE_FILTER ? EX_IOERR : EX_OK);
+    }
     fclose(fp); fp = NULL;
 
     /* in Debug mode output the script to the console */
             CU(mode == MODE_FILTER ? EX_IOERR : EX_OK);
         }
         fprintf(fp, "----internally created Perl script-----------------------------------\n");
-        fwrite(cpScript, strlen(cpScript)-1, 1, fp);
+        if (fwrite(cpScript, strlen(cpScript)-1, 1, fp) != 1)
+        {
+            PrintError(mode, source, NULL, NULL, "%s\n", "Cannot write");
+            CU(mode == MODE_FILTER ? EX_IOERR : EX_OK);
+        }
         if (cpScript[strlen(cpScript)-1] == '\n') 
             fprintf(fp, "%c", cpScript[strlen(cpScript)-1]);
         else 
         if (outputfile != NULL && stringNE(outputfile, "-")) {
             /* if we remembered current working dir, restore it now */
             if (mode == MODE_FILTER && cwd[0] != NUL)
-                chdir(cwd);
+            {
+                if (chdir(cwd) != 0)
+                {
+                    PrintError(mode, source, NULL, NULL, "%s\n", "Cannot chdir");
+                    CU(mode == MODE_FILTER ? EX_FAIL : EX_OK);
+                }
+            }
             /* open outputfile and write out the data */
             if ((fp = fopen(outputfile, "w")) == NULL) {
                 PrintError(mode, source, NULL, NULL, "Cannot open output file `%s' for writing", outputfile);
                 CU(mode == MODE_FILTER ? EX_IOERR : EX_OK);
             }
-            fwrite(cpOut, nOut, 1, fp);
+            if (fwrite(cpOut, nOut, 1, fp) != 1) {
+                PrintError(mode, source, NULL, NULL, "Cannot write to Perl script file `%s'", perlscript);
+                CU(mode == MODE_FILTER ? EX_IOERR : EX_OK);
+            }
             fclose(fp); fp = NULL;
         }
         else {
             /* data just goes to stdout */
-            fwrite(cpOut, nOut, 1, stdout);
+            if (fwrite(cpOut, nOut, 1, stdout) != 1) {
+                PrintError(mode, source, NULL, NULL, "%s\n", "Cannot write to stdout");
+                CU(mode == MODE_FILTER ? EX_IOERR : EX_OK);
+            }
             /* make sure that the data is out before we exit */
             fflush(stdout);
         }