Fixed the implementation of DataTypeString to avoid a stack overflow when
authorBenoit Steiner <bsteiner@google.com>
Thu, 4 Jan 2018 21:42:13 +0000 (13:42 -0800)
committerTensorFlower Gardener <gardener@tensorflow.org>
Thu, 4 Jan 2018 21:45:42 +0000 (13:45 -0800)
processing invalid types

PiperOrigin-RevId: 180839917

tensorflow/core/framework/types.cc

index 58354d6f4edea1f29ba033f2579324d400a532ab..8bc44030945a7adbff447812d2c052f97a091e5f 100644 (file)
@@ -47,11 +47,8 @@ const std::string DeviceName<Eigen::GpuDevice>::value = DEVICE_GPU;
 const std::string DeviceName<Eigen::SyclDevice>::value = DEVICE_SYCL;
 #endif  // TENSORFLOW_USE_SYCL
 
-string DataTypeString(DataType dtype) {
-  if (IsRefType(dtype)) {
-    DataType non_ref = static_cast<DataType>(dtype - kDataTypeRefOffset);
-    return strings::StrCat(DataTypeString(non_ref), "_ref");
-  }
+namespace {
+string DataTypeStringInternal(DataType dtype) {
   switch (dtype) {
     case DT_INVALID:
       return "INVALID";
@@ -106,6 +103,15 @@ string DataTypeString(DataType dtype) {
       return strings::StrCat("unknown dtype enum (", dtype, ")");
   }
 }
+}  // end namespace
+
+string DataTypeString(DataType dtype) {
+  if (IsRefType(dtype)) {
+    DataType non_ref = static_cast<DataType>(dtype - kDataTypeRefOffset);
+    return strings::StrCat(DataTypeStringInternal(non_ref), "_ref");
+  }
+  return DataTypeStringInternal(dtype);
+}
 
 bool DataTypeFromString(StringPiece sp, DataType* dt) {
   if (sp.ends_with("_ref")) {