summaryrefslogtreecommitdiffstats
path: root/dbus
diff options
context:
space:
mode:
authorricea <ricea@chromium.org>2015-09-18 15:26:10 -0700
committerCommit bot <commit-bot@chromium.org>2015-09-18 22:26:44 +0000
commit19b947df2525b66bee8fae31de23dba12423703a (patch)
treef81f31add02ce938664438c16680d8cde1d01129 /dbus
parentaa2d8437ba50aeed8d3c104915d6bc3841a277f2 (diff)
downloadchromium_src-19b947df2525b66bee8fae31de23dba12423703a.zip
chromium_src-19b947df2525b66bee8fae31de23dba12423703a.tar.gz
chromium_src-19b947df2525b66bee8fae31de23dba12423703a.tar.bz2
IntToString() signedness fixes for //dbus
Use UintToString() rather than IntToString() for unsigned types, to improve correctness. Also replace some trivial usages of StringPrintf() with the appropriate IntToString() variants, to improve performance, code size and type safety. No behavioural changes are intended. BUG=505479 TEST=dbus_unittests Review URL: https://codereview.chromium.org/1349493004 Cr-Commit-Position: refs/heads/master@{#349785}
Diffstat (limited to 'dbus')
-rw-r--r--dbus/message.cc21
1 files changed, 10 insertions, 11 deletions
diff --git a/dbus/message.cc b/dbus/message.cc
index 3b021e5..0bf76d4 100644
--- a/dbus/message.cc
+++ b/dbus/message.cc
@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "base/format_macros.h"
#include "base/logging.h"
+#include "base/numerics/safe_conversions.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
@@ -38,8 +39,7 @@ void AppendUint32Header(const std::string& header_name,
uint32 header_value,
std::string* output) {
if (header_value != 0) {
- *output += (header_name + ": " + base::StringPrintf("%u", header_value) +
- "\n");
+ *output += (header_name + ": " + base::UintToString(header_value) + "\n");
}
}
@@ -102,7 +102,7 @@ std::string Message::ToStringInternal(const std::string& indent,
uint8 value = 0;
if (!reader->PopByte(&value))
return kBrokenMessage;
- output += indent + "byte " + base::IntToString(value) + "\n";
+ output += indent + "byte " + base::UintToString(value) + "\n";
break;
}
case BOOL: {
@@ -123,7 +123,7 @@ std::string Message::ToStringInternal(const std::string& indent,
uint16 value = 0;
if (!reader->PopUint16(&value))
return kBrokenMessage;
- output += indent + "uint16 " + base::IntToString(value) + "\n";
+ output += indent + "uint16 " + base::UintToString(value) + "\n";
break;
}
case INT32: {
@@ -137,30 +137,28 @@ std::string Message::ToStringInternal(const std::string& indent,
uint32 value = 0;
if (!reader->PopUint32(&value))
return kBrokenMessage;
- output += indent + "uint32 " + base::StringPrintf("%u", value) + "\n";
+ output += indent + "uint32 " + base::UintToString(value) + "\n";
break;
}
case INT64: {
int64 value = 0;
if (!reader->PopInt64(&value))
return kBrokenMessage;
- output += (indent + "int64 " +
- base::StringPrintf("%" PRId64, value) + "\n");
+ output += (indent + "int64 " + base::Int64ToString(value) + "\n");
break;
}
case UINT64: {
uint64 value = 0;
if (!reader->PopUint64(&value))
return kBrokenMessage;
- output += (indent + "uint64 " +
- base::StringPrintf("%" PRIu64, value) + "\n");
+ output += (indent + "uint64 " + base::Uint64ToString(value) + "\n");
break;
}
case DOUBLE: {
double value = 0;
if (!reader->PopDouble(&value))
return kBrokenMessage;
- output += indent + "double " + base::StringPrintf("%f", value) + "\n";
+ output += indent + "double " + base::DoubleToString(value) + "\n";
break;
}
case STRING: {
@@ -696,7 +694,8 @@ void MessageWriter::AppendBasic(int dbus_type, const void* value) {
}
void MessageWriter::AppendVariantOfBasic(int dbus_type, const void* value) {
- const std::string signature = base::StringPrintf("%c", dbus_type);
+ const std::string signature(1u, // length
+ base::checked_cast<char>(dbus_type));
MessageWriter variant_writer(message_);
OpenVariant(signature, &variant_writer);
variant_writer.AppendBasic(dbus_type, value);