Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Unified Diff: net/der/input.h

Issue 1160643002: Remove dangerous std::string constructor for der::Input (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix null-terminated strings bug, and use a static factory method instead of another constructor Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/der/input.h
diff --git a/net/der/input.h b/net/der/input.h
index 6731b0c0600afd22f623141252b7e2b58d413061..9732ce7e258026a185b9976d519228b43b943f9f 100644
--- a/net/der/input.h
+++ b/net/der/input.h
@@ -46,12 +46,18 @@ class NET_EXPORT_PRIVATE Input {
explicit Input(const uint8_t(&data)[N])
: data_(data), len_(N) {}
+ // Creates an Input from a null-terminated constant char array |data|. This is
+ // provided as a factory method instead of a constructor to avoid confusion
+ // with the similar constructor above which takes an array of uint8_t which is
+ // not null terminated.
+ template <size_t N>
+ static Input FromCString(const char(&data)[N]) {
+ return Input(reinterpret_cast<const uint8_t*>(data), N - 1);
+ }
Ryan Sleevi 2015/05/26 18:53:30 Strictly on a STYLE basis, this shouldn't be inter
+
// Creates an Input from the given |data| and |len|.
Input(const uint8_t* data, size_t len);
- // Creates an Input from the given string |s|.
- explicit Input(const std::string& s);
-
// Returns the length in bytes of an Input's data.
size_t Length() const { return len_; }

Powered by Google App Engine
This is Rietveld 408576698