Commit 26d0f579c01018e2f42250ee48c0250e2e524541

Werner Lemberg 2019-11-23T10:28:37

* include/freetype/internal/ftmemory.h (FT_OFFSET): New macro. Use this for `base + offset' pointer calculations where `base' can be NULL (triggering a sanitizer warning even if the resulting pointer gets never dereferenced since it is undefined behaviour in C). Suggested by Ben Wagner.

diff --git a/ChangeLog b/ChangeLog
index b921853..23c3595 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2019-11-23  Werner Lemberg  <wl@gnu.org>
+
+	* include/freetype/internal/ftmemory.h (FT_OFFSET): New macro.
+
+	Use this for `base + offset' pointer calculations where `base' can
+	be NULL (triggering a sanitizer warning even if the resulting
+	pointer gets never dereferenced since it is undefined behaviour
+	in C).
+
+	Suggested by Ben Wagner.
+
 2019-11-23  Ben Wagner  <bungeman@google.com>
 
 	[sfnt] Ensure OTTO fonts have tables (#57285).
diff --git a/include/freetype/internal/ftmemory.h b/include/freetype/internal/ftmemory.h
index f0891ae..7a8eeb8 100644
--- a/include/freetype/internal/ftmemory.h
+++ b/include/freetype/internal/ftmemory.h
@@ -57,6 +57,14 @@ FT_BEGIN_HEADER
   /*************************************************************************/
 
 
+  /* The calculation `NULL + n' is undefined in C.  Even if the resulting */
+  /* pointer doesn't get dereferenced, this causes warnings with          */
+  /* sanitizers.                                                          */
+  /*                                                                      */
+  /* We thus provide a macro that should be used if `base' can be NULL.   */
+#define FT_OFFSET( base, count )  ( (base) ? (base) + (count) : NULL )
+
+
   /*
    * C++ refuses to handle statements like p = (void*)anything, with `p' a
    * typed pointer.  Since we don't have a `typeof' operator in standard C++,