From 9b92bac1ec135862132b1c49b977b53891b73d88 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simon=20B=C3=BCnzli?= <zeniko@gmail.com>
Date: Thu, 2 Jan 2014 21:27:15 +0100
Subject: fix various MSVC warnings

Some warnings we'd like to enable for MuPDF and still be able to
compile it with warnings as errors using MSVC (2008 to 2013):

* C4115: 'timeval' : named type definition in parentheses
* C4204: nonstandard extension used : non-constant aggregate initializer
* C4295: 'hex' : array is too small to include a terminating null character
* C4389: '==' : signed/unsigned mismatch
* C4702: unreachable code
* C4706: assignment within conditional expression

Also, globally disable C4701 which is frequently caused by MSVC not
being able to correctly figure out fz_try/fz_catch code flow.

And don't define isnan for VS2013 and later where that's no longer needed.
---
 source/cbz/mucbz.c          |  1 -
 source/fitz/draw-device.c   |  4 +++-
 source/fitz/string.c        |  2 +-
 source/fitz/svg-device.c    | 15 ++++++++++++---
 source/fitz/time.c          |  3 ---
 source/pdf/pdf-cmap-load.c  |  2 +-
 source/pdf/pdf-colorspace.c |  4 +---
 source/pdf/pdf-font.c       | 11 ++++-------
 source/pdf/pdf-form.c       |  2 +-
 source/pdf/pdf-function.c   |  2 +-
 source/pdf/pdf-image.c      |  2 +-
 source/pdf/pdf-outline.c    |  4 ++--
 source/pdf/pdf-parse.c      |  1 -
 source/pdf/pdf-pattern.c    |  2 +-
 source/pdf/pdf-shade.c      |  2 +-
 source/pdf/pdf-write.c      |  2 +-
 source/pdf/pdf-xobject.c    |  2 +-
 source/tools/mudraw.c       |  1 -
 source/xps/xps-common.c     |  2 +-
 source/xps/xps-doc.c        |  1 -
 source/xps/xps-zip.c        |  2 --
 21 files changed, 32 insertions(+), 35 deletions(-)

(limited to 'source')

diff --git a/source/cbz/mucbz.c b/source/cbz/mucbz.c
index 4ebb623a..d9be58f3 100644
--- a/source/cbz/mucbz.c
+++ b/source/cbz/mucbz.c
@@ -160,7 +160,6 @@ cbz_read_zip_entry(cbz_document *doc, int offset, int *sizep)
 	}
 
 	fz_throw(ctx, FZ_ERROR_GENERIC, "unknown zip method: %d", method);
-	return NULL; /* not reached */
 }
 
 static void
diff --git a/source/fitz/draw-device.c b/source/fitz/draw-device.c
index 355022f3..cf3daa51 100644
--- a/source/fitz/draw-device.c
+++ b/source/fitz/draw-device.c
@@ -564,7 +564,9 @@ fz_draw_fill_text(fz_device *devp, fz_text *text, const fz_matrix *ctm,
 			}
 			else
 			{
-				fz_matrix mat = {pixmap->w, 0.0, 0.0, pixmap->h, x + pixmap->x, y + pixmap->y};
+				fz_matrix mat;
+				mat.a = pixmap->w; mat.b = mat.c = 0; mat.d = pixmap->h;
+				mat.e = x + pixmap->x; mat.f = y + pixmap->y;
 				fz_paint_image(state->dest, &state->scissor, state->shape, pixmap, &mat, alpha * 255, !(devp->hints & FZ_DONT_INTERPOLATE_IMAGES));
 			}
 			fz_drop_glyph(dev->ctx, glyph);
diff --git a/source/fitz/string.c b/source/fitz/string.c
index b29cdbdc..1442b205 100644
--- a/source/fitz/string.c
+++ b/source/fitz/string.c
@@ -5,7 +5,7 @@ fz_strsep(char **stringp, const char *delim)
 {
 	char *ret = *stringp;
 	if (!ret) return NULL;
-	if ((*stringp = strpbrk(*stringp, delim)))
+	if ((*stringp = strpbrk(*stringp, delim)) != NULL)
 		*((*stringp)++) = '\0';
 	return ret;
 }
diff --git a/source/fitz/svg-device.c b/source/fitz/svg-device.c
index dc248f88..aa5ff74c 100644
--- a/source/fitz/svg-device.c
+++ b/source/fitz/svg-device.c
@@ -682,7 +682,10 @@ svg_dev_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float
 	fz_context *ctx = dev->ctx;
 	fz_output *out = sdev->out;
 	fz_matrix local_ctm = *ctm;
-	fz_matrix scale = { 1.0f/image->w, 0, 0, 1.0f/image->h, 0, 0};
+	fz_matrix scale = { 0 };
+
+	scale.a = 1.0f / image->w;
+	scale.d = 1.0f / image->h;
 
 	fz_concat(&local_ctm, &scale, ctm);
 	if (alpha != 1.0f)
@@ -767,9 +770,12 @@ fz_colorspace *colorspace, float *color, float alpha)
 	fz_context *ctx = dev->ctx;
 	fz_output *out;
 	fz_matrix local_ctm = *ctm;
-	fz_matrix scale = { 1.0f/image->w, 0, 0, 1.0f/image->h, 0, 0};
+	fz_matrix scale = { 0 };
 	int mask = sdev->id++;
 
+	scale.a = 1.0f / image->w;
+	scale.d = 1.0f / image->h;
+
 	fz_concat(&local_ctm, &scale, ctm);
 	out = start_def(sdev);
 	fz_printf(out, "<mask id=\"ma%d\"><image", mask);
@@ -808,9 +814,12 @@ svg_dev_clip_image_mask(fz_device *dev, fz_image *image, const fz_rect *rect, co
 	fz_context *ctx = dev->ctx;
 	fz_output *out;
 	fz_matrix local_ctm = *ctm;
-	fz_matrix scale = { 1.0f/image->w, 0, 0, 1.0f/image->h, 0, 0};
+	fz_matrix scale = { 0 };
 	int mask = sdev->id++;
 
+	scale.a = 1.0f / image->w;
+	scale.d = 1.0f / image->h;
+
 	fz_concat(&local_ctm, &scale, ctm);
 	out = start_def(sdev);
 	fz_printf(out, "<mask id=\"ma%d\"><image", mask);
diff --git a/source/fitz/time.c b/source/fitz/time.c
index 0e3d21b5..6b1d6255 100644
--- a/source/fitz/time.c
+++ b/source/fitz/time.c
@@ -9,9 +9,6 @@
 
 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
 
-struct timeval;
-struct timezone;
-
 int gettimeofday(struct timeval *tv, struct timezone *tz)
 {
 	FILETIME ft;
diff --git a/source/pdf/pdf-cmap-load.c b/source/pdf/pdf-cmap-load.c
index 4ac7208b..08c4a80a 100644
--- a/source/pdf/pdf-cmap-load.c
+++ b/source/pdf/pdf-cmap-load.c
@@ -33,7 +33,7 @@ pdf_load_embedded_cmap(pdf_document *doc, pdf_obj *stmobj)
 	if (pdf_obj_marked(stmobj))
 		fz_throw(ctx, FZ_ERROR_GENERIC, "Recursion in embedded cmap");
 
-	if ((cmap = pdf_find_item(ctx, pdf_free_cmap_imp, stmobj)))
+	if ((cmap = pdf_find_item(ctx, pdf_free_cmap_imp, stmobj)) != NULL)
 	{
 		return cmap;
 	}
diff --git a/source/pdf/pdf-colorspace.c b/source/pdf/pdf-colorspace.c
index 611a187b..5fd569c3 100644
--- a/source/pdf/pdf-colorspace.c
+++ b/source/pdf/pdf-colorspace.c
@@ -42,7 +42,6 @@ load_icc_based(pdf_document *doc, pdf_obj *dict)
 	}
 
 	fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: ICCBased must have 1, 3 or 4 components");
-	return NULL; /* Stupid MSVC */
 }
 
 /* Lab */
@@ -350,7 +349,6 @@ pdf_load_colorspace_imp(pdf_document *doc, pdf_obj *obj)
 	}
 
 	fz_throw(doc->ctx, FZ_ERROR_GENERIC, "syntaxerror: could not parse color space (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj));
-	return NULL; /* Stupid MSVC */
 }
 
 fz_colorspace *
@@ -359,7 +357,7 @@ pdf_load_colorspace(pdf_document *doc, pdf_obj *obj)
 	fz_context *ctx = doc->ctx;
 	fz_colorspace *cs;
 
-	if ((cs = pdf_find_item(ctx, fz_free_colorspace_imp, obj)))
+	if ((cs = pdf_find_item(ctx, fz_free_colorspace_imp, obj)) != NULL)
 	{
 		return cs;
 	}
diff --git a/source/pdf/pdf-font.c b/source/pdf/pdf-font.c
index 0d387151..efb1eee6 100644
--- a/source/pdf/pdf-font.c
+++ b/source/pdf/pdf-font.c
@@ -821,7 +821,7 @@ pdf_load_hail_mary_font(pdf_document *doc)
 	pdf_font_desc *fontdesc;
 	pdf_font_desc *existing;
 
-	if ((fontdesc = fz_find_item(ctx, pdf_free_font_imp, &hail_mary_store_type, &hail_mary_store_type)))
+	if ((fontdesc = fz_find_item(ctx, pdf_free_font_imp, &hail_mary_store_type, &hail_mary_store_type)) != NULL)
 	{
 		return fontdesc;
 	}
@@ -1101,12 +1101,9 @@ pdf_load_type0_font(pdf_document *doc, pdf_obj *dict)
 
 	if (pdf_is_name(subtype) && !strcmp(pdf_to_name(subtype), "CIDFontType0"))
 		return load_cid_font(doc, dfont, encoding, to_unicode);
-	else if (pdf_is_name(subtype) && !strcmp(pdf_to_name(subtype), "CIDFontType2"))
+	if (pdf_is_name(subtype) && !strcmp(pdf_to_name(subtype), "CIDFontType2"))
 		return load_cid_font(doc, dfont, encoding, to_unicode);
-	else
-		fz_throw(doc->ctx, FZ_ERROR_GENERIC, "syntaxerror: unknown cid font type");
-
-	return NULL; /* Stupid MSVC */
+	fz_throw(doc->ctx, FZ_ERROR_GENERIC, "syntaxerror: unknown cid font type");
 }
 
 /*
@@ -1224,7 +1221,7 @@ pdf_load_font(pdf_document *doc, pdf_obj *rdb, pdf_obj *dict, int nested_depth)
 	pdf_font_desc *fontdesc;
 	int type3 = 0;
 
-	if ((fontdesc = pdf_find_item(ctx, pdf_free_font_imp, dict)))
+	if ((fontdesc = pdf_find_item(ctx, pdf_free_font_imp, dict)) != NULL)
 	{
 		return fontdesc;
 	}
diff --git a/source/pdf/pdf-form.c b/source/pdf/pdf-form.c
index 2b48abec..a6ea16c3 100644
--- a/source/pdf/pdf-form.c
+++ b/source/pdf/pdf-form.c
@@ -137,7 +137,7 @@ static pdf_obj *find_field(pdf_obj *dict, char *name, int len)
 
 		field = pdf_array_get(dict, i);
 		part = pdf_to_str_buf(pdf_dict_gets(field, "T"));
-		if (strlen(part) == len && !memcmp(part, name, len))
+		if (strlen(part) == (size_t)len && !memcmp(part, name, len))
 			return field;
 	}
 
diff --git a/source/pdf/pdf-function.c b/source/pdf/pdf-function.c
index 510e36cf..b18ccf17 100644
--- a/source/pdf/pdf-function.c
+++ b/source/pdf/pdf-function.c
@@ -1626,7 +1626,7 @@ pdf_load_function(pdf_document *doc, pdf_obj *dict, int in, int out)
 	if (pdf_obj_marked(dict))
 		fz_throw(ctx, FZ_ERROR_GENERIC, "Recursion in function definition");
 
-	if ((func = pdf_find_item(ctx, pdf_free_function_imp, dict)))
+	if ((func = pdf_find_item(ctx, pdf_free_function_imp, dict)) != NULL)
 	{
 		return (fz_function *)func;
 	}
diff --git a/source/pdf/pdf-image.c b/source/pdf/pdf-image.c
index b22f39fb..ef7f94ad 100644
--- a/source/pdf/pdf-image.c
+++ b/source/pdf/pdf-image.c
@@ -268,7 +268,7 @@ pdf_load_image(pdf_document *doc, pdf_obj *dict)
 	fz_context *ctx = doc->ctx;
 	fz_image *image;
 
-	if ((image = pdf_find_item(ctx, fz_free_image, dict)))
+	if ((image = pdf_find_item(ctx, fz_free_image, dict)) != NULL)
 	{
 		return (fz_image *)image;
 	}
diff --git a/source/pdf/pdf-outline.c b/source/pdf/pdf-outline.c
index 1e01b692..44273dda 100644
--- a/source/pdf/pdf-outline.c
+++ b/source/pdf/pdf-outline.c
@@ -31,9 +31,9 @@ pdf_load_outline_imp(pdf_document *doc, pdf_obj *dict)
 			if (obj)
 				node->title = pdf_to_utf8(doc, obj);
 
-			if ((obj = pdf_dict_gets(dict, "Dest")))
+			if ((obj = pdf_dict_gets(dict, "Dest")) != NULL)
 				node->dest = pdf_parse_link_dest(doc, FZ_LINK_GOTO, obj);
-			else if ((obj = pdf_dict_gets(dict, "A")))
+			else if ((obj = pdf_dict_gets(dict, "A")) != NULL)
 				node->dest = pdf_parse_action(doc, obj);
 
 			obj = pdf_dict_gets(dict, "First");
diff --git a/source/pdf/pdf-parse.c b/source/pdf/pdf-parse.c
index 66e0fbe7..a2fd09db 100644
--- a/source/pdf/pdf-parse.c
+++ b/source/pdf/pdf-parse.c
@@ -490,7 +490,6 @@ pdf_parse_stm_obj(pdf_document *doc, fz_stream *file, pdf_lexbuf *buf)
 	case PDF_TOK_INT: return pdf_new_int(doc, buf->i); break;
 	default: fz_throw(ctx, FZ_ERROR_GENERIC, "unknown token in object stream");
 	}
-	return NULL; /* Stupid MSVC */
 }
 
 pdf_obj *
diff --git a/source/pdf/pdf-pattern.c b/source/pdf/pdf-pattern.c
index 89e7f94f..f13a49c9 100644
--- a/source/pdf/pdf-pattern.c
+++ b/source/pdf/pdf-pattern.c
@@ -39,7 +39,7 @@ pdf_load_pattern(pdf_document *doc, pdf_obj *dict)
 	pdf_obj *obj;
 	fz_context *ctx = doc->ctx;
 
-	if ((pat = pdf_find_item(ctx, pdf_free_pattern_imp, dict)))
+	if ((pat = pdf_find_item(ctx, pdf_free_pattern_imp, dict)) != NULL)
 	{
 		return pat;
 	}
diff --git a/source/pdf/pdf-shade.c b/source/pdf/pdf-shade.c
index afeab247..40728dc7 100644
--- a/source/pdf/pdf-shade.c
+++ b/source/pdf/pdf-shade.c
@@ -456,7 +456,7 @@ pdf_load_shading(pdf_document *doc, pdf_obj *dict)
 	fz_context *ctx = doc->ctx;
 	fz_shade *shade;
 
-	if ((shade = pdf_find_item(ctx, fz_free_shade_imp, dict)))
+	if ((shade = pdf_find_item(ctx, fz_free_shade_imp, dict)) != NULL)
 	{
 		return shade;
 	}
diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c
index 42316da1..df432c21 100644
--- a/source/pdf/pdf-write.c
+++ b/source/pdf/pdf-write.c
@@ -1464,7 +1464,7 @@ static int isbinarystream(fz_buffer *buf)
 
 static fz_buffer *hexbuf(fz_context *ctx, unsigned char *p, int n)
 {
-	static const char hex[16] = "0123456789abcdef";
+	static const char hex[17] = "0123456789abcdef";
 	fz_buffer *buf;
 	int x = 0;
 
diff --git a/source/pdf/pdf-xobject.c b/source/pdf/pdf-xobject.c
index 648f8d29..c4259466 100644
--- a/source/pdf/pdf-xobject.c
+++ b/source/pdf/pdf-xobject.c
@@ -40,7 +40,7 @@ pdf_load_xobject(pdf_document *doc, pdf_obj *dict)
 	pdf_obj *obj;
 	fz_context *ctx = doc->ctx;
 
-	if ((form = pdf_find_item(ctx, pdf_free_xobject_imp, dict)))
+	if ((form = pdf_find_item(ctx, pdf_free_xobject_imp, dict)) != NULL)
 	{
 		return form;
 	}
diff --git a/source/tools/mudraw.c b/source/tools/mudraw.c
index 8bbaa03d..682aab86 100644
--- a/source/tools/mudraw.c
+++ b/source/tools/mudraw.c
@@ -928,7 +928,6 @@ parse_colorspace(const char *name)
 	}
 	fprintf(stderr, "Unknown colorspace \"%s\"\n", name);
 	exit(1);
-	return -1;
 }
 
 static void *
diff --git a/source/xps/xps-common.c b/source/xps/xps-common.c
index ec16d879..b780f428 100644
--- a/source/xps/xps-common.c
+++ b/source/xps/xps-common.c
@@ -18,7 +18,7 @@ xps_lookup_alternate_content(fz_xml *node)
 			char list[64];
 			char *next = list, *item;
 			fz_strlcpy(list, fz_xml_att(node, "Requires"), sizeof(list));
-			while ((item = fz_strsep(&next, " \t\r\n")) && (!*item || !strcmp(item, "xps")));
+			while ((item = fz_strsep(&next, " \t\r\n")) != NULL && (!*item || !strcmp(item, "xps")));
 			if (!item)
 				return fz_xml_down(node);
 		}
diff --git a/source/xps/xps-doc.c b/source/xps/xps-doc.c
index 097392e8..86d67d4a 100644
--- a/source/xps/xps-doc.c
+++ b/source/xps/xps-doc.c
@@ -510,7 +510,6 @@ xps_load_page(xps_document *doc, int number)
 	}
 
 	fz_throw(doc->ctx, FZ_ERROR_GENERIC, "cannot find page %d", number + 1);
-	return NULL;
 }
 
 fz_rect *
diff --git a/source/xps/xps-zip.c b/source/xps/xps-zip.c
index c9dc9840..3aca8cdb 100644
--- a/source/xps/xps-zip.c
+++ b/source/xps/xps-zip.c
@@ -406,7 +406,6 @@ xps_read_zip_part(xps_document *doc, char *partname)
 	}
 
 	fz_throw(doc->ctx, FZ_ERROR_GENERIC, "cannot find part '%s'", partname);
-	return NULL;
 }
 
 static int
@@ -502,7 +501,6 @@ xps_read_dir_part(xps_document *doc, char *name)
 	}
 
 	fz_throw(doc->ctx, FZ_ERROR_GENERIC, "cannot find part '%s'", name);
-	return NULL;
 }
 
 static int
-- 
cgit v1.2.3