about summary refs log tree commit diff
path: root/converter/other/pamtopng.c
diff options
context:
space:
mode:
Diffstat (limited to 'converter/other/pamtopng.c')
-rw-r--r--converter/other/pamtopng.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/converter/other/pamtopng.c b/converter/other/pamtopng.c
index bb24562a..fd0d89fa 100644
--- a/converter/other/pamtopng.c
+++ b/converter/other/pamtopng.c
@@ -579,6 +579,9 @@ writeRaster(const struct pam * const pamP,
             struct pngx *      const pngxP,
             int                const bitDepth) {
 
+    unsigned int const rowSz =
+        pamP->width * pamP->depth * (MAX(1, bitDepth/8));
+
     tuple * tupleRow;
     png_byte * pngRow;
     unsigned int row;
@@ -587,8 +590,7 @@ writeRaster(const struct pam * const pamP,
 
     tupleRow = pnm_allocpamrow(pamP);
 
-    MALLOCARRAY(pngRow, pamP->width * 8);
-        /* sufficient to store a 16-bit RGB+A row */
+    MALLOCARRAY(pngRow, rowSz);
 
     if (pngRow == NULL)
         pm_error("Unable to allocate space for PNG pixel row for "