Commit 2d1d60aac67e105e6b812aa4ed6448d277f985e2

John Stracke 2019-11-23T10:42:04

[base] Fix `NULL + offset' sanitizer warnings (#57194). * src/base/ftgloadr.c (FT_GlyphLoader_Adjust_Points, FT_GlyphLoader_Adjust_Subglyphs): Use `FT_OFFSET'. (FT_GlyphLoader_CreateExtra): Add short cut if some values are zero.

diff --git a/ChangeLog b/ChangeLog
index 23c3595..7019ab1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2019-11-23  John Stracke  <jstracke@Google.com>
+            Werner Lemberg  <wl@gnu.org>
+
+	[base] Fix `NULL + offset' sanitizer warnings (#57194).
+
+	* src/base/ftgloadr.c (FT_GlyphLoader_Adjust_Points,
+	FT_GlyphLoader_Adjust_Subglyphs): Use `FT_OFFSET'.
+	(FT_GlyphLoader_CreateExtra): Add short cut if some values are zero.
+
 2019-11-23  Werner Lemberg  <wl@gnu.org>
 
 	* include/freetype/internal/ftmemory.h (FT_OFFSET): New macro.
diff --git a/src/base/ftgloadr.c b/src/base/ftgloadr.c
index bfeed46..c076dcc 100644
--- a/src/base/ftgloadr.c
+++ b/src/base/ftgloadr.c
@@ -146,9 +146,9 @@
     FT_Outline*  current = &loader->current.outline;
 
 
-    current->points   = base->points   + base->n_points;
-    current->tags     = base->tags     + base->n_points;
-    current->contours = base->contours + base->n_contours;
+    current->points   = FT_OFFSET( base->points,   base->n_points );
+    current->tags     = FT_OFFSET( base->tags,     base->n_points );
+    current->contours = FT_OFFSET( base->contours, base->n_contours );
 
     /* handle extra points table - if any */
     if ( loader->use_extra )
@@ -169,6 +169,10 @@
     FT_Memory  memory = loader->memory;
 
 
+    if ( loader->max_points == 0           ||
+         loader->base.extra_points != NULL )
+      return FT_Err_Ok;
+
     if ( !FT_NEW_ARRAY( loader->base.extra_points, 2 * loader->max_points ) )
     {
       loader->use_extra          = 1;
@@ -189,7 +193,7 @@
     FT_GlyphLoad  current = &loader->current;
 
 
-    current->subglyphs = base->subglyphs + base->num_subglyphs;
+    current->subglyphs = FT_OFFSET( base->subglyphs, base->num_subglyphs );
   }