Skip to content
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

Merged
merged 1 commit into from Mar 13, 2024
Merged

Fixing compiler warnings #4619

merged 1 commit into from Mar 13, 2024

Conversation

jpcomito
Copy link
Contributor

All warning are for format specifiers (-WFormat) in sprintf().

Test: Compile only

All warning are for format specifiers (-WFormat) in sprintf().
@behdad behdad merged commit 61a1ba2 into harfbuzz:main Mar 13, 2024
22 checks passed
@jpcomito
Copy link
Contributor Author

Thank you for the speedy turnaround!

@jpcomito jpcomito deleted the compiler_warnings branch March 13, 2024 19:22
@sezero
Copy link
Contributor

sezero commented Mar 14, 2024

This broke build on older systems where inttypes.h doesn't define the PRIxxx macros in C++ unless __STDC_FORMAT_MACROS is defined. See, e.g.:

In file included from /tmp/harfbuzz/src/hb-subset-input.hh:37:0,
                 from /tmp/harfbuzz/src/hb-subset.hh:37,
                 from /tmp/harfbuzz/src/hb-open-type.hh:37,
                 from /tmp/harfbuzz/src/hb-aat-ltag-table.hh:28,
                 from /tmp/harfbuzz/src/hb-aat-layout.hh:33,
                 from /tmp/harfbuzz/src/hb-aat-layout.cc:30,
                 from /tmp/harfbuzz/src/harfbuzz.cc:1:
/tmp/harfbuzz/src/hb-font.hh: In member function 'void hb_font_t::glyph_to_string(hb_codepoint_t, char*, unsigned int)':
/tmp/harfbuzz/src/hb-font.hh:655:43: error: expected ')' before 'PRIu32'
     if (size && snprintf (s, size, "gid%" PRIu32 "", glyph) < 0)
                                           ^
/tmp/harfbuzz/src/hb-font.hh:655:59: warning: spurious trailing '%' in format [-Wformat=]
     if (size && snprintf (s, size, "gid%" PRIu32 "", glyph) < 0)
                                                           ^
/tmp/harfbuzz/src/hb-font.hh:655:59: warning: too many arguments for format [-Wformat-extra-args]
/tmp/harfbuzz/src/hb-font.hh:655:59: warning: spurious trailing '%' in format [-Wformat=]
/tmp/harfbuzz/src/hb-font.hh:655:59: warning: too many arguments for format [-Wformat-extra-args]
In file included from /tmp/harfbuzz/src/harfbuzz.cc:7:0:
/tmp/harfbuzz/src/hb-common.cc: In function 'void hb_feature_to_string(hb_feature_t*, char*, unsigned int)':
/tmp/harfbuzz/src/hb-common.cc:1000:70: error: expected ')' before 'PRIu32'
     len += hb_max (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%" PRIu32 "", feature->value));
                                                                      ^
/tmp/harfbuzz/src/hb-common.cc:1000:95: warning: spurious trailing '%' in format [-Wformat=]
     len += hb_max (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%" PRIu32 "", feature->value));
                                                                                               ^
/tmp/harfbuzz/src/hb-common.cc:1000:95: warning: too many arguments for format [-Wformat-extra-args]
/tmp/harfbuzz/src/hb-common.cc:1000:95: warning: spurious trailing '%' in format [-Wformat=]
/tmp/harfbuzz/src/hb-common.cc:1000:95: warning: too many arguments for format [-Wformat-extra-args]
In file included from /tmp/harfbuzz/src/hb.hh:539:0,
                 from /tmp/harfbuzz/src/hb-aat-layout.cc:28,
                 from /tmp/harfbuzz/src/harfbuzz.cc:1:
/tmp/harfbuzz/src/OT/glyf/glyf-helpers.hh: In function 'void OT::glyf_impl::_write_loca(IteratorIn&&, hb_sorted_vector_t<hb_pair_t<unsigned int, unsigned int> >, bool, TypeOut*, unsigned int)':
/tmp/harfbuzz/src/OT/glyf/glyf-helpers.hh:42:52: error: expected ')' before 'PRIu32'
     DEBUG_MSG (SUBSET, nullptr, "loca entry gid %" PRIu32 " offset %u padded-size %u", gid, offset, padded_size);
                                                    ^
/tmp/harfbuzz/src/hb-debug.hh:232:109: note: in definition of macro 'DEBUG_MSG'
 #define DEBUG_MSG(WHAT, OBJ, ...)    _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), nullptr,    false, 0, 0, __VA_ARGS__)
                                                                                                             ^
/tmp/harfbuzz/src/hb-ot-shaper-arabic.cc: In function 'void apply_stch(const hb_ot_shape_plan_t*, hb_buffer_t*, hb_font_t*)':
/tmp/harfbuzz/src/hb-ot-shaper-arabic.cc:563:71: error: expected ')' before 'PRId32'
       DEBUG_MSG (ARABIC, nullptr, "rest of word:    count=%u width %" PRId32 "", start - context, w_total);
                                                                       ^
/tmp/harfbuzz/src/hb-debug.hh:232:109: note: in definition of macro 'DEBUG_MSG'
 #define DEBUG_MSG(WHAT, OBJ, ...)    _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), nullptr,    false, 0, 0, __VA_ARGS__)
                                                                                                             ^
/tmp/harfbuzz/src/hb-debug.hh:232:120: warning: spurious trailing '%' in format [-Wformat=]
 #define DEBUG_MSG(WHAT, OBJ, ...)    _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), nullptr,    false, 0, 0, __VA_ARGS__)
                                                                                                                        ^
/tmp/harfbuzz/src/hb-ot-shaper-arabic.cc:563:7: note: in expansion of macro 'DEBUG_MSG'
       DEBUG_MSG (ARABIC, nullptr, "rest of word:    count=%u width %" PRId32 "", start - context, w_total);
       ^
/tmp/harfbuzz/src/hb-debug.hh:232:120: warning: too many arguments for format [-Wformat-extra-args]
 #define DEBUG_MSG(WHAT, OBJ, ...)    _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), nullptr,    false, 0, 0, __VA_ARGS__)
                                                                                                                        ^
/tmp/harfbuzz/src/hb-ot-shaper-arabic.cc:563:7: note: in expansion of macro 'DEBUG_MSG'
       DEBUG_MSG (ARABIC, nullptr, "rest of word:    count=%u width %" PRId32 "", start - context, w_total);
       ^
/tmp/harfbuzz/src/hb-ot-shaper-arabic.cc:564:71: error: expected ')' before 'PRId32'
       DEBUG_MSG (ARABIC, nullptr, "fixed tiles:     count=%d width=%" PRId32 "", n_fixed, w_fixed);
                                                                       ^
/tmp/harfbuzz/src/hb-debug.hh:232:109: note: in definition of macro 'DEBUG_MSG'
 #define DEBUG_MSG(WHAT, OBJ, ...)    _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), nullptr,    false, 0, 0, __VA_ARGS__)
                                                                                                             ^
/tmp/harfbuzz/src/hb-debug.hh:232:120: warning: spurious trailing '%' in format [-Wformat=]
 #define DEBUG_MSG(WHAT, OBJ, ...)    _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), nullptr,    false, 0, 0, __VA_ARGS__)
                                                                                                                        ^
/tmp/harfbuzz/src/hb-ot-shaper-arabic.cc:564:7: note: in expansion of macro 'DEBUG_MSG'
       DEBUG_MSG (ARABIC, nullptr, "fixed tiles:     count=%d width=%" PRId32 "", n_fixed, w_fixed);
       ^
/tmp/harfbuzz/src/hb-debug.hh:232:120: warning: too many arguments for format [-Wformat-extra-args]
 #define DEBUG_MSG(WHAT, OBJ, ...)    _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), nullptr,    false, 0, 0, __VA_ARGS__)
                                                                                                                        ^
/tmp/harfbuzz/src/hb-ot-shaper-arabic.cc:564:7: note: in expansion of macro 'DEBUG_MSG'
       DEBUG_MSG (ARABIC, nullptr, "fixed tiles:     count=%d width=%" PRId32 "", n_fixed, w_fixed);
       ^
/tmp/harfbuzz/src/hb-ot-shaper-arabic.cc:565:71: error: expected ')' before 'PRId32'
       DEBUG_MSG (ARABIC, nullptr, "repeating tiles: count=%d width=%" PRId32 "", n_repeating, w_repeating);
                                                                       ^
/tmp/harfbuzz/src/hb-debug.hh:232:109: note: in definition of macro 'DEBUG_MSG'
 #define DEBUG_MSG(WHAT, OBJ, ...)    _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), nullptr,    false, 0, 0, __VA_ARGS__)
                                                                                                             ^
/tmp/harfbuzz/src/hb-debug.hh:232:120: warning: spurious trailing '%' in format [-Wformat=]
 #define DEBUG_MSG(WHAT, OBJ, ...)    _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), nullptr,    false, 0, 0, __VA_ARGS__)
                                                                                                                        ^
/tmp/harfbuzz/src/hb-ot-shaper-arabic.cc:565:7: note: in expansion of macro 'DEBUG_MSG'
       DEBUG_MSG (ARABIC, nullptr, "repeating tiles: count=%d width=%" PRId32 "", n_repeating, w_repeating);
       ^
/tmp/harfbuzz/src/hb-debug.hh:232:120: warning: too many arguments for format [-Wformat-extra-args]
 #define DEBUG_MSG(WHAT, OBJ, ...)    _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), nullptr,    false, 0, 0, __VA_ARGS__)
                                                                                                                        ^
/tmp/harfbuzz/src/hb-ot-shaper-arabic.cc:565:7: note: in expansion of macro 'DEBUG_MSG'
       DEBUG_MSG (ARABIC, nullptr, "repeating tiles: count=%d width=%" PRId32 "", n_repeating, w_repeating);
       ^
/tmp/harfbuzz/src/hb-ot-shaper-arabic.cc:605:65: error: expected ')' before 'PRIu32'
    DEBUG_MSG (ARABIC, nullptr, "appending %u copies of glyph %" PRIu32 "; j=%u",
                                                                 ^
/tmp/harfbuzz/src/hb-debug.hh:232:109: note: in definition of macro 'DEBUG_MSG'
 #define DEBUG_MSG(WHAT, OBJ, ...)    _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), nullptr,    false, 0, 0, __VA_ARGS__)
                                                                                                             ^
/tmp/harfbuzz/src/hb-debug.hh:232:120: warning: spurious trailing '%' in format [-Wformat=]
 #define DEBUG_MSG(WHAT, OBJ, ...)    _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), nullptr,    false, 0, 0, __VA_ARGS__)
                                                                                                                        ^
/tmp/harfbuzz/src/hb-ot-shaper-arabic.cc:605:4: note: in expansion of macro 'DEBUG_MSG'
    DEBUG_MSG (ARABIC, nullptr, "appending %u copies of glyph %" PRIu32 "; j=%u",
    ^
/tmp/harfbuzz/src/hb-debug.hh:232:120: warning: too many arguments for format [-Wformat-extra-args]
 #define DEBUG_MSG(WHAT, OBJ, ...)    _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), nullptr,    false, 0, 0, __VA_ARGS__)
                                                                                                                        ^
/tmp/harfbuzz/src/hb-ot-shaper-arabic.cc:605:4: note: in expansion of macro 'DEBUG_MSG'
    DEBUG_MSG (ARABIC, nullptr, "appending %u copies of glyph %" PRIu32 "; j=%u",
    ^
In file included from /tmp/harfbuzz/src/harfbuzz.cc:47:0:
/tmp/harfbuzz/src/hb-ot-tag.cc: In function 'const hb_language_impl_t* hb_ot_tag_to_language(hb_tag_t)':
/tmp/harfbuzz/src/hb-ot-tag.cc:551:37: error: expected ')' before 'PRIx32'
     snprintf (str, 16, "x-hbot-%08" PRIx32 "", tag);
                                     ^
/tmp/harfbuzz/src/hb-ot-tag.cc:551:51: warning: conversion lacks type at end of format [-Wformat=]
     snprintf (str, 16, "x-hbot-%08" PRIx32 "", tag);
                                                   ^
/tmp/harfbuzz/src/hb-ot-tag.cc:551:51: warning: too many arguments for format [-Wformat-extra-args]
/tmp/harfbuzz/src/hb-ot-tag.cc:551:51: warning: conversion lacks type at end of format [-Wformat=]
/tmp/harfbuzz/src/hb-ot-tag.cc:551:51: warning: too many arguments for format [-Wformat-extra-args]
In file included from /tmp/harfbuzz/src/hb.hh:539:0,
                 from /tmp/harfbuzz/src/hb-aat-layout.cc:28,
                 from /tmp/harfbuzz/src/harfbuzz.cc:1:
/tmp/harfbuzz/src/OT/glyf/glyf-helpers.hh: In instantiation of 'void OT::glyf_impl::_write_loca(IteratorIn&&, hb_sorted_vector_t<hb_pair_t<unsigned int, unsigned int> >, bool, TypeOut*, unsigned int) [with IteratorIn = hb_array_t<const unsigned int>&; TypeOut = OT::IntType<short unsigned int>; typename hb_enable_if<hb_is_source_of<Iterator, unsigned int>::value>::type* <anonymous> = 0u; hb_sorted_vector_t<hb_pair_t<unsigned int, unsigned int> > = hb_vector_t<hb_pair_t<unsigned int, unsigned int>, true>]':
/tmp/harfbuzz/src/OT/glyf/glyf-helpers.hh:106:111:   required from 'bool OT::glyf_impl::_add_loca_and_head(hb_subset_context_t*, Iterator, bool) [with Iterator = hb_array_t<const unsigned int>; typename hb_enable_if<hb_is_source_of<Iterator, unsigned int>::value>::type* <anonymous> = 0u]'
/tmp/harfbuzz/src/OT/glyf/glyf.hh:134:9:   required from here
/tmp/harfbuzz/src/hb-debug.hh:232:120: warning: spurious trailing '%' in format [-Wformat=]
 #define DEBUG_MSG(WHAT, OBJ, ...)    _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), nullptr,    false, 0, 0, __VA_ARGS__)
                                                                                                                        ^
/tmp/harfbuzz/src/OT/glyf/glyf-helpers.hh:42:5: note: in expansion of macro 'DEBUG_MSG'
     DEBUG_MSG (SUBSET, nullptr, "loca entry gid %" PRIu32 " offset %u padded-size %u", gid, offset, padded_size);
     ^
/tmp/harfbuzz/src/hb-debug.hh:232:120: warning: too many arguments for format [-Wformat-extra-args]
 #define DEBUG_MSG(WHAT, OBJ, ...)    _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), nullptr,    false, 0, 0, __VA_ARGS__)
                                                                                                                        ^
/tmp/harfbuzz/src/OT/glyf/glyf-helpers.hh:42:5: note: in expansion of macro 'DEBUG_MSG'
     DEBUG_MSG (SUBSET, nullptr, "loca entry gid %" PRIu32 " offset %u padded-size %u", gid, offset, padded_size);
     ^
/tmp/harfbuzz/src/OT/glyf/glyf-helpers.hh: In instantiation of 'void OT::glyf_impl::_write_loca(IteratorIn&&, hb_sorted_vector_t<hb_pair_t<unsigned int, unsigned int> >, bool, TypeOut*, unsigned int) [with IteratorIn = hb_array_t<const unsigned int>&; TypeOut = OT::IntType<unsigned int>; typename hb_enable_if<hb_is_source_of<Iterator, unsigned int>::value>::type* <anonymous> = 0u; hb_sorted_vector_t<hb_pair_t<unsigned int, unsigned int> > = hb_vector_t<hb_pair_t<unsigned int, unsigned int>, true>]':
/tmp/harfbuzz/src/OT/glyf/glyf-helpers.hh:108:112:   required from 'bool OT::glyf_impl::_add_loca_and_head(hb_subset_context_t*, Iterator, bool) [with Iterator = hb_array_t<const unsigned int>; typename hb_enable_if<hb_is_source_of<Iterator, unsigned int>::value>::type* <anonymous> = 0u]'
/tmp/harfbuzz/src/OT/glyf/glyf.hh:134:9:   required from here
/tmp/harfbuzz/src/hb-debug.hh:232:120: warning: spurious trailing '%' in format [-Wformat=]
 #define DEBUG_MSG(WHAT, OBJ, ...)    _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), nullptr,    false, 0, 0, __VA_ARGS__)
                                                                                                                        ^
/tmp/harfbuzz/src/OT/glyf/glyf-helpers.hh:42:5: note: in expansion of macro 'DEBUG_MSG'
     DEBUG_MSG (SUBSET, nullptr, "loca entry gid %" PRIu32 " offset %u padded-size %u", gid, offset, padded_size);
     ^
/tmp/harfbuzz/src/hb-debug.hh:232:120: warning: too many arguments for format [-Wformat-extra-args]
 #define DEBUG_MSG(WHAT, OBJ, ...)    _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), nullptr,    false, 0, 0, __VA_ARGS__)
                                                                                                                        ^
/tmp/harfbuzz/src/OT/glyf/glyf-helpers.hh:42:5: note: in expansion of macro 'DEBUG_MSG'
     DEBUG_MSG (SUBSET, nullptr, "loca entry gid %" PRIu32 " offset %u padded-size %u", gid, offset, padded_size);
     ^
make[2]: *** [CMakeFiles/harfbuzz.dir/src/harfbuzz.cc.o] Error 1
make[1]: *** [CMakeFiles/harfbuzz.dir/all] Error 2
make: *** [all] Error 2

My fix is defining __STDC_FORMAT_MACROS inthe files touched by this P/R:

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.: #include "inttypes.h" seems wrong to me: It should be #include <inttypes.h> no?

@behdad
Copy link
Member

behdad commented Mar 14, 2024

Thanks.

I suggest moving the include and macro to hb.hh. And probably as #include <cinttypes>.

@behdad
Copy link
Member

behdad commented Mar 14, 2024

I have a slight preference on reverting this patch and just doing casts as needed.

@sezero
Copy link
Contributor

sezero commented Mar 14, 2024

OK, anything that works.

@behdad
Copy link
Member

behdad commented Mar 14, 2024

I reverted this for now, since we probably will have a release today or tomorrow.

@behdad
Copy link
Member

behdad commented Mar 14, 2024

All warning are for format specifiers (-WFormat) in sprintf().

Which compiler is this? What's special about it?

@sezero
Copy link
Contributor

sezero commented Mar 14, 2024

All warning are for format specifiers (-WFormat) in sprintf().

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??
(@jpcomito should have the right answers, of course..)

@jpcomito
Copy link
Contributor Author

It is GCC for a Cortex-M33 where uint32_t is a long int.

@sezero
Copy link
Contributor

sezero commented Mar 15, 2024

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
patch which doesn't include inttypes.h in individual files but modifies
hb-common.h instead by expecting inttypes.h presence (and undoes #1974 and
902ab86 along the way somehow) and defines __STDC_FORMAT_MACROS there.

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);
   }
 }

@behdad
Copy link
Member

behdad commented Mar 15, 2024

LGTM

@sezero
Copy link
Contributor

sezero commented Mar 15, 2024

LGTM

Created #4622

behdad pushed a commit that referenced this pull request Mar 15, 2024
This is a modified and cleaned-up version of PR #4619 by @jpcomito:
hb-common.h now expects 'inttypes.h' presence with MSVC exceptions,
defines __STDC_FORMAT_MACROS in there (if not already defined) and
undoes c930ae2 (PR #1974) and 902ab86.

Co-authored-by: jcomito <jcomito@google.com>
@behdad
Copy link
Member

behdad commented Mar 15, 2024

This is what I mean: #4623

behdad pushed a commit that referenced this pull request Mar 15, 2024
This is a modified and cleaned-up version of PR #4619 by @jpcomito:
hb-common.h now expects 'inttypes.h' presence with MSVC exceptions,
defines __STDC_FORMAT_MACROS in there (if not already defined) and
undoes c930ae2 (PR #1974) and 902ab86.

Co-authored-by: jcomito <jcomito@google.com>
behdad pushed a commit that referenced this pull request Mar 15, 2024
This is a modified and cleaned-up version of PR #4619 by @jpcomito:
hb-common.h now expects 'inttypes.h' presence with MSVC exceptions,
defines __STDC_FORMAT_MACROS in there (if not already defined) and
undoes c930ae2 (PR #1974) and 902ab86.

Co-authored-by: jcomito <jcomito@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants