New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing compiler warnings #4619
Fixing compiler warnings #4619
Conversation
All warning are for format specifiers (-WFormat) in sprintf().
Thank you for the speedy turnaround! |
This broke build on older systems where inttypes.h doesn't define the
My fix is defining diff --git a/src/OT/glyf/glyf-helpers.hh b/src/OT/glyf/glyf-helpers.hh
index 635cdfd..7faa5ad 100644
--- a/src/OT/glyf/glyf-helpers.hh
+++ b/src/OT/glyf/glyf-helpers.hh
@@ -1,6 +1,9 @@
#ifndef OT_GLYF_GLYF_HELPERS_HH
#define OT_GLYF_GLYF_HELPERS_HH
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS 1
+#endif
#include "../../hb-open-type.hh"
#include "../../hb-subset-plan.hh"
diff --git a/src/hb-common.cc b/src/hb-common.cc
index 6277f46..608625d 100644
--- a/src/hb-common.cc
+++ b/src/hb-common.cc
@@ -26,6 +26,11 @@
* Google Author(s): Behdad Esfahbod
*/
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS 1
+#endif
+
+
#include "hb.hh"
#include "hb-machinery.hh"
#include "inttypes.h"
diff --git a/src/hb-font.hh b/src/hb-font.hh
index a748ce5..6b54ef4 100644
--- a/src/hb-font.hh
+++ b/src/hb-font.hh
@@ -29,6 +29,10 @@
#ifndef HB_FONT_HH
#define HB_FONT_HH
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS 1
+#endif
+
#include "hb.hh"
#include "hb-face.hh"
diff --git a/src/hb-ot-shaper-arabic.cc b/src/hb-ot-shaper-arabic.cc
index 70a1dff..9751ee0 100644
--- a/src/hb-ot-shaper-arabic.cc
+++ b/src/hb-ot-shaper-arabic.cc
@@ -24,6 +24,10 @@
* Google Author(s): Behdad Esfahbod
*/
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS 1
+#endif
+
#include "hb.hh"
#ifndef HB_NO_OT_SHAPE
diff --git a/src/hb-ot-tag.cc b/src/hb-ot-tag.cc
index d8b1151..234d30b 100644
--- a/src/hb-ot-tag.cc
+++ b/src/hb-ot-tag.cc
@@ -26,6 +26,10 @@
* Google Author(s): Behdad Esfahbod, Roozbeh Pournader
*/
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS 1
+#endif
+
#include "hb.hh"
#include "inttypes.h"
If it is acceptable, please tell me if you want a P/R, or you guys can apply manually. P.S.: |
Thanks. I suggest moving the include and macro to |
I have a slight preference on reverting this patch and just doing casts as needed. |
OK, anything that works. |
I reverted this for now, since we probably will have a release today or tomorrow. |
Which compiler is this? What's special about it? |
I'm guessing that maybe it's not the compiler but libc where int32_t is a long instead of int?? |
It is GCC for a Cortex-M33 where uint32_t is a long int. |
As I suspected. Is the following acceptable then? It is a cleaned-up version of @jpcomito Build-tested only on linux with g++4.9 using cmake build system. diff --git a/src/hb-common.h b/src/hb-common.h
index a9fe666..6317d79 100644
--- a/src/hb-common.h
+++ b/src/hb-common.h
@@ -46,28 +46,33 @@
# define HB_END_DECLS
# endif /* !__cplusplus */
#endif
-#if defined (_SVR4) || defined (SVR4) || defined (__OpenBSD__) || \
- defined (_sgi) || defined (__sun) || defined (sun) || \
- defined (__digital__) || defined (__HP_cc)
-# include <inttypes.h>
-#elif defined (_AIX)
-# include <sys/inttypes.h>
-#elif defined (_MSC_VER) && _MSC_VER < 1600
-/* VS 2010 (_MSC_VER 1600) has stdint.h */
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS 1
+#endif
+
+#if defined (_MSC_VER) && _MSC_VER < 1800
+/* VS 2010 (_MSC_VER 1600) has stdint.h, VS 2013 (_MSC_VER 1800) has inttypes.h */
+# define PRId32 "d"
+# define PRIu32 "u"
+# define PRIx32 "x"
+# if _MSC_VER >= 1600 /* VS 2010+ */
+# include <stdint.h>
+# else
typedef __int8 int8_t;
typedef unsigned __int8 uint8_t;
typedef __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
-#elif defined (__KERNEL__)
-# include <linux/types.h>
+# endif /* VS 2010+ */
+#elif defined (_AIX)
+# include <sys/inttypes.h>
#else
-# include <stdint.h>
+# include <inttypes.h>
#endif
#if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
#define HB_DEPRECATED __attribute__((__deprecated__))
diff --git a/src/OT/glyf/glyf-helpers.hh b/src/OT/glyf/glyf-helpers.hh
index d0a5a13..f157bf0 100644
--- a/src/OT/glyf/glyf-helpers.hh
+++ b/src/OT/glyf/glyf-helpers.hh
@@ -38,7 +38,7 @@ _write_loca (IteratorIn&& it,
unsigned padded_size = *it++;
offset += padded_size;
- DEBUG_MSG (SUBSET, nullptr, "loca entry gid %u offset %u padded-size %u", gid, offset, padded_size);
+ DEBUG_MSG (SUBSET, nullptr, "loca entry gid %" PRIu32 " offset %u padded-size %u", gid, offset, padded_size);
value = offset >> right_shift;
*dest++ = value;
diff --git a/src/hb-common.cc b/src/hb-common.cc
index 0c13c7d..4b8bae4 100644
--- a/src/hb-common.cc
+++ b/src/hb-common.cc
@@ -996,7 +996,7 @@ hb_feature_to_string (hb_feature_t *feature,
if (feature->value > 1)
{
s[len++] = '=';
- len += hb_max (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%u", feature->value));
+ len += hb_max (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%" PRIu32, feature->value));
}
assert (len < ARRAY_LENGTH (s));
len = hb_min (len, size - 1);
diff --git a/src/hb-font.hh b/src/hb-font.hh
index f503575..4c8190b 100644
--- a/src/hb-font.hh
+++ b/src/hb-font.hh
@@ -651,7 +651,7 @@ struct hb_font_t
{
if (get_glyph_name (glyph, s, size)) return;
- if (size && snprintf (s, size, "gid%u", glyph) < 0)
+ if (size && snprintf (s, size, "gid%" PRIu32, glyph) < 0)
*s = '\0';
}
diff --git a/src/hb-ot-shaper-arabic.cc b/src/hb-ot-shaper-arabic.cc
index 72dcc84..d70746e 100644
--- a/src/hb-ot-shaper-arabic.cc
+++ b/src/hb-ot-shaper-arabic.cc
@@ -560,9 +560,9 @@ apply_stch (const hb_ot_shape_plan_t *plan HB_UNUSED,
DEBUG_MSG (ARABIC, nullptr, "%s stretch at (%u,%u,%u)",
step == MEASURE ? "measuring" : "cutting", context, start, end);
- DEBUG_MSG (ARABIC, nullptr, "rest of word: count=%u width %d", start - context, w_total);
- DEBUG_MSG (ARABIC, nullptr, "fixed tiles: count=%d width=%d", n_fixed, w_fixed);
- DEBUG_MSG (ARABIC, nullptr, "repeating tiles: count=%d width=%d", n_repeating, w_repeating);
+ DEBUG_MSG (ARABIC, nullptr, "rest of word: count=%u width %" PRId32, start - context, w_total);
+ DEBUG_MSG (ARABIC, nullptr, "fixed tiles: count=%d width=%" PRId32, n_fixed, w_fixed);
+ DEBUG_MSG (ARABIC, nullptr, "repeating tiles: count=%d width=%" PRId32, n_repeating, w_repeating);
/* Number of additional times to repeat each repeating tile. */
int n_copies = 0;
@@ -602,7 +602,7 @@ apply_stch (const hb_ot_shape_plan_t *plan HB_UNUSED,
if (info[k - 1].arabic_shaping_action() == STCH_REPEATING)
repeat += n_copies;
- DEBUG_MSG (ARABIC, nullptr, "appending %u copies of glyph %u; j=%u",
+ DEBUG_MSG (ARABIC, nullptr, "appending %u copies of glyph %" PRIu32 "; j=%u",
repeat, info[k - 1].codepoint, j);
pos[k - 1].x_advance = 0;
for (unsigned int n = 0; n < repeat; n++)
diff --git a/src/hb-ot-tag.cc b/src/hb-ot-tag.cc
index 53b6b38..0c63756 100644
--- a/src/hb-ot-tag.cc
+++ b/src/hb-ot-tag.cc
@@ -547,7 +547,7 @@ hb_ot_tag_to_language (hb_tag_t tag)
buf[3] = '-';
str += 4;
}
- snprintf (str, 16, "x-hbot-%08x", tag);
+ snprintf (str, 16, "x-hbot-%08" PRIx32, tag);
return hb_language_from_string (&*buf, -1);
}
} |
LGTM |
Created #4622 |
This is what I mean: #4623 |
All warning are for format specifiers (-WFormat) in sprintf().
Test: Compile only