Subject: [PATCH 1/1] gnu: giflib: Make "reallocarray" private, solve [email-masked] conflict.

From: Hartmut Goebel <[email-masked]>
Date: Wed, 28 Feb 2018 21:12:02 +0100

Move the declaration from gif_lib.h to gif_lib_private.h to solve
conflicts when some .c-file #includes both stdlib.h and gif_lib.h.
See also https://sourceforge.net/p/giflib/bugs/110/

* gnu/packages/patches/giflib-make-reallocarray-private.patch: New
  file
* gnu/local.mk (dist_patch_DATA): Register it.
* gnu/packages/image.scm(giflib)[source](patches): New field.
---
 gnu/local.mk                                       |  1 +
 gnu/packages/image.scm                             |  4 ++-
 .../patches/giflib-make-reallocarray-private.patch | 42 ++++++++++++++++++++++
 3 files changed, 46 insertions(+), 1 deletion(-)
 create mode 100644 gnu/packages/patches/giflib-make-reallocarray-private.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 24368727f..de8161bbb 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -693,6 +693,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/ghostscript-no-header-uuid.patch		\
   %D%/packages/patches/ghostscript-no-header-creationdate.patch \
   %D%/packages/patches/ghostscript-runpath.patch		\
+  %D%/packages/patches/giflib-make-reallocarray-private.patch	\
   %D%/packages/patches/gimp-CVE-2017-17784.patch		\
   %D%/packages/patches/gimp-CVE-2017-17785.patch		\
   %D%/packages/patches/gimp-CVE-2017-17786.patch		\
diff --git a/gnu/packages/image.scm b/gnu/packages/image.scm
index e3e3a3ccc..a39718903 100644
--- a/gnu/packages/image.scm
+++ b/gnu/packages/image.scm
@@ -572,7 +572,9 @@ error-resilience, a Java-viewer for j2k-images, ...")
                                   version ".tar.bz2"))
               (sha256
                (base32
-                "1md83dip8rf29y40cm5r7nn19705f54iraz6545zhwa6y8zyq9yz"))))
+                "1md83dip8rf29y40cm5r7nn19705f54iraz6545zhwa6y8zyq9yz"))
+              (patches (search-patches
+                        "giflib-make-reallocarray-private.patch"))))
     (build-system gnu-build-system)
     (outputs '("bin"                    ; utility programs
                "out"))                  ; library
diff --git a/gnu/packages/patches/giflib-make-reallocarray-private.patch b/gnu/packages/patches/giflib-make-reallocarray-private.patch
new file mode 100644
index 000000000..d29ac05c8
--- /dev/null
+++ b/gnu/packages/patches/giflib-make-reallocarray-private.patch
@@ -0,0 +1,42 @@
+Move the declaration from gif_lib.h to gif_lib_private.h to solve
+conflicts when some .c-file #includes both stdlib.h and gif_lib.h.
+See also https://sourceforge.net/p/giflib/bugs/110/
+
+diff -ur giflib-5.1.4.orig/lib/gifalloc.c giflib-5.1.4/lib/gifalloc.c
+--- giflib-5.1.4.orig/lib/gifalloc.c	2018-02-28 20:31:02.294682673 +0100
++++ giflib-5.1.4/lib/gifalloc.c	2018-02-28 20:39:12.093799085 +0100
+@@ -8,7 +8,7 @@
+ #include <stdio.h>
+ #include <string.h>
+ 
+-#include "gif_lib.h"
++#include "gif_lib_private.h"
+ 
+ #define MAX(x, y)    (((x) > (y)) ? (x) : (y))
+ 
+diff -ur giflib-5.1.4.orig/lib/gif_lib.h giflib-5.1.4/lib/gif_lib.h
+--- giflib-5.1.4.orig/lib/gif_lib.h	2018-02-28 20:31:02.294682673 +0100
++++ giflib-5.1.4/lib/gif_lib.h	2018-02-28 20:31:43.135716712 +0100
+@@ -244,9 +244,6 @@
+                                      GifPixelType ColorTransIn2[]);
+ extern int GifBitSize(int n);
+ 
+-extern void *
+-reallocarray(void *optr, size_t nmemb, size_t size);
+-
+ /******************************************************************************
+  Support for the in-core structures allocation (slurp mode).              
+ ******************************************************************************/
+diff -ur giflib-5.1.4.orig/lib/gif_lib_private.h giflib-5.1.4/lib/gif_lib_private.h
+--- giflib-5.1.4.orig/lib/gif_lib_private.h	2018-02-28 20:31:02.294682673 +0100
++++ giflib-5.1.4/lib/gif_lib_private.h	2018-02-28 20:31:56.208257947 +0100
+@@ -54,6 +54,9 @@
+     bool gif89;
+ } GifFilePrivateType;
+ 
++extern void *
++reallocarray(void *optr, size_t nmemb, size_t size);
++
+ #endif /* _GIF_LIB_PRIVATE_H */
+ 
+ /* end */
-- 
2.13.6