[haiku-commits] r42281 - haiku/trunk/src/kits/app

  • From: mmlr@xxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 22 Jun 2011 10:47:31 +0200 (CEST)

Author: mmlr
Date: 2011-06-22 10:47:30 +0200 (Wed, 22 Jun 2011)
New Revision: 42281
Changeset: https://dev.haiku-os.org/changeset/42281

Modified:
   haiku/trunk/src/kits/app/Message.cpp
Log:
* Check the no-init case consistently, no need to crash when we failed to
  allocate the header.
* Code style cleanups: 80-char limit, pointer style of recent additions,
  explicit NULL checks, check ports against 0 instead of B_OK, results != B_OK.


Modified: haiku/trunk/src/kits/app/Message.cpp
===================================================================
--- haiku/trunk/src/kits/app/Message.cpp        2011-06-22 05:22:04 UTC (rev 
42280)
+++ haiku/trunk/src/kits/app/Message.cpp        2011-06-22 08:47:30 UTC (rev 
42281)
@@ -196,6 +196,9 @@
        if (fHeader == NULL)
                return *this;
 
+       if (other.fHeader == NULL)
+               return *this;
+
        memcpy(fHeader, other.fHeader, sizeof(message_header));
 
        // Clear some header flags inherited from the original message that 
don't
@@ -207,7 +210,9 @@
 
        if (fHeader->field_count > 0) {
                size_t fieldsSize = fHeader->field_count * sizeof(field_header);
-               fFields = (field_header *)malloc(fieldsSize);
+               if (other.fFields != NULL)
+                       fFields = (field_header *)malloc(fieldsSize);
+
                if (fFields == NULL) {
                        fHeader->field_count = 0;
                        fHeader->data_size = 0;
@@ -216,7 +221,9 @@
        }
 
        if (fHeader->data_size > 0) {
-               fData = (uint8 *)malloc(fHeader->data_size);
+               if (other.fData != NULL)
+                       fData = (uint8 *)malloc(fHeader->data_size);
+
                if (fData == NULL) {
                        fHeader->field_count = 0;
                        free(fFields);
@@ -268,6 +275,9 @@
        if (this == &other)
                return true;
 
+       if (fHeader == NULL)
+               return other.fHeader == NULL;
+
        if (fHeader->field_count != other.fHeader->field_count)
                return false;
 
@@ -290,8 +300,10 @@
                                return false;
                }
 
-               if (otherField->type != field->type || otherField->count != 
field->count)
+               if (otherField->type != field->type
+                       || otherField->count != field->count) {
                        return false;
+               }
 
                uint8 *data = fData + field->offset + field->name_length;
                uint8 *otherData = other.fData + otherField->offset
@@ -341,7 +353,6 @@
        if (initHeader)
                return _InitHeader();
 
-       fHeader = NULL;
        return B_OK;
 }
 
@@ -416,15 +427,18 @@
        type_code *typeFound, int32 *countFound) const
 {
        DEBUG_FUNCTION_ENTER;
+       if (fHeader == NULL)
+               return B_NO_INIT;
+
        if (index < 0 || (uint32)index >= fHeader->field_count)
                return B_BAD_INDEX;
 
        if (typeRequested == B_ANY_TYPE) {
-               if (nameFound)
+               if (nameFound != NULL)
                        *nameFound = (char *)fData + fFields[index].offset;
-               if (typeFound)
+               if (typeFound != NULL)
                        *typeFound = fFields[index].type;
-               if (countFound)
+               if (countFound != NULL)
                        *countFound = fFields[index].count;
                return B_OK;
        }
@@ -436,11 +450,11 @@
                        counter++;
 
                if (counter == index) {
-                       if (nameFound)
+                       if (nameFound != NULL)
                                *nameFound = (char *)fData + field->offset;
-                       if (typeFound)
+                       if (typeFound != NULL)
                                *typeFound = field->type;
-                       if (countFound)
+                       if (countFound != NULL)
                                *countFound = field->count;
                        return B_OK;
                }
@@ -458,17 +472,17 @@
        const
 {
        DEBUG_FUNCTION_ENTER;
-       if (countFound)
+       if (countFound != NULL)
                *countFound = 0;
 
        field_header *field = NULL;
        status_t result = _FindField(name, B_ANY_TYPE, &field);
-       if (result < B_OK || field == NULL)
+       if (result != B_OK)
                return result;
 
-       if (typeFound)
+       if (typeFound != NULL)
                *typeFound = field->type;
-       if (countFound)
+       if (countFound != NULL)
                *countFound = field->count;
 
        return B_OK;
@@ -482,12 +496,12 @@
        DEBUG_FUNCTION_ENTER;
        field_header *field = NULL;
        status_t result = _FindField(name, B_ANY_TYPE, &field);
-       if (result < B_OK || field == NULL)
+       if (result != B_OK)
                return result;
 
-       if (typeFound)
+       if (typeFound != NULL)
                *typeFound = field->type;
-       if (fixedSize)
+       if (fixedSize != NULL)
                *fixedSize = (field->flags & FIELD_FLAG_FIXED_SIZE) != 0;
 
        return B_OK;
@@ -501,14 +515,14 @@
        DEBUG_FUNCTION_ENTER;
        field_header *field = NULL;
        status_t result = _FindField(name, B_ANY_TYPE, &field);
-       if (result < B_OK || field == NULL)
+       if (result != B_OK)
                return result;
 
-       if (typeFound)
+       if (typeFound != NULL)
                *typeFound = field->type;
-       if (countFound)
+       if (countFound != NULL)
                *countFound = field->count;
-       if (fixedSize)
+       if (fixedSize != NULL)
                *fixedSize = (field->flags & FIELD_FLAG_FIXED_SIZE) != 0;
 
        return B_OK;
@@ -519,6 +533,9 @@
 BMessage::CountNames(type_code type) const
 {
        DEBUG_FUNCTION_ENTER;
+       if (fHeader == NULL)
+               return 0;
+
        if (type == B_ANY_TYPE)
                return fHeader->field_count;
 
@@ -537,7 +554,7 @@
 BMessage::IsEmpty() const
 {
        DEBUG_FUNCTION_ENTER;
-       return fHeader->field_count == 0;
+       return fHeader == NULL || fHeader->field_count == 0;
 }
 
 
@@ -567,7 +584,7 @@
 BMessage::IsReply() const
 {
        DEBUG_FUNCTION_ENTER;
-       return (fHeader->flags & MESSAGE_FLAG_IS_REPLY) != 0;
+       return fHeader != NULL && (fHeader->flags & MESSAGE_FLAG_IS_REPLY) != 0;
 }
 
 
@@ -580,7 +597,7 @@
 
 
 void
-BMessage::_PrintToStream(const char* indent) const
+BMessage::_PrintToStream(const char *indent) const
 {
        DEBUG_FUNCTION_ENTER;
 
@@ -730,6 +747,9 @@
        if (oldEntry == NULL || newEntry == NULL)
                return B_BAD_VALUE;
 
+       if (fHeader == NULL)
+               return B_NO_INIT;
+
        if (fHeader->message_area >= 0)
                _CopyForWrite();
 
@@ -755,7 +775,7 @@
                        int32 newLength = strlen(newEntry) + 1;
                        status_t result = _ResizeData(field->offset + 1,
                                newLength - field->name_length);
-                       if (result < B_OK)
+                       if (result != B_OK)
                                return result;
 
                        memcpy(fData + field->offset, newEntry, newLength);
@@ -774,7 +794,8 @@
 BMessage::WasDelivered() const
 {
        DEBUG_FUNCTION_ENTER;
-       return (fHeader->flags & MESSAGE_FLAG_WAS_DELIVERED) != 0;
+       return fHeader != NULL
+               && (fHeader->flags & MESSAGE_FLAG_WAS_DELIVERED) != 0;
 }
 
 
@@ -782,7 +803,8 @@
 BMessage::IsSourceWaiting() const
 {
        DEBUG_FUNCTION_ENTER;
-       return (fHeader->flags & MESSAGE_FLAG_REPLY_REQUIRED) != 0
+       return fHeader != NULL
+               && (fHeader->flags & MESSAGE_FLAG_REPLY_REQUIRED) != 0
                && (fHeader->flags & MESSAGE_FLAG_REPLY_DONE) == 0;
 }
 
@@ -791,7 +813,8 @@
 BMessage::IsSourceRemote() const
 {
        DEBUG_FUNCTION_ENTER;
-       return (fHeader->flags & MESSAGE_FLAG_WAS_DELIVERED) != 0
+       return fHeader != NULL
+               && (fHeader->flags & MESSAGE_FLAG_WAS_DELIVERED) != 0
                && fHeader->reply_team != BPrivate::current_team();
 }
 
@@ -800,14 +823,13 @@
 BMessage::ReturnAddress() const
 {
        DEBUG_FUNCTION_ENTER;
-       if ((fHeader->flags & MESSAGE_FLAG_WAS_DELIVERED) != 0) {
-               BMessenger messenger;
-               BMessenger::Private(messenger).SetTo(fHeader->reply_team,
-                       fHeader->reply_port, fHeader->reply_target);
-               return messenger;
-       }
+       if (fHeader == NULL || (fHeader->flags & MESSAGE_FLAG_WAS_DELIVERED) == 
0)
+               return BMessenger();
 
-       return BMessenger();
+       BMessenger messenger;
+       BMessenger::Private(messenger).SetTo(fHeader->reply_team,
+               fHeader->reply_port, fHeader->reply_target);
+       return messenger;
 }
 
 
@@ -833,7 +855,8 @@
 BMessage::WasDropped() const
 {
        DEBUG_FUNCTION_ENTER;
-       return (fHeader->flags & MESSAGE_FLAG_WAS_DROPPED) != 0;
+       return fHeader != NULL
+               && (fHeader->flags & MESSAGE_FLAG_WAS_DROPPED) != 0;
 }
 
 
@@ -841,7 +864,7 @@
 BMessage::DropPoint(BPoint *offset) const
 {
        DEBUG_FUNCTION_ENTER;
-       if (offset)
+       if (offset != NULL)
                *offset = FindPoint("_drop_offset_");
 
        return FindPoint("_drop_point_");
@@ -870,6 +893,9 @@
 BMessage::SendReply(BMessage *reply, BMessenger replyTo, bigtime_t timeout)
 {
        DEBUG_FUNCTION_ENTER;
+       if (fHeader == NULL)
+               return B_NO_INIT;
+
        BMessenger messenger;
        BMessenger::Private messengerPrivate(messenger);
        messengerPrivate.SetTo(fHeader->reply_team, fHeader->reply_port,
@@ -921,6 +947,9 @@
        bigtime_t sendTimeout, bigtime_t replyTimeout)
 {
        DEBUG_FUNCTION_ENTER;
+       if (fHeader == NULL)
+               return B_NO_INIT;
+
        BMessenger messenger;
        BMessenger::Private messengerPrivate(messenger);
        messengerPrivate.SetTo(fHeader->reply_team, fHeader->reply_port,
@@ -964,6 +993,9 @@
 BMessage::FlattenedSize() const
 {
        DEBUG_FUNCTION_ENTER;
+       if (fHeader == NULL)
+               return B_NO_INIT;
+
        return sizeof(message_header) + fHeader->field_count * 
sizeof(field_header)
                + fHeader->data_size;
 }
@@ -1071,6 +1103,9 @@
 BMessage::_FlattenToArea(message_header **_header) const
 {
        DEBUG_FUNCTION_ENTER;
+       if (fHeader == NULL)
+               return B_NO_INIT;
+
        message_header *header = (message_header 
*)malloc(sizeof(message_header));
        if (header == NULL)
                return B_NO_MEMORY;
@@ -1109,6 +1144,9 @@
 BMessage::_Reference()
 {
        DEBUG_FUNCTION_ENTER;
+       if (fHeader == NULL)
+               return B_NO_INIT;
+
        fHeader->flags &= ~MESSAGE_FLAG_PASS_BY_AREA;
 
        /* if there is no data at all we don't need the area */
@@ -1117,7 +1155,7 @@
 
        area_info areaInfo;
        status_t result = get_area_info(fHeader->message_area, &areaInfo);
-       if (result < B_OK)
+       if (result != B_OK)
                return result;
 
        uint8 *address = (uint8 *)areaInfo.address;
@@ -1132,6 +1170,9 @@
 BMessage::_Dereference()
 {
        DEBUG_FUNCTION_ENTER;
+       if (fHeader == NULL)
+               return B_NO_INIT;
+
        delete_area(fHeader->message_area);
        fHeader->message_area = -1;
        fFields = NULL;
@@ -1144,6 +1185,8 @@
 BMessage::_CopyForWrite()
 {
        DEBUG_FUNCTION_ENTER;
+       if (fHeader == NULL)
+               return B_NO_INIT;
 
        field_header *newFields = NULL;
        uint8 *newData = NULL;
@@ -1181,6 +1224,10 @@
 status_t
 BMessage::_ValidateMessage()
 {
+       DEBUG_FUNCTION_ENTER;
+       if (fHeader == NULL)
+               return B_NO_INIT;
+
        if (fHeader->field_count == 0)
                return B_OK;
 
@@ -1341,7 +1388,7 @@
        DEBUG_FUNCTION_ENTER;
        BMessage message(B_DIRECT_SPECIFIER);
        status_t result = message.AddString(B_PROPERTY_ENTRY, property);
-       if (result < B_OK)
+       if (result != B_OK)
                return result;
 
        return AddSpecifier(&message);
@@ -1354,11 +1401,11 @@
        DEBUG_FUNCTION_ENTER;
        BMessage message(B_INDEX_SPECIFIER);
        status_t result = message.AddString(B_PROPERTY_ENTRY, property);
-       if (result < B_OK)
+       if (result != B_OK)
                return result;
 
        result = message.AddInt32("index", index);
-       if (result < B_OK)
+       if (result != B_OK)
                return result;
 
        return AddSpecifier(&message);
@@ -1374,15 +1421,15 @@
 
        BMessage message(B_RANGE_SPECIFIER);
        status_t result = message.AddString(B_PROPERTY_ENTRY, property);
-       if (result < B_OK)
+       if (result != B_OK)
                return result;
 
        result = message.AddInt32("index", index);
-       if (result < B_OK)
+       if (result != B_OK)
                return result;
 
        result = message.AddInt32("range", range);
-       if (result < B_OK)
+       if (result != B_OK)
                return result;
 
        return AddSpecifier(&message);
@@ -1395,11 +1442,11 @@
        DEBUG_FUNCTION_ENTER;
        BMessage message(B_NAME_SPECIFIER);
        status_t result = message.AddString(B_PROPERTY_ENTRY, property);
-       if (result < B_OK)
+       if (result != B_OK)
                return result;
 
        result = message.AddString(B_PROPERTY_NAME_ENTRY, name);
-       if (result < B_OK)
+       if (result != B_OK)
                return result;
 
        return AddSpecifier(&message);
@@ -1411,7 +1458,7 @@
 {
        DEBUG_FUNCTION_ENTER;
        status_t result = AddMessage(B_SPECIFIER_ENTRY, specifier);
-       if (result < B_OK)
+       if (result != B_OK)
                return result;
 
        fHeader->current_specifier++;
@@ -1430,7 +1477,7 @@
        type_code type;
        int32 count;
        status_t result = GetInfo(B_SPECIFIER_ENTRY, &type, &count);
-       if (result < B_OK)
+       if (result != B_OK)
                return result;
 
        if (index > count)
@@ -1446,6 +1493,8 @@
        const char **property) const
 {
        DEBUG_FUNCTION_ENTER;
+       if (fHeader == NULL)
+               return B_NO_INIT;
 
        if (index != NULL)
                *index = fHeader->current_specifier;
@@ -1456,14 +1505,14 @@
 
        if (specifier) {
                if (FindMessage(B_SPECIFIER_ENTRY, fHeader->current_specifier,
-                       specifier) < B_OK)
+                       specifier) != B_OK)
                        return B_BAD_SCRIPT_SYNTAX;
 
                if (_what != NULL)
                        *_what = specifier->what;
 
                if (property) {
-                       if (specifier->FindString(B_PROPERTY_ENTRY, property) < 
B_OK)
+                       if (specifier->FindString(B_PROPERTY_ENTRY, property) 
!= B_OK)
                                return B_BAD_SCRIPT_SYNTAX;
                }
        }
@@ -1476,7 +1525,8 @@
 BMessage::HasSpecifiers() const
 {
        DEBUG_FUNCTION_ENTER;
-       return (fHeader->flags & MESSAGE_FLAG_HAS_SPECIFIERS) != 0;
+       return fHeader != NULL
+               && (fHeader->flags & MESSAGE_FLAG_HAS_SPECIFIERS) != 0;
 }
 
 
@@ -1484,6 +1534,9 @@
 BMessage::PopSpecifier()
 {
        DEBUG_FUNCTION_ENTER;
+       if (fHeader == NULL)
+               return B_NO_INIT;
+
        if (fHeader->current_specifier < 0 ||
                (fHeader->flags & MESSAGE_FLAG_WAS_DELIVERED) == 0)
                return B_BAD_VALUE;
@@ -1582,12 +1635,16 @@
 
 
 status_t
-BMessage::_FindField(const char *name, type_code type, field_header **result) 
const
+BMessage::_FindField(const char *name, type_code type, field_header **result)
+       const
 {
        if (name == NULL)
                return B_BAD_VALUE;
 
-       if (fHeader == NULL || fFields == NULL || fData == NULL)
+       if (fHeader == NULL)
+               return B_NO_INIT;
+
+       if (fHeader->field_count == 0 || fFields == NULL || fData == NULL)
                return B_NAME_NOT_FOUND;
 
        uint32 hash = _HashName(name) % fHeader->hash_table_size;
@@ -1619,7 +1676,7 @@
        field_header **result)
 {
        if (fHeader == NULL)
-               return B_ERROR;
+               return B_NO_INIT;
 
        if (fFieldsAvailable <= 0) {
                uint32 count = fHeader->field_count * 2 + 1;
@@ -1648,7 +1705,7 @@
        field->offset = fHeader->data_size;
        field->name_length = strlen(name) + 1;
        status_t status = _ResizeData(field->offset, field->name_length);
-       if (status < B_OK)
+       if (status != B_OK)
                return status;
 
        memcpy(fData + field->offset, name, field->name_length);
@@ -1668,7 +1725,7 @@
 {
        status_t result = _ResizeData(field->offset, -(field->data_size
                + field->name_length));
-       if (result < B_OK)
+       if (result != B_OK)
                return result;
 
        int32 index = ((uint8 *)field - (uint8 *)fFields) / 
sizeof(field_header);
@@ -1725,6 +1782,9 @@
        if (numBytes <= 0 || data == NULL)
                return B_BAD_VALUE;
 
+       if (fHeader == NULL)
+               return B_NO_INIT;
+
        if (fHeader->message_area >= 0)
                _CopyForWrite();
 
@@ -1733,7 +1793,7 @@
        if (result == B_NAME_NOT_FOUND)
                result = _AddField(name, type, isFixedSize, &field);
 
-       if (result < B_OK)
+       if (result != B_OK)
                return result;
 
        if (field == NULL)
@@ -1748,7 +1808,7 @@
                }
 
                result = _ResizeData(offset, numBytes);
-               if (result < B_OK) {
+               if (result != B_OK) {
                        if (field->count == 0)
                                _RemoveField(field);
                        return result;
@@ -1759,7 +1819,7 @@
        } else {
                int32 change = numBytes + sizeof(uint32);
                result = _ResizeData(offset, change);
-               if (result < B_OK) {
+               if (result != B_OK) {
                        if (field->count == 0)
                                _RemoveField(field);
                        return result;
@@ -1783,18 +1843,17 @@
        if (index < 0)
                return B_BAD_INDEX;
 
+       if (fHeader == NULL)
+               return B_NO_INIT;
+
        if (fHeader->message_area >= 0)
                _CopyForWrite();
 
        field_header *field = NULL;
        status_t result = _FindField(name, B_ANY_TYPE, &field);
-
-       if (result < B_OK)
+       if (result != B_OK)
                return result;
 
-       if (field == NULL)
-               return B_ERROR;
-
        if ((uint32)index >= field->count)
                return B_BAD_INDEX;
 
@@ -1805,7 +1864,7 @@
        if ((field->flags & FIELD_FLAG_FIXED_SIZE) != 0) {
                ssize_t size = field->data_size / field->count;
                result = _ResizeData(offset + index * size, -size);
-               if (result < B_OK)
+               if (result != B_OK)
                        return result;
 
                field->data_size -= size;
@@ -1818,7 +1877,7 @@
 
                size_t currentSize = *(uint32 *)pointer + sizeof(uint32);
                result = _ResizeData(offset, -currentSize);
-               if (result < B_OK)
+               if (result != B_OK)
                        return result;
 
                field->data_size -= currentSize;
@@ -1833,18 +1892,17 @@
 BMessage::RemoveName(const char *name)
 {
        DEBUG_FUNCTION_ENTER;
+       if (fHeader == NULL)
+               return B_NO_INIT;
+
        if (fHeader->message_area >= 0)
                _CopyForWrite();
 
        field_header *field = NULL;
        status_t result = _FindField(name, B_ANY_TYPE, &field);
-
-       if (result < B_OK)
+       if (result != B_OK)
                return result;
 
-       if (field == NULL)
-               return B_ERROR;
-
        return _RemoveField(field);
 }
 
@@ -1854,8 +1912,7 @@
 {
        DEBUG_FUNCTION_ENTER;
        _Clear();
-       _InitHeader();
-       return B_OK;
+       return _InitHeader();
 }
 
 
@@ -1870,13 +1927,9 @@
        *data = NULL;
        field_header *field = NULL;
        status_t result = _FindField(name, type, &field);
-
-       if (result < B_OK)
+       if (result != B_OK)
                return result;
 
-       if (field == NULL)
-               return B_ERROR;
-
        if (index < 0 || (uint32)index >= field->count)
                return B_BAD_INDEX;
 
@@ -1909,13 +1962,9 @@
 
        field_header *field = NULL;
        status_t result = _FindField(name, type, &field);
-
-       if (result < B_OK)
+       if (result != B_OK)
                return result;
 
-       if (field == NULL)
-               return B_ERROR;
-
        if (index < 0 || (uint32)index >= field->count)
                return B_BAD_INDEX;
 
@@ -1941,7 +1990,7 @@
                size_t currentSize = *(uint32 *)pointer;
                int32 change = numBytes - currentSize;
                result = _ResizeData(offset, change);
-               if (result < B_OK)
+               if (result != B_OK)
                        return result;
 
                uint32 newSize = (uint32)numBytes;
@@ -1960,13 +2009,9 @@
        DEBUG_FUNCTION_ENTER;
        field_header *field = NULL;
        status_t result = _FindField(name, type, &field);
-
-       if (result < B_OK)
+       if (result != B_OK)
                return false;
 
-       if (field == NULL)
-               return false;
-
        if (index < 0 || (uint32)index >= field->count)
                return false;
 
@@ -2061,14 +2106,14 @@
        status_t result = B_OK;
 
        BPrivate::BDirectMessageTarget* direct = NULL;
-       BMessage* copy = NULL;
+       BMessage *copy = NULL;
        if (portOwner == BPrivate::current_team())
                BPrivate::gDefaultTokens.AcquireHandlerTarget(token, &direct);
 
        if (direct != NULL) {
-               // We have a direct local message target - we can just enqueue 
the message
-               // in its message queue. This will also prevent possible 
deadlocks when the
-               // queue is full.
+               // We have a direct local message target - we can just enqueue 
the
+               // message in its message queue. This will also prevent possible
+               // deadlocks when the queue is full.
                copy = new BMessage(*this);
                if (copy != NULL) {
                        header = copy->fHeader;
@@ -2119,7 +2164,7 @@
                        return B_NO_MEMORY;
 
                result = Flatten(buffer, size);
-               if (result < B_OK) {
+               if (result != B_OK) {
                        free(buffer);
                        return result;
                }
@@ -2177,7 +2222,8 @@
                // this is a local message transmission
                direct->AddMessage(copy);
                if (direct->Queue()->IsNextMessage(copy) && port_count(port) <= 
0) {
-                       // there is currently no message waiting, and we need 
to wakeup the looper
+                       // there is currently no message waiting, and we need 
to wakeup the
+                       // looper
                        write_port_etc(port, 0, NULL, 0, B_RELATIVE_TIMEOUT, 0);
                }
                direct->Release();
@@ -2206,10 +2252,10 @@
        port_id replyPort = B_BAD_PORT_ID;
        status_t result = B_OK;
 
-       if (cachedReplyPort < B_OK) {
+       if (cachedReplyPort < 0) {
                // All the cached reply ports are in use; create a new one
                replyPort = create_port(1 /* for one message */, 
"tmp_reply_port");
-               if (replyPort < B_OK)
+               if (replyPort < 0)
                        return replyPort;
        } else {
                assert(cachedReplyPort < sNumReplyPorts);
@@ -2222,14 +2268,14 @@
        else {
                port_info portInfo;
                result = get_port_info(replyPort, &portInfo);
-               if (result < B_OK)
+               if (result != B_OK)
                        goto error;
 
                team = portInfo.team;
        }
 
        result = set_port_owner(replyPort, portOwner);
-       if (result < B_OK)
+       if (result != B_OK)
                goto error;
 
        // tests if the queue of the reply port is really empty
@@ -2272,17 +2318,18 @@
                BMessenger replyTarget;
                BMessenger::Private(replyTarget).SetTo(team, replyPort,
                        B_PREFERRED_TOKEN);
-               // TODO: replying could also use a BDirectMessageTarget like 
mechanism for local targets
+               // TODO: replying could also use a BDirectMessageTarget like 
mechanism
+               // for local targets
                result = _SendMessage(port, -1, token, sendTimeout, true,
                        replyTarget);
        }
 
-       if (result < B_OK)
+       if (result != B_OK)
                goto error;
 
        int32 code;
        result = handle_reply(replyPort, &code, replyTimeout, reply);
-       if (result < B_OK && cachedReplyPort >= 0) {
+       if (result != B_OK && cachedReplyPort >= 0) {
                delete_port(replyPort);
                sReplyPorts[cachedReplyPort] = create_port(1, "tmp_rport");
        }
@@ -2311,7 +2358,8 @@
 
        uint32 magic = *(uint32 *)data;
 
-       if (magic == MESSAGE_FORMAT_HAIKU || magic == 
MESSAGE_FORMAT_HAIKU_SWAPPED) {
+       if (magic == MESSAGE_FORMAT_HAIKU
+               || magic == MESSAGE_FORMAT_HAIKU_SWAPPED) {
                message_header *header = (message_header *)data;
                header->target = token;
                header->flags |= MESSAGE_FLAG_WAS_DELIVERED;
@@ -2321,7 +2369,8 @@
                        + sizeof(ssize_t) /* flattenedSize */ + sizeof(int32) 
/* what */
                        + sizeof(uint8) /* flags */;
                *(int32 *)header = token;
-       } else if (((KMessage::Header *)data)->magic == 
KMessage::kMessageHeaderMagic) {
+       } else if (((KMessage::Header *)data)->magic
+                       == KMessage::kMessageHeaderMagic) {
                KMessage::Header *header = (KMessage::Header *)data;
                header->targetToken = token;
        } else {
@@ -2460,9 +2509,9 @@
 #undef DEFINE_LAZY_FIND_FUNCTION
 
 status_t
-BMessage::AddAlignment(const char* name, const BAlignment& alignment)
+BMessage::AddAlignment(const char *name, const BAlignment &alignment)
 {
-       int32 data[2] = {alignment.horizontal, alignment.vertical};
+       int32 data[2] = { alignment.horizontal, alignment.vertical };
        return AddData(name, B_ALIGNMENT_TYPE, data, sizeof(data));
 }
 
@@ -2470,14 +2519,16 @@
 status_t
 BMessage::AddString(const char *name, const char *string)
 {
-       return AddData(name, B_STRING_TYPE, string, string ? strlen(string) + 1 
: 0, false);
+       return AddData(name, B_STRING_TYPE, string, string ? strlen(string) + 1 
: 0,
+               false);
 }
 
 
 status_t
 BMessage::AddString(const char *name, const BString &string)
 {
-       return AddData(name, B_STRING_TYPE, string.String(), string.Length() + 
1, false);
+       return AddData(name, B_STRING_TYPE, string.String(), string.Length() + 
1,
+               false);
 }
 
 
@@ -2523,7 +2574,7 @@
        char stackBuffer[16384];
        ssize_t size = message->FlattenedSize();
 
-       char* buffer;
+       char *buffer;
        if (size > (ssize_t)sizeof(stackBuffer)) {
                buffer = (char *)malloc(size);
                if (buffer == NULL)
@@ -2552,7 +2603,7 @@
        char stackBuffer[16384];
        ssize_t size = object->FlattenedSize();
 
-       char* buffer;
+       char *buffer;
        if (size > (ssize_t)sizeof(stackBuffer)) {
                buffer = (char *)malloc(size);
                if (buffer == NULL)
@@ -2573,20 +2624,20 @@
 
 
 status_t
-BMessage::FindAlignment(const char* name, BAlignment* alignment) const
+BMessage::FindAlignment(const char *name, BAlignment *alignment) const
 {
        return FindAlignment(name, 0, alignment);
 }
 
 
 status_t
-BMessage::FindAlignment(const char* name, int32 index,
-       BAlignment* alignment) const
+BMessage::FindAlignment(const char *name, int32 index, BAlignment *alignment)
+       const
 {
        if (!alignment)
                return B_BAD_VALUE;
 
-       int32* data;
+       int32 *data;
        ssize_t bytes;
 
        status_t err = FindData(name, B_ALIGNMENT_TYPE, index,
@@ -2784,7 +2835,7 @@
 
 
 status_t
-BMessage::ReplaceAlignment(const char* name, const BAlignment& alignment)
+BMessage::ReplaceAlignment(const char *name, const BAlignment &alignment)
 {
        int32 data[2] = {alignment.horizontal, alignment.vertical};
        return ReplaceData(name, B_ALIGNMENT_TYPE, 0, data, sizeof(data));
@@ -2792,8 +2843,8 @@
 
 
 status_t
-BMessage::ReplaceAlignment(const char* name, int32 index,
-       const BAlignment& alignment)
+BMessage::ReplaceAlignment(const char *name, int32 index,
+       const BAlignment &alignment)
 {
        int32 data[2] = {alignment.horizontal, alignment.vertical};
        return ReplaceData(name, B_ALIGNMENT_TYPE, index, data, sizeof(data));


Other related posts:

  • » [haiku-commits] r42281 - haiku/trunk/src/kits/app - mmlr