[corosync] [PATCH] Perform endian conversion on a local copy

John Thompson thompa26 at gmail.com
Mon Nov 18 00:29:25 UTC 2013


The problem seen was that in a mixed endian environment that had to
retransmit
messages, the message would be received with the msg_count fields already
swapped.

To resolve the problem a local variable is used to store the swapped value.

Signed-off-by: John Thompson <thompa26 at gmail.com>
---
 exec/totempg.c |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/exec/totempg.c b/exec/totempg.c
index fe111b1..fc2c15a 100644
--- a/exec/totempg.c
+++ b/exec/totempg.c
@@ -640,10 +640,12 @@ static void totempg_deliver_fn (

     mcast = (struct totempg_mcast *)msg;
     if (endian_conversion_required) {
-        mcast->msg_count = swab16 (mcast->msg_count);
+        msg_count = swab16 (mcast->msg_count);
+    }
+    else {
+        msg_count = mcast->msg_count;
     }

-    msg_count = mcast->msg_count;
     datasize = sizeof (struct totempg_mcast) +
         msg_count * sizeof (unsigned short);

@@ -652,7 +654,7 @@ static void totempg_deliver_fn (

     msg_lens = (unsigned short *) (header + sizeof (struct totempg_mcast));
     if (endian_conversion_required) {
-        for (i = 0; i < mcast->msg_count; i++) {
+        for (i = 0; i < msg_count; i++) {
             msg_lens[i] = swab16 (msg_lens[i]);
         }
     }
@@ -666,7 +668,7 @@ static void totempg_deliver_fn (
      * then adjust the assembly buffer so we can add the rest of the
      * fragment when it arrives.
      */
-    msg_count = mcast->fragmented ? mcast->msg_count - 1 :
mcast->msg_count;
+    msg_count = mcast->fragmented ? msg_count - 1 : msg_count;
     continuation = mcast->continuation;
     iov_delv.iov_base = (void *)&assembly->data[0];
     iov_delv.iov_len = assembly->index + msg_lens[0];
@@ -724,7 +726,7 @@ static void totempg_deliver_fn (
         /*
          * Message is fragmented, keep around assembly list
          */
-        if (mcast->msg_count > 1) {
+        if (msg_count > 1) {
             memmove (&assembly->data[0],
                 &assembly->data[assembly->index],
                 msg_lens[msg_count]);
-- 
1.7.9.5
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.corosync.org/pipermail/discuss/attachments/20131118/cebd5732/attachment.html>


More information about the discuss mailing list