aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/lib
diff options
context:
space:
mode:
authorGravatar Rachel Lim <rachelim@google.com>2018-06-01 08:52:46 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-06-01 08:55:42 -0700
commit6bb35f848a7164d3f5a696826b9659b1bd24fed0 (patch)
treed86d072b8521620cd73005fb1d7d3afb3d6c481a /tensorflow/core/lib
parent46cd11058d049362b3ec813c7c07193449242eb3 (diff)
Automated g4 rollback of changelist 198815200
PiperOrigin-RevId: 198878259
Diffstat (limited to 'tensorflow/core/lib')
-rw-r--r--tensorflow/core/lib/strings/numbers.cc26
-rw-r--r--tensorflow/core/lib/strings/numbers.h4
2 files changed, 14 insertions, 16 deletions
diff --git a/tensorflow/core/lib/strings/numbers.cc b/tensorflow/core/lib/strings/numbers.cc
index 987e4fe733..87aa5915ff 100644
--- a/tensorflow/core/lib/strings/numbers.cc
+++ b/tensorflow/core/lib/strings/numbers.cc
@@ -331,31 +331,29 @@ bool safe_strtou32(StringPiece str, uint32* value) {
return true;
}
-bool safe_strtof(const char* str, float* value) {
+bool safe_strtof(StringPiece str, float* value) {
int processed_characters_count = -1;
- auto len = str_util::Strnlen(str, kFastToBufferSize);
+ auto len = str.size();
- // If there is no zero-termination in str, fail.
- if (len == kFastToBufferSize) return false;
- // If string length exceeds int max, fail.
+ // If string length exceeds buffer size or int max, fail.
+ if (len >= kFastToBufferSize) return false;
if (len > std::numeric_limits<int>::max()) return false;
- *value = StringToFloatConverter().StringToFloat(str, static_cast<int>(len),
- &processed_characters_count);
+ *value = StringToFloatConverter().StringToFloat(
+ str.data(), static_cast<int>(len), &processed_characters_count);
return processed_characters_count > 0;
}
-bool safe_strtod(const char* str, double* value) {
+bool safe_strtod(StringPiece str, double* value) {
int processed_characters_count = -1;
- auto len = str_util::Strnlen(str, kFastToBufferSize);
+ auto len = str.size();
- // If there is no zero-termination in str, fail.
- if (len == kFastToBufferSize) return false;
- // If string length exceeds int max, fail.
+ // If string length exceeds buffer size or int max, fail.
+ if (len >= kFastToBufferSize) return false;
if (len > std::numeric_limits<int>::max()) return false;
- *value = StringToFloatConverter().StringToDouble(str, static_cast<int>(len),
- &processed_characters_count);
+ *value = StringToFloatConverter().StringToDouble(
+ str.data(), static_cast<int>(len), &processed_characters_count);
return processed_characters_count > 0;
}
diff --git a/tensorflow/core/lib/strings/numbers.h b/tensorflow/core/lib/strings/numbers.h
index 9cb56415cb..1d5bacac93 100644
--- a/tensorflow/core/lib/strings/numbers.h
+++ b/tensorflow/core/lib/strings/numbers.h
@@ -115,13 +115,13 @@ bool safe_strtou64(StringPiece str, uint64* value);
// Leading and trailing spaces are allowed.
// Values may be rounded on over- and underflow.
// Returns false on invalid input or if `strlen(value) >= kFastToBufferSize`.
-bool safe_strtof(const char* str, float* value);
+bool safe_strtof(StringPiece str, float* value);
// Convert strings to double precision floating point values.
// Leading and trailing spaces are allowed.
// Values may be rounded on over- and underflow.
// Returns false on invalid input or if `strlen(value) >= kFastToBufferSize`.
-bool safe_strtod(const char* str, double* value);
+bool safe_strtod(StringPiece str, double* value);
inline bool ProtoParseNumeric(StringPiece s, int32* value) {
return safe_strto32(s, value);