about summary refs log tree commit diff
path: root/lib/libpam.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libpam.c')
-rw-r--r--lib/libpam.c20
1 files changed, 5 insertions, 15 deletions
diff --git a/lib/libpam.c b/lib/libpam.c
index 07241e9e..9875331d 100644
--- a/lib/libpam.c
+++ b/lib/libpam.c
@@ -132,19 +132,7 @@ validateComputableMaxval(const struct pam * const pamP) {
 /*----------------------------------------------------------------------------
   This is similar to validateComputableSize, but for the maxval.
 -----------------------------------------------------------------------------*/
-    /* Code sometimes allocates an array indexed by sample values and
-       represents the size of that array as an INT.  (UNSIGNED INT would be
-       more proper, but there's no need to be that permissive).
-
-       Code also sometimes iterates through sample values and quits when the
-       value is greater than the maxval.
-    */
-
-    if (pamP->maxval == 0)
-        pm_error("Maxval is zero.  Must be at least one.");
-
-    if (pamP->maxval > INT_MAX-1)
-        pm_error("Maxval (%lu) is too large to be processed", pamP->maxval);
+    pgm_validateComputableMaxval(pamP->maxval);
 }
 
 
@@ -154,7 +142,7 @@ pnm_allocpamtuple(const struct pam * const pamP) {
 
     tuple retval;
 
-    retval = malloc(allocationDepth(pamP) * sizeof(retval[0]));
+    MALLOCARRAY(retval, allocationDepth(pamP));
 
     if (retval == NULL)
         pm_error("Out of memory allocating %u-plane tuple",
@@ -334,7 +322,7 @@ pnm_allocrowimage(const struct pam * const pamP) {
 
     unsigned char * retval;
 
-    retval = malloc(size);
+    MALLOCARRAY(retval, size);
 
     if (retval == NULL)
         pm_error("Unable to allocate %u bytes for a row image buffer",
@@ -1121,6 +1109,8 @@ pnm_writepaminit(struct pam * const pamP) {
 
     switch (PAM_FORMAT_TYPE(pamP->format)) {
     case PAM_TYPE:
+        validateComputableSize(pamP);
+        validateComputableMaxval(pamP);
         /* See explanation below of why we ignore 'pm_plain_output' here. */
         fprintf(pamP->file, "P7\n");
         writeComments(pamP);