about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-04-10 16:07:24 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-04-10 16:07:24 +0000
commit7d714381d1af9f51ae0094df79e1fe8d28c46b84 (patch)
treecf576cb526aa84b025b3bb599062e1849a55a3b0 /lib
parent73225706f044df73549d0982e782b41ff94e117f (diff)
downloadnetpbm-mirror-7d714381d1af9f51ae0094df79e1fe8d28c46b84.tar.gz
netpbm-mirror-7d714381d1af9f51ae0094df79e1fe8d28c46b84.tar.xz
netpbm-mirror-7d714381d1af9f51ae0094df79e1fe8d28c46b84.zip
Fix compiler warnings
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1185 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib')
-rw-r--r--lib/libpam.c10
-rw-r--r--lib/libpamn.c2
-rw-r--r--lib/libpgm2.c10
-rw-r--r--lib/libppm1.c81
-rw-r--r--lib/libppm2.c9
-rw-r--r--lib/util/floatcode.h2
6 files changed, 66 insertions, 48 deletions
diff --git a/lib/libpam.c b/lib/libpam.c
index 9384e178..e00f00db 100644
--- a/lib/libpam.c
+++ b/lib/libpam.c
@@ -261,9 +261,9 @@ pnm_allocpamrow(const struct pam * const pamP) {
     tuple * const tuplerow = allocPamRow(pamP);
 
     if (tuplerow == NULL)
-        pm_error("Out of memory allocating space for a tuple row of\n"
-                 "%d tuples by %d samples per tuple by %d bytes per sample.",
-                 pamP->width, allocationDepth(pamP), sizeof(sample));
+        pm_error("Out of memory allocating space for a tuple row of "
+                 "%d tuples by %d samples per tuple by %u bytes per sample.",
+                 pamP->width, allocationDepth(pamP), (unsigned)sizeof(sample));
 
     return tuplerow;
 }
@@ -400,7 +400,7 @@ pnm_setminallocationdepth(struct pam * const pamP,
         pm_error("Can't set minimum allocation depth in pam structure, "
                  "because the structure is only %u bytes long, and to "
                  "have an allocation_depth field, it must bea at least %u",
-                 pamP->len, PAM_STRUCT_SIZE(allocation_depth));
+                 pamP->len, (unsigned)PAM_STRUCT_SIZE(allocation_depth));
 
     pamP->allocation_depth = MAX(allocationDepth, pamP->depth);
         
@@ -575,7 +575,7 @@ appendComment(char **      const commentsP,
 
     if (*commentsP == NULL)
         pm_error("Couldn't get storage for %u characters of comments from "
-                 "the PAM header", commentLen);
+                 "the PAM header", (unsigned)commentLen);
 
     strcat(*commentsP, commentLine);
 }
diff --git a/lib/libpamn.c b/lib/libpamn.c
index fe004e91..76a8bb6d 100644
--- a/lib/libpamn.c
+++ b/lib/libpamn.c
@@ -42,7 +42,7 @@ allocpamrown(const struct pam * const pamP,
     if (tuplerown == NULL)
         asprintfN(&error, "Out of memory allocating space for a tuple row of"
                   "%u tuples by %u samples per tuple by %u bytes per sample.",
-                  pamP->width, pamP->depth, sizeof(samplen));
+                  pamP->width, pamP->depth, (unsigned)sizeof(samplen));
     else {
         /* Now we initialize the pointers to the individual tuples to make this
            a regulation C two dimensional array.
diff --git a/lib/libpgm2.c b/lib/libpgm2.c
index 650d2cb5..00929c5a 100644
--- a/lib/libpgm2.c
+++ b/lib/libpgm2.c
@@ -125,10 +125,12 @@ writepgmrowraw(FILE *       const fileP,
     if (rc < 0)
         pm_error("Error writing row.  fwrite() errno=%d (%s)",
                  errno, strerror(errno));
-    else if (rc != bytesPerRow)
-        pm_error("Error writing row.  Short write of %u bytes "
-                 "instead of %u", rc, bytesPerRow);
-
+    else {
+        size_t const bytesWritten = rc;
+        if (bytesWritten != bytesPerRow)
+            pm_error("Error writing row.  Short write of %u bytes "
+                     "instead of %u", (unsigned)bytesWritten, bytesPerRow);
+    }
     free(rowBuffer);
 }
 
diff --git a/lib/libppm1.c b/lib/libppm1.c
index ea929908..7b92d3ee 100644
--- a/lib/libppm1.c
+++ b/lib/libppm1.c
@@ -184,6 +184,46 @@ readPpmRow(FILE *       const fileP,
 
 
 static void
+interpRasterRowRaw(const unsigned char * const rowBuffer,
+                   pixel *               const pixelrow,
+                   unsigned int          const cols,
+                   unsigned int          const bytesPerSample) {
+
+    unsigned int bufferCursor;
+
+    bufferCursor = 0;  /* start at beginning of rowBuffer[] */
+        
+    if (bytesPerSample == 1) {
+        unsigned int col;
+        for (col = 0; col < cols; ++col) {
+            pixval const r = rowBuffer[bufferCursor++];
+            pixval const g = rowBuffer[bufferCursor++];
+            pixval const b = rowBuffer[bufferCursor++];
+            PPM_ASSIGN(pixelrow[col], r, g, b);
+        }
+    } else  {
+        /* two byte samples */
+        unsigned int col;
+        for (col = 0; col < cols; ++col) {
+            pixval r, g, b;
+                    
+            r = rowBuffer[bufferCursor++] << 8;
+            r |= rowBuffer[bufferCursor++];
+                    
+            g = rowBuffer[bufferCursor++] << 8;
+            g |= rowBuffer[bufferCursor++];
+                    
+            b = rowBuffer[bufferCursor++] << 8;
+            b |= rowBuffer[bufferCursor++];
+                    
+            PPM_ASSIGN(pixelrow[col], r, g, b);
+        }
+    }
+}
+
+
+
+static void
 readRppmRow(FILE *       const fileP, 
             pixel *      const pixelrow, 
             unsigned int const cols, 
@@ -211,41 +251,14 @@ readRppmRow(FILE *       const fileP,
         else if (ferror(fileP))
             asprintfN(&error, "Error reading row.  fread() errno=%d (%s)",
                       errno, strerror(errno));
-        else if (rc != bytesPerRow)
-            asprintfN(&error, "Error reading row.  Short read of %u bytes "
-                      "instead of %u", rc, bytesPerRow);
         else {
-            unsigned int bufferCursor;
-
-            error = NULL;
-
-            bufferCursor = 0;  /* start at beginning of rowBuffer[] */
-        
-            if (bytesPerSample == 1) {
-                unsigned int col;
-                for (col = 0; col < cols; ++col) {
-                    pixval const r = rowBuffer[bufferCursor++];
-                    pixval const g = rowBuffer[bufferCursor++];
-                    pixval const b = rowBuffer[bufferCursor++];
-                    PPM_ASSIGN(pixelrow[col], r, g, b);
-                }
-            } else  {
-                /* two byte samples */
-                unsigned int col;
-                for (col = 0; col < cols; ++col) {
-                    pixval r, g, b;
-                    
-                    r = rowBuffer[bufferCursor++] << 8;
-                    r |= rowBuffer[bufferCursor++];
-                    
-                    g = rowBuffer[bufferCursor++] << 8;
-                    g |= rowBuffer[bufferCursor++];
-                    
-                    b = rowBuffer[bufferCursor++] << 8;
-                    b |= rowBuffer[bufferCursor++];
-                    
-                    PPM_ASSIGN(pixelrow[col], r, g, b);
-                }
+            size_t const bytesRead = rc;
+            if (bytesRead != bytesPerRow)
+                asprintfN(&error, "Error reading row.  Short read of %u bytes "
+                          "instead of %u", (unsigned)bytesRead, bytesPerRow);
+            else {
+                interpRasterRowRaw(rowBuffer, pixelrow, cols, bytesPerSample);
+                error = NULL;
             }
         }
         free(rowBuffer);
diff --git a/lib/libppm2.c b/lib/libppm2.c
index 3bf74bd4..9d877bd3 100644
--- a/lib/libppm2.c
+++ b/lib/libppm2.c
@@ -133,10 +133,13 @@ ppm_writeppmrowraw(FILE *        const fileP,
     if (rc < 0)
         pm_error("Error writing row.  fwrite() errno=%d (%s)",
                  errno, strerror(errno));
-    else if (rc != bytesPerRow)
-        pm_error("Error writing row.  Short write of %u bytes "
-                 "instead of %u", rc, bytesPerRow);
+    else {
+        size_t const bytesWritten = rc;
 
+        if (bytesWritten != bytesPerRow)
+            pm_error("Error writing row.  Short write of %u bytes "
+                     "instead of %u", (unsigned)bytesWritten, bytesPerRow);
+    }
     free(rowBuffer);
 }
 
diff --git a/lib/util/floatcode.h b/lib/util/floatcode.h
index 99aec256..8559ff79 100644
--- a/lib/util/floatcode.h
+++ b/lib/util/floatcode.h
@@ -124,7 +124,7 @@ pm_doubleFromBigendDouble(pm_bigendDouble const arg) {
     }; break;
     case LITTLE_ENDIAN: {
         union {
-            unsigned char bytes[4];
+            unsigned char bytes[8];
             double native;
         } converter;