2011-04-08 Siddharth Mathur <siddharth.mathur@nokia.com>
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Apr 2011 19:30:03 +0000 (19:30 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Apr 2011 19:30:03 +0000 (19:30 +0000)
        Reviewed by Martin Robinson.

        [Qt][WK2][Symbian] Remove use of stack arrays with variable size
        https://bugs.webkit.org/show_bug.cgi?id=57877

        For better compiler portability, use new/delete for arrays when size
        isn't known at compile time. Also fix one compiler warning about bitshift
        operations on signed integer
        * Platform/CoreIPC/unix/ConnectionUnix.cpp:
        (CoreIPC::Connection::readyReadHandler):
        (CoreIPC::Connection::sendOutgoingMessage):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@83323 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/Platform/CoreIPC/unix/ConnectionUnix.cpp

index 31f5634..47f6107 100644 (file)
@@ -1,3 +1,17 @@
+2011-04-08  Siddharth Mathur  <siddharth.mathur@nokia.com>
+
+        Reviewed by Martin Robinson.
+
+        [Qt][WK2][Symbian] Remove use of stack arrays with variable size
+        https://bugs.webkit.org/show_bug.cgi?id=57877
+
+        For better compiler portability, use new/delete for arrays when size
+        isn't known at compile time. Also fix one compiler warning about bitshift
+        operations on signed integer
+        * Platform/CoreIPC/unix/ConnectionUnix.cpp:
+        (CoreIPC::Connection::readyReadHandler):
+        (CoreIPC::Connection::sendOutgoingMessage):
+
 2011-04-08  Martin Robinson  <mrobinson@igalia.com>
 
         Reviewed by Xan Lopez.
index 3fc4412..92ffff3 100644 (file)
@@ -53,7 +53,7 @@ static const size_t messageMaxSize = 4096;
 static const size_t attachmentMaxAmount = 255;
 
 enum {
-    MessageBodyIsOOL = 1 << 31
+    MessageBodyIsOOL = 1U << 31
 };
 
 class MessageInfo {
@@ -166,14 +166,14 @@ void Connection::readyReadHandler()
 #endif
     AttachmentResourceGuard<Deque<Attachment>, Deque<Attachment>::iterator> attachementDisposer(attachments);
 
-    char attachmentDescriptorBuffer[CMSG_SPACE(sizeof(int) * (attachmentMaxAmount))];
+    OwnArrayPtr<char> attachmentDescriptorBuffer = adoptArrayPtr(new char[CMSG_SPACE(sizeof(int) * (attachmentMaxAmount))]);
     struct msghdr message;
     memset(&message, 0, sizeof(message));
 
     struct iovec iov[1];
     memset(&iov, 0, sizeof(iov));
 
-    message.msg_control = attachmentDescriptorBuffer;
+    message.msg_control = attachmentDescriptorBuffer.get();
     message.msg_controllen = CMSG_SPACE(sizeof(int) * (attachmentMaxAmount));
 
     iov[0].iov_base = m_readBuffer.data();
@@ -203,13 +203,13 @@ void Connection::readyReadHandler()
 
     if (messageInfo.attachmentCount()) {
         if (controlMessage && controlMessage->cmsg_level == SOL_SOCKET && controlMessage->cmsg_type == SCM_RIGHTS) {
-            size_t attachmentSizes[messageInfo.attachmentCount()];
-            memcpy(attachmentSizes, messageData, sizeof(attachmentSizes));
+            OwnArrayPtr<size_t> attachmentSizes = adoptArrayPtr(new size_t[messageInfo.attachmentCount()]);
+            memcpy(attachmentSizes.get(), messageData, sizeof(size_t) * messageInfo.attachmentCount());
 
             messageData += sizeof(attachmentSizes);
 
-            int fileDescriptors[messageInfo.attachmentCount()];
-            memcpy(fileDescriptors, CMSG_DATA(controlMessage), sizeof(fileDescriptors));
+            OwnArrayPtr<int> fileDescriptors = adoptArrayPtr(new int[messageInfo.attachmentCount()]);
+            memcpy(fileDescriptors.get(), CMSG_DATA(controlMessage), sizeof(int) * messageInfo.attachmentCount());
 
             int attachmentCount = messageInfo.attachmentCount();
 
@@ -350,12 +350,12 @@ bool Connection::sendOutgoingMessage(MessageID messageID, PassOwnPtr<ArgumentEnc
     iov[0].iov_base = reinterpret_cast<void*>(&messageInfo);
     iov[0].iov_len = sizeof(messageInfo);
 
-    char attachmentFDBuffer[CMSG_SPACE(sizeof(int) * (attachments.size()))];
-    size_t attachmentSizes[attachments.size()];
+    OwnArrayPtr<char> attachmentFDBuffer = adoptArrayPtr(new char[CMSG_SPACE(sizeof(int) * attachments.size())]);
+    OwnArrayPtr<size_t> attachmentSizes = adoptArrayPtr(new size_t[attachments.size()]);
 
     if (!attachments.isEmpty()) {
-        message.msg_control = attachmentFDBuffer;
-        message.msg_controllen = sizeof(attachmentFDBuffer);
+        message.msg_control = attachmentFDBuffer.get();
+        message.msg_controllen = sizeof(char) * CMSG_SPACE(sizeof(int) * attachments.size());
 
         struct cmsghdr* cmsg = CMSG_FIRSTHDR(&message);
         cmsg->cmsg_level = SOL_SOCKET;
@@ -370,8 +370,8 @@ bool Connection::sendOutgoingMessage(MessageID messageID, PassOwnPtr<ArgumentEnc
 
         message.msg_controllen = cmsg->cmsg_len;
 
-        iov[iovLength].iov_base = attachmentSizes;
-        iov[iovLength].iov_len = sizeof(attachmentSizes);
+        iov[iovLength].iov_base = attachmentSizes.get();
+        iov[iovLength].iov_len = sizeof(size_t) * attachments.size();
         ++iovLength;
     }