summaryrefslogtreecommitdiffstats
path: root/ipc/ipc_channel_posix.cc
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-01 00:50:13 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-01 00:50:13 +0000
commit05094a3fd1209ad3c5fa5c92c78694da589b9448 (patch)
tree59eab02505b51bcff2c1a48ea097de85befbfaef /ipc/ipc_channel_posix.cc
parentd643172a8573e7e75f325bec2125de8071bfd0fc (diff)
downloadchromium_src-05094a3fd1209ad3c5fa5c92c78694da589b9448.zip
chromium_src-05094a3fd1209ad3c5fa5c92c78694da589b9448.tar.gz
chromium_src-05094a3fd1209ad3c5fa5c92c78694da589b9448.tar.bz2
Convert some constants declared as anonymous enums into static consts so they have types. This defines the constants where they're declared to preserve the existing readability as well as allow us to do things like dimension arrays based on the values of the constants.
The drawback to defining constants at their declaration point is that supplying them to a templated function, like what DCHECK_EQ() expands into, triggers an "undefined symbol" error on Mac/Linux (and adding explicit storage for them in the .cc file can cause duplicate symbol errors on Windows). Here I've worked around that by converting DCHECK_EQ(a, b) to DCHECK(b == a). The original motiviation for this change was to find a way to eliminate some cases of passing anonymous-typed values as template arguments (which happens when you use a value from the enum in e.g. EXPECT_EQ()), which is technically illegal in C++03, though we don't warn about it. Simply naming the enum would have done this, but in general naming enums used to declare constants like this is bizarre ("enum Constants { ... }"?). BUG=92247 TEST=Compiles Review URL: http://codereview.chromium.org/7817005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99087 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc/ipc_channel_posix.cc')
-rw-r--r--ipc/ipc_channel_posix.cc11
1 files changed, 5 insertions, 6 deletions
diff --git a/ipc/ipc_channel_posix.cc b/ipc/ipc_channel_posix.cc
index df927d0..a88506c 100644
--- a/ipc/ipc_channel_posix.cc
+++ b/ipc/ipc_channel_posix.cc
@@ -585,8 +585,7 @@ bool Channel::ChannelImpl::ProcessIncomingMessages() {
p = input_buf_;
end = p + bytes_read;
} else {
- if (input_overflow_buf_.size() >
- static_cast<size_t>(kMaximumMessageSize - bytes_read)) {
+ if (input_overflow_buf_.size() > (kMaximumMessageSize - bytes_read)) {
input_overflow_buf_.clear();
LOG(ERROR) << "IPC message is too big";
return false;
@@ -676,7 +675,7 @@ bool Channel::ChannelImpl::ProcessIncomingMessages() {
}
if (header_fds >
- FileDescriptorSet::MAX_DESCRIPTORS_PER_MESSAGE) {
+ FileDescriptorSet::kMaxDescriptorsPerMessage) {
// There are too many descriptors in this message
error = "Message requires an excessive number of descriptors";
}
@@ -782,7 +781,7 @@ bool Channel::ChannelImpl::ProcessOutgoingMessages() {
msgh.msg_iov = &iov;
msgh.msg_iovlen = 1;
char buf[CMSG_SPACE(
- sizeof(int[FileDescriptorSet::MAX_DESCRIPTORS_PER_MESSAGE]))];
+ sizeof(int) * FileDescriptorSet::kMaxDescriptorsPerMessage)];
ssize_t bytes_written = 1;
int fd_written = -1;
@@ -793,7 +792,7 @@ bool Channel::ChannelImpl::ProcessOutgoingMessages() {
struct cmsghdr *cmsg;
const unsigned num_fds = msg->file_descriptor_set()->size();
- DCHECK_LE(num_fds, FileDescriptorSet::MAX_DESCRIPTORS_PER_MESSAGE);
+ DCHECK(num_fds <= FileDescriptorSet::kMaxDescriptorsPerMessage);
if (msg->file_descriptor_set()->ContainsDirectoryDescriptor()) {
LOG(FATAL) << "Panic: attempting to transport directory descriptor over"
" IPC. Aborting to maintain sandbox isolation.";
@@ -815,7 +814,7 @@ bool Channel::ChannelImpl::ProcessOutgoingMessages() {
msgh.msg_controllen = cmsg->cmsg_len;
// DCHECK_LE above already checks that
- // num_fds < MAX_DESCRIPTORS_PER_MESSAGE so no danger of overflow.
+ // num_fds < kMaxDescriptorsPerMessage so no danger of overflow.
msg->header()->num_fds = static_cast<uint16>(num_fds);
#if defined(IPC_USES_READWRITE)