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

Unified Diff: trunk/src/base/base64.cc

Issue 101113004: Revert 239759 "The comment in base64.h implies that base::Base64..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years 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
« no previous file with comments | « trunk/src/base/base64.h ('k') | trunk/src/base/base64_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: trunk/src/base/base64.cc
===================================================================
--- trunk/src/base/base64.cc (revision 239920)
+++ trunk/src/base/base64.cc (working copy)
@@ -8,15 +8,21 @@
namespace base {
-void Base64Encode(const StringPiece& input, std::string* output) {
+bool Base64Encode(const StringPiece& input, std::string* output) {
std::string temp;
temp.resize(modp_b64_encode_len(input.size())); // makes room for null byte
+ // null terminates result since result is base64 text!
+ int input_size = static_cast<int>(input.size());
+
// modp_b64_encode_len() returns at least 1, so temp[0] is safe to use.
- size_t output_size = modp_b64_encode(&(temp[0]), input.data(), input.size());
+ size_t output_size = modp_b64_encode(&(temp[0]), input.data(), input_size);
+ if (output_size == MODP_B64_ERROR)
+ return false;
temp.resize(output_size); // strips off null byte
output->swap(temp);
+ return true;
}
bool Base64Decode(const StringPiece& input, std::string* output) {
« no previous file with comments | « trunk/src/base/base64.h ('k') | trunk/src/base/base64_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698