[geos-commits] [SCM] GEOS branch main updated. 93e74e57d0e5be7026b87162c640fa866db661da

git at osgeo.org git at osgeo.org
Fri May 24 10:43:42 PDT 2024


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".

The branch, main has been updated
       via  93e74e57d0e5be7026b87162c640fa866db661da (commit)
      from  6de25db755162d79e24474924ae05ee1c37aafb0 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 93e74e57d0e5be7026b87162c640fa866db661da
Author: Sandro Santilli <strk at kbt.io>
Date:   Fri May 24 19:43:15 2024 +0200

    Add printf format attribute (#1097)
    
    as suggested by -Wsuggest-attribute=format
    
    Handle MinGW and MSVC printf format attributes
    
    ---------
    
    Co-authored-by: Mike Taves <mwtoews at gmail.com>

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 622838340..fb7f4ebd7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -307,9 +307,9 @@ target_compile_definitions(geos_developer_cxx_flags
 
 target_compile_options(geos_developer_cxx_flags
   INTERFACE
-    $<$<CXX_COMPILER_ID:MSVC>:-W4>
+    $<$<CXX_COMPILER_ID:MSVC>:-W4>  # consider -analyze
     $<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-Werror -pedantic -Wall -Wextra -Wno-long-long -Wcast-align -Wconversion -Wsign-conversion -Wchar-subscripts -Wdouble-promotion -Wpointer-arith -Wformat -Wformat-security -Wshadow -Wuninitialized -Wunused-parameter -fno-common>
-    $<$<CXX_COMPILER_ID:GNU>:-fno-implicit-inline-templates -Wno-psabi>
+    $<$<CXX_COMPILER_ID:GNU>:-fno-implicit-inline-templates -Wno-psabi -Wsuggest-attribute=format>
     $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-Wno-unknown-warning-option>
     )
 
diff --git a/capi/geos_c.h.in b/capi/geos_c.h.in
index 31d1feaef..5db388b24 100644
--- a/capi/geos_c.h.in
+++ b/capi/geos_c.h.in
@@ -102,7 +102,8 @@ typedef struct GEOSContextHandle_HS *GEOSContextHandle_t;
 *
 * \param fmt the message format template
 */
-typedef void (*GEOSMessageHandler)(const char *fmt, ...);
+typedef void (*GEOSMessageHandler)(GEOS_PRINTF_FORMAT const char *fmt, ...)
+    GEOS_PRINTF_FORMAT_ATTR(1, 2);
 
 /**
 * A GEOS message handler function.
diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp
index 6efc5f2f5..2c18d8489 100644
--- a/capi/geos_ts_c.cpp
+++ b/capi/geos_ts_c.cpp
@@ -289,7 +289,7 @@ typedef struct GEOSContextHandle_HS {
     }
 
     void
-    NOTICE_MESSAGE(const char *fmt, ...)
+    NOTICE_MESSAGE(GEOS_PRINTF_FORMAT const char *fmt, ...) GEOS_PRINTF_FORMAT_ATTR(2, 3)
     {
         if(nullptr == noticeMessageOld && nullptr == noticeMessageNew) {
             return;
@@ -297,7 +297,14 @@ typedef struct GEOSContextHandle_HS {
 
         va_list args;
         va_start(args, fmt);
+        #ifdef __MINGW32__
+        #pragma GCC diagnostic push
+        #pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
+        #endif
         int result = vsnprintf(msgBuffer, sizeof(msgBuffer) - 1, fmt, args);
+        #ifdef __MINGW32__
+        #pragma GCC diagnostic pop
+        #endif
         va_end(args);
 
         if(result > 0) {
@@ -311,7 +318,7 @@ typedef struct GEOSContextHandle_HS {
     }
 
     void
-    ERROR_MESSAGE(const char *fmt, ...)
+    ERROR_MESSAGE(GEOS_PRINTF_FORMAT const char *fmt, ...) GEOS_PRINTF_FORMAT_ATTR(2, 3)
     {
         if(nullptr == errorMessageOld && nullptr == errorMessageNew) {
             return;
@@ -319,7 +326,14 @@ typedef struct GEOSContextHandle_HS {
 
         va_list args;
         va_start(args, fmt);
+        #ifdef __MINGW32__
+        #pragma GCC diagnostic push
+        #pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
+        #endif
         int result = vsnprintf(msgBuffer, sizeof(msgBuffer) - 1, fmt, args);
+        #ifdef __MINGW32__
+        #pragma GCC diagnostic pop
+        #endif
         va_end(args);
 
         if(result > 0) {
diff --git a/include/geos/export.h b/include/geos/export.h
index 997fb4c30..d1baff31d 100644
--- a/include/geos/export.h
+++ b/include/geos/export.h
@@ -31,3 +31,21 @@
 #if defined(_MSC_VER)
 #  pragma warning(disable: 4251) // identifier : class type needs to have dll-interface to be used by clients of class type2
 #endif
+
+
+/**********************************************************************
+ * Portability macros
+ **********************************************************************/
+
+#ifdef _MSC_VER
+#include <sal.h>
+#define GEOS_PRINTF_FORMAT _Printf_format_string_
+#define GEOS_PRINTF_FORMAT_ATTR(format_param, dots_param) /**/
+#elif __GNUC__
+#define GEOS_PRINTF_FORMAT /**/
+#define GEOS_PRINTF_FORMAT_ATTR(format_param, dots_param) \
+  __attribute__((format(printf, format_param, dots_param)))
+#else
+#define GEOS_PRINTF_FORMAT /**/
+#define GEOS_PRINTF_FORMAT_ATTR(format_param, dots_param) /**/
+#endif
diff --git a/tests/unit/capi/capi_test_utils.h b/tests/unit/capi/capi_test_utils.h
index 3ceed08d6..5f2d0cf04 100644
--- a/tests/unit/capi/capi_test_utils.h
+++ b/tests/unit/capi/capi_test_utils.h
@@ -61,13 +61,20 @@ namespace capitest {
             finishGEOS();
         }
 
-        static void notice(const char* fmt, ...)
+        static void notice(GEOS_PRINTF_FORMAT const char* fmt, ...) GEOS_PRINTF_FORMAT_ATTR(1, 2)
         {
             std::fprintf(stdout, "NOTICE: ");
 
             va_list ap;
             va_start(ap, fmt);
+            #ifdef __MINGW32__
+            #pragma GCC diagnostic push
+            #pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
+            #endif
             std::vfprintf(stdout, fmt, ap);
+            #ifdef __MINGW32__
+            #pragma GCC diagnostic pop
+            #endif
             va_end(ap);
 
             std::fprintf(stdout, "\n");

-----------------------------------------------------------------------

Summary of changes:
 CMakeLists.txt                    |  4 ++--
 capi/geos_c.h.in                  |  3 ++-
 capi/geos_ts_c.cpp                | 18 ++++++++++++++++--
 include/geos/export.h             | 18 ++++++++++++++++++
 tests/unit/capi/capi_test_utils.h |  9 ++++++++-
 5 files changed, 46 insertions(+), 6 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list