Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Commit

Permalink
Fix i686 build -Werror=incompatible-pointer-types complaint
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jnpkrn committed Nov 6, 2018
1 parent 61df6f0 commit aa679f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions cairo_jpg.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
#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>

#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];
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion include/cairo_jpg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit aa679f0

Please sign in to comment.