summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Bowler <jbowler@acm.org>2011-11-16 22:37:46 -0600
committerGlenn Randers-Pehrson <glennrp at users.sourceforge.net>2011-11-16 22:37:46 -0600
commit17878c6e6530309721936309cc670b2a8a4287c9 (patch)
tree9a5e7cacfea6e8207faf36ee55d63981cfad794a
parent7006dc4c6a145f6e8a3b2a51bd48b14b9367445f (diff)
downloadlibpng-17878c6e6530309721936309cc670b2a8a4287c9.tar.gz
[libpng15] Work around compilers that don't support declaration of const data.
Some compilers fault 'extern const' data declarations (because the data is not initialized); this turns on const-ness only for compilers where this is known to work.
-rw-r--r--ANNOUNCE4
-rw-r--r--CHANGES4
-rw-r--r--png.c10
-rw-r--r--pngpriv.h26
4 files changed, 36 insertions, 8 deletions
diff --git a/ANNOUNCE b/ANNOUNCE
index cc4fba497..271a8b89e 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -88,6 +88,10 @@ Version 1.5.7beta03 [November 17, 2011]
this on assembler compilation, even though it does on C compilation.
This creates security issues if assembler code is enabled; the
work-around is to set it by default in the flags for $(CCAS)
+ Work around compilers that don't support declaration of const data. Some
+ compilers fault 'extern const' data declarations (because the data is
+ not initialized); this turns on const-ness only for compilers where
+ this is known to work.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net:
(subscription required; visit
diff --git a/CHANGES b/CHANGES
index 7a638aa07..bd7d437bd 100644
--- a/CHANGES
+++ b/CHANGES
@@ -3733,6 +3733,10 @@ Version 1.5.7beta03 [November 17, 2011]
this on assembler compilation, even though it does on C compilation.
This creates security issues if assembler code is enabled; the
work-around is to set it by default in the flags for $(CCAS)
+ Work around compilers that don't support declaration of const data. Some
+ compilers fault 'extern const' data declarations (because the data is
+ not initialized); this turns on const-ness only for compilers where
+ this is known to work.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit
diff --git a/png.c b/png.c
index 14ab048bd..24fd02c57 100644
--- a/png.c
+++ b/png.c
@@ -645,13 +645,13 @@ png_get_copyright(png_const_structp png_ptr)
#else
# ifdef __STDC__
return PNG_STRING_NEWLINE \
- "libpng version 1.5.7beta03 - November 16, 2011" PNG_STRING_NEWLINE \
+ "libpng version 1.5.7beta03 - November 17, 2011" PNG_STRING_NEWLINE \
"Copyright (c) 1998-2011 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \
"Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
"Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
PNG_STRING_NEWLINE;
# else
- return "libpng version 1.5.7beta03 - November 16, 2011\
+ return "libpng version 1.5.7beta03 - November 17, 2011\
Copyright (c) 1998-2011 Glenn Randers-Pehrson\
Copyright (c) 1996-1997 Andreas Dilger\
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
@@ -2876,7 +2876,7 @@ png_build_gamma_table(png_structp png_ptr, int bit_depth)
#ifdef PNG_SIMPLIFIED_READ_SUPPORTED
/* The convert-to-sRGB table is only currently required for read. */
-png_uint_16 png_sRGB_table[256] =
+PNG_CONST_DATA png_uint_16 png_sRGB_table[256] =
{
0,20,40,60,80,99,119,139,
159,179,199,219,241,264,288,313,
@@ -2917,7 +2917,7 @@ png_uint_16 png_sRGB_table[256] =
/* The base/delta tables are required for both read and write (but currently
* only the simplified versions.)
*/
-png_uint_16 png_sRGB_base[512] =
+PNG_CONST_DATA png_uint_16 png_sRGB_base[512] =
{
128,1782,3383,4644,5675,6564,7357,8074,
8732,9346,9921,10463,10977,11466,11935,12384,
@@ -2985,7 +2985,7 @@ png_uint_16 png_sRGB_base[512] =
65070,65126,65183,65239,65296,65352,65409,65465
};
-png_byte png_sRGB_delta[512] =
+PNG_CONST_DATA png_byte png_sRGB_delta[512] =
{
207,201,158,129,113,100,90,82,77,72,68,64,61,59,56,54,
52,50,49,47,46,45,43,42,41,40,39,39,38,37,36,36,
diff --git a/pngpriv.h b/pngpriv.h
index 6f6a85af8..09f6892a6 100644
--- a/pngpriv.h
+++ b/pngpriv.h
@@ -258,6 +258,26 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp;
# define PNG_EXTERN extern
#endif
+#ifndef PNG_CONST_DATA
+/* Some compilers fail if given an "extern const" data declaration followed by a
+ * "const" definition, therefore declaring const data in pngpriv.h is
+ * impossible, the following allows a work-round for the problematic compilers
+ * by defining -DPNG_NO_CONST_DATA on the command line (notice that this does
+ * not affect static const definitions, where there is no declaration.)
+ */
+# ifndef PNG_NO_CONST_DATA
+ /* List of compilers where "extern const" is known to be OK: */
+# if defined __GNUC__ || defined _MSC_VER || defined __WATCOMC__
+# define PNG_CONST_DATA const
+# endif
+# endif
+
+ /* Default to disabling const data declarations: */
+# ifndef PNG_CONST_DATA
+# define PNG_CONST_DATA /*const*/
+# endif
+#endif
+
/* Some fixed point APIs are still required even if not exported because
* they get used by the corresponding floating point APIs. This magic
* deals with this:
@@ -532,14 +552,14 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp;
#if defined PNG_SIMPLIFIED_READ_SUPPORTED ||\
defined PNG_SIMPLIFIED_WRITE_SUPPORTED
#ifdef PNG_SIMPLIFIED_READ_SUPPORTED
-extern /*PRIVATE*/ png_uint_16 png_sRGB_table[256];
+extern /*PRIVATE*/ PNG_CONST_DATA png_uint_16 png_sRGB_table[256];
/* Convert from an sRGB encoded value 0..255 to a 16-bit linear value,
* 0..65535. This table gives the closes 16-bit answers (no errors).
*/
#endif
-extern /*PRIVATE*/ png_uint_16 png_sRGB_base[512];
-extern /*PRIVATE*/ png_byte png_sRGB_delta[512];
+extern /*PRIVATE*/ PNG_CONST_DATA png_uint_16 png_sRGB_base[512];
+extern /*PRIVATE*/ PNG_CONST_DATA png_byte png_sRGB_delta[512];
#define PNG_sRGB_FROM_LINEAR(linear) ((png_sRGB_base[(linear)>>15] +\
((((linear)&0x7fff)*png_sRGB_delta[(linear)>>15])>>12)) >> 8)