1From ebce9f1b129ebc8f2b17afa02a4ffcb9453c11d9 Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Rapha=C3=ABl=20M=C3=A9lotte?= <raphael.melotte@mind.be>
3Date: Mon, 24 Apr 2023 17:27:35 +0200
4Subject: [PATCH] Add missing limits.h include for UINT_MAX
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9encode-basic.c uses 'UINT_MAX', which is available in the 'limits.h'
10header.
11
12In some configurations that build with zlib from [1], by chance
13limits.h gets indirectly included when including 'z-imp.h' (the
14includes are: 'z-imp.h' -> 'zlib.h' -> 'zconf.h' -> 'limits.h'), so
15the build succeeds.
16
17When using other zlib implementations however (for example from [2]),
18limits.h is not necessarily included indirectly, which leads to the
19build failing in the following way:
20
21source/fitz/encode-basic.c: In function 'deflate_write':
22source/fitz/encode-basic.c:343:27: error: 'UINT_MAX' undeclared (first use in this function)
23  343 |         newbufsize = n >= UINT_MAX ? UINT_MAX : deflateBound(&state->z, n);
24      |                           ^~~~~~~~
25source/fitz/encode-basic.c:26:1: note: 'UINT_MAX' is defined in header '<limits.h>'; did you forget to '#include <limits.h>'?
26
27Add the missing include, so that the build succeeds no matter if zlib
28indirectly includes 'limit.h' or not.
29
30Similarly, also add it in output-ps.c where it's also missing.
31
32[1]: https://zlib.net/
33[2]: https://github.com/zlib-ng/zlib-ng
34
35Signed-off-by: Raphaël Mélotte <raphael.melotte@mind.be>
36Upstream: https://bugs.ghostscript.com/show_bug.cgi?id=706667
37---
38 source/fitz/encode-basic.c | 2 ++
39 source/fitz/output-ps.c    | 2 ++
40 2 files changed, 4 insertions(+)
41
42diff --git a/source/fitz/encode-basic.c b/source/fitz/encode-basic.c
43index 03a4ff76b..84f0c35e6 100644
44--- a/source/fitz/encode-basic.c
45+++ b/source/fitz/encode-basic.c
46@@ -24,6 +24,8 @@
47
48 #include "z-imp.h"
49
50+#include <limits.h>
51+
52 struct ahx
53 {
54 	fz_output *chain;
55diff --git a/source/fitz/output-ps.c b/source/fitz/output-ps.c
56index ef22c3cd6..3dc8ea17d 100644
57--- a/source/fitz/output-ps.c
58+++ b/source/fitz/output-ps.c
59@@ -24,6 +24,8 @@
60
61 #include "z-imp.h"
62
63+#include <limits.h>
64+
65 typedef struct ps_band_writer_s
66 {
67 	fz_band_writer super;
68--
692.39.1
70
71