From e2f04be4830521cc7ac5f70b7e247aa52b2fc76c Mon Sep 17 00:00:00 2001
From: Mihai Maruseac <mihaimaruseac@google.com>
Date: Thu, 16 Apr 2020 16:01:36 -0700
Subject: [PATCH] Allow targets to pass with `-fsanitize=null` under
 `--config=asan`.

PiperOrigin-RevId: 306939167
Change-Id: Ibe3a9a0f627d74bbebf93af8b0badd92e9c5abef
---
 .../core/util/example_proto_fast_parsing.cc   | 27 ++++++++++---------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/tensorflow/core/util/example_proto_fast_parsing.cc b/tensorflow/core/util/example_proto_fast_parsing.cc
index eb50d621b02..b148ffab042 100644
--- a/tensorflow/core/util/example_proto_fast_parsing.cc
+++ b/tensorflow/core/util/example_proto_fast_parsing.cc
@@ -1272,20 +1272,23 @@ Status FastParseExample(const Config& config,
       SparseBuffer& buffer = sparse_buffers[i][d];
 
       // Update indices.
-      int64* ix_p = &indices->matrix<int64>()(offset, 0);
       size_t delta = 0;
-      size_t example_index = first_example_of_minibatch(i);
-      for (size_t example_end_index : buffer.example_end_indices) {
-        size_t feature_index = 0;
-        for (; delta < example_end_index; ++delta) {
-          // Column 0: example index
-          *ix_p = example_index;
-          // Column 1: the feature index buffer example
-          *(ix_p + 1) = feature_index;
-          ix_p += 2;
-          ++feature_index;
+
+      if (indices->NumElements() > 0) {
+        int64* ix_p = &indices->matrix<int64>()(offset, 0);
+        size_t example_index = first_example_of_minibatch(i);
+        for (size_t example_end_index : buffer.example_end_indices) {
+          size_t feature_index = 0;
+          for (; delta < example_end_index; ++delta) {
+            // Column 0: example index
+            *ix_p = example_index;
+            // Column 1: the feature index buffer example
+            *(ix_p + 1) = feature_index;
+            ix_p += 2;
+            ++feature_index;
+          }
+          ++example_index;
         }
-        ++example_index;
       }
 
       CopySparseBufferToTensor(config.sparse[d].dtype, offset, &buffer, values);