Skip to content

Commit f210236

Browse files
committed
pam: fix writing 3 channels
1 parent 022942a commit f210236

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/utils/pam.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
#include <ctype.h>
3939
#include <errno.h>
40+
#include <stddef.h>
4041
#include <stdio.h>
4142
#include <stdlib.h>
4243
#include <string.h>
@@ -270,15 +271,17 @@ bool pam_write(const char *filename, unsigned int width, unsigned int pitch,
270271
"ENDHDR\n",
271272
width, height, ch_count, maxval, tuple_type);
272273
}
273-
size_t len = (size_t) width * height * ch_count * (maxval <= 255 ? 1 : 2);
274+
const size_t linesize = (size_t) height * ch_count * (maxval <= 255 ? 1 : 2);
275+
const size_t len = width * linesize;
274276
errno = 0;
275277
size_t bytes_written = 0;
276278
if (width == pitch) {
277279
bytes_written = fwrite((const char *) data, 1, len, file);
278280
} else {
279281
for (unsigned y = 0; y < height; ++y) {
280-
bytes_written += fwrite(
281-
(const char *)data + (y * pitch), 1, width, file);
282+
bytes_written += fwrite((const char *)data +
283+
((size_t)y * pitch),
284+
1, linesize, file);
282285
}
283286
}
284287
if (bytes_written != len) {

0 commit comments

Comments
 (0)