Fix wrong height of pictures on x86_64
On 64-bit Fedora latex2rtf produced RTFs with insanely large pictures.
The dimensions of a PNG are stored in the header as 4-byte values.
GetPngSize() reads them as consecutive unsigned longs.
The problem is that sizeof(unsigned long) != 4 bytes. It's 8 bytes on
x86_64 Linux.
Use standard ISO C uint32_t instead.
With this patch the figures have their normal size.
Index: graphics.c
===================================================================
--- graphics.c (revision 894)
+++ graphics.c (working copy)
@@ -29,6 +29,7 @@
#include <ctype.h>
#include <limits.h>
#include <math.h>
+#include <stdint.h>
#ifdef UNIX
#include <unistd.h>
#endif
@@ -755,7 +756,7 @@
static unsigned char * getPngChunk(FILE *fp, char *s)
{
- unsigned long size, crc;
+ uint32_t size, crc;
char head[5];
unsigned char *data;
@@ -777,7 +778,7 @@
if (strcmp(head,"IEND") == 0) return NULL;
- diagnostics(6,"found chunk '%s' size %ld bytes",head,size);
+ diagnostics(6,"found chunk '%s' size %ld bytes",head,(unsigned long)size);
data = malloc(size);
if (data == NULL) return NULL;
@@ -798,7 +799,7 @@
static void GetPngSize(char *s, unsigned long *w, unsigned long *h, unsigned long *xres, unsigned long *yres, int *bad_res)
{
FILE *fp;
- unsigned long *p;
+ uint32_t *p;
unsigned char buffer[16];
char reftag[9] = "\211PNG\r\n\032\n";
unsigned char *data = NULL;
@@ -833,7 +834,7 @@
return;
}
- p = (unsigned long *) data;
+ p = (uint32_t *) data;
*w = (g_little_endian) ? LETONL(*p) : *p;
p++;
*h = (g_little_endian) ? LETONL(*p) : *p;
@@ -846,7 +847,7 @@
return;
}
- p = (unsigned long *) data;
+ p = (uint32_t *) data;
*xres = (g_little_endian) ? LETONL(*p) : *p;
p++;
*yres = (g_little_endian) ? LETONL(*p) : *p;