summaryrefslogtreecommitdiff
path: root/community/grim/bced8c88165bd15cf97d3b55a9241b0a6ee1fe3c.patch
blob: 48afa84f906e4d82ad4e652b0bb3c852729df352 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
From aa679f0501a30fb5a452d35f7ef9d7ed2c3fa2f9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= <jpokorny@fedoraproject.org>
Date: Sat, 3 Nov 2018 15:16:08 +0100
Subject: [PATCH] Fix i686 build -Werror=incompatible-pointer-types complaint
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This was caused with jpeg_mem_dest expecting pointer to unsigned long
and being fed with pointer to size_t, which may amount to different
data-width types.  There's also a simple overflow check for such
cases now.

Signed-off-by: Jan Pokorný <jpokorny@fedoraproject.org>
---
 cairo_jpg.c         | 17 +++++++++--------
 include/cairo_jpg.h |  2 +-
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/cairo_jpg.c b/cairo_jpg.c
index e905e4e..3a37a37 100644
--- a/cairo_jpg.c
+++ b/cairo_jpg.c
@@ -7,7 +7,9 @@
 #include <stdlib.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <assert.h>
 #include <fcntl.h>
+#include <limits.h>
 #include <unistd.h>
 #include <cairo.h>
 #include <jpeglib.h>
@@ -15,7 +17,7 @@
 #include "cairo_jpg.h"
 
 cairo_status_t cairo_surface_write_to_jpeg_mem(cairo_surface_t *sfc,
-		unsigned char **data, size_t *len, int quality) {
+		unsigned char **data, unsigned long *len, int quality) {
 	struct jpeg_compress_struct cinfo;
 	struct jpeg_error_mgr jerr;
 	JSAMPROW row_pointer[1];
@@ -91,18 +93,17 @@ cairo_status_t cairo_surface_write_to_jpeg_stream(cairo_surface_t *sfc,
 		cairo_write_func_t write_func, void *closure, int quality) {
 	cairo_status_t e;
 	unsigned char *data = NULL;
-	size_t len = 0;
+	unsigned long len = 0;
 
 	e = cairo_surface_write_to_jpeg_mem(sfc, &data, &len, quality);
-	if (e != CAIRO_STATUS_SUCCESS) {
-		return e;
+	if (e == CAIRO_STATUS_SUCCESS) {
+		assert(sizeof(unsigned long) <= sizeof(size_t)
+			|| !(len >> (sizeof(size_t) * CHAR_BIT)));
+		e = write_func(closure, data, len);
+		free(data);
 	}
 
-	e = write_func(closure, data, len);
-
-	free(data);
 	return e;
-
 }
 
 cairo_status_t cairo_surface_write_to_jpeg(cairo_surface_t *sfc,
diff --git a/include/cairo_jpg.h b/include/cairo_jpg.h
index a2d0328..7e09e55 100644
--- a/include/cairo_jpg.h
+++ b/include/cairo_jpg.h
@@ -3,7 +3,7 @@
 
 #include <cairo.h>
 
-cairo_status_t cairo_surface_write_to_jpeg_mem(cairo_surface_t *sfc, unsigned char **data, size_t *len, int quality);
+cairo_status_t cairo_surface_write_to_jpeg_mem(cairo_surface_t *sfc, unsigned char **data, unsigned long *len, int quality);
 cairo_status_t cairo_surface_write_to_jpeg_stream(cairo_surface_t *sfc, cairo_write_func_t write_func, void *closure, int quality);
 cairo_status_t cairo_surface_write_to_jpeg(cairo_surface_t *sfc, const char *filename, int quality);