Fixed an obvious bug in _checksum_() that isn't triggered by its current use:
"temp" was added to "sum" in the loop, so that some int8 values were taken into account more than once. Cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13431 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,48 +1,21 @@
|
|||||||
//------------------------------------------------------------------------------
|
/*
|
||||||
// Copyright (c) 2001-2002, OpenBeOS
|
* Copyright 2001-2005, Haiku.
|
||||||
//
|
* Distributed under the terms of the MIT License.
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
*
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
* Authors:
|
||||||
// to deal in the Software without restriction, including without limitation
|
* Erik Jaesler ([email protected])
|
||||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
*/
|
||||||
// and/or sell copies of the Software, and to permit persons to whom the
|
|
||||||
// Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in
|
|
||||||
// all copies or substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
//
|
|
||||||
// File Name: MessageUtils.cpp
|
|
||||||
// Author(s): Erik Jaesler <[email protected]>
|
|
||||||
//
|
|
||||||
// Description: Extra messaging utility functions
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Standard Includes -----------------------------------------------------------
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
// System Includes -------------------------------------------------------------
|
/** Extra messaging utility functions */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
#include <ByteOrder.h>
|
#include <ByteOrder.h>
|
||||||
|
|
||||||
// Project Includes ------------------------------------------------------------
|
|
||||||
#include <MessageUtils.h>
|
#include <MessageUtils.h>
|
||||||
|
|
||||||
// Local Includes --------------------------------------------------------------
|
|
||||||
|
|
||||||
// Local Defines ---------------------------------------------------------------
|
uint32
|
||||||
|
_checksum_(const uchar* buf, int32 size)
|
||||||
// Globals ---------------------------------------------------------------------
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
uint32 _checksum_(const uchar* buf, int32 size)
|
|
||||||
{
|
{
|
||||||
uint32 sum = 0;
|
uint32 sum = 0;
|
||||||
uint32 temp = 0;
|
uint32 temp = 0;
|
||||||
@@ -61,17 +34,16 @@ uint32 _checksum_(const uchar* buf, int32 size)
|
|||||||
while (size > 0) {
|
while (size > 0) {
|
||||||
temp = (temp << 8) + *buf++;
|
temp = (temp << 8) + *buf++;
|
||||||
size -= 1;
|
size -= 1;
|
||||||
sum += temp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return sum;
|
return sum + temp;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
namespace BPrivate { // Only putting these here because Be did
|
namespace BPrivate { // Only putting these here because Be did
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
status_t entry_ref_flatten(char* buffer, size_t* size, const entry_ref* ref)
|
status_t
|
||||||
|
entry_ref_flatten(char* buffer, size_t* size, const entry_ref* ref)
|
||||||
{
|
{
|
||||||
memcpy((void*)buffer, (const void*)&ref->device, sizeof (ref->device));
|
memcpy((void*)buffer, (const void*)&ref->device, sizeof (ref->device));
|
||||||
buffer += sizeof (ref->device);
|
buffer += sizeof (ref->device);
|
||||||
@@ -79,8 +51,7 @@ status_t entry_ref_flatten(char* buffer, size_t* size, const entry_ref* ref)
|
|||||||
buffer += sizeof (ref->directory);
|
buffer += sizeof (ref->directory);
|
||||||
|
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
if (ref->name)
|
if (ref->name) {
|
||||||
{
|
|
||||||
len = strlen(ref->name) + 1; // extra for NULL terminator
|
len = strlen(ref->name) + 1; // extra for NULL terminator
|
||||||
memcpy((void*)buffer, (const void*)ref->name, len);
|
memcpy((void*)buffer, (const void*)ref->name, len);
|
||||||
}
|
}
|
||||||
@@ -88,11 +59,12 @@ status_t entry_ref_flatten(char* buffer, size_t* size, const entry_ref* ref)
|
|||||||
*size = sizeof (ref->device) + sizeof (ref->directory) + len;
|
*size = sizeof (ref->device) + sizeof (ref->directory) + len;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
status_t entry_ref_unflatten(entry_ref* ref, const char* buffer, size_t size)
|
|
||||||
|
status_t
|
||||||
|
entry_ref_unflatten(entry_ref* ref, const char* buffer, size_t size)
|
||||||
{
|
{
|
||||||
if (size < (sizeof (ref->device) + sizeof (ref->directory)))
|
if (size < (sizeof (ref->device) + sizeof (ref->directory))) {
|
||||||
{
|
|
||||||
*ref = entry_ref();
|
*ref = entry_ref();
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
}
|
}
|
||||||
@@ -103,30 +75,25 @@ status_t entry_ref_unflatten(entry_ref* ref, const char* buffer, size_t size)
|
|||||||
sizeof (ref->directory));
|
sizeof (ref->directory));
|
||||||
buffer += sizeof (ref->directory);
|
buffer += sizeof (ref->directory);
|
||||||
|
|
||||||
if (ref->device != -1 &&
|
if (ref->device != -1
|
||||||
size > (sizeof (ref->device) + sizeof (ref->directory)))
|
&& size > (sizeof (ref->device) + sizeof (ref->directory))) {
|
||||||
{
|
|
||||||
ref->set_name(buffer);
|
ref->set_name(buffer);
|
||||||
if (ref->name == NULL)
|
if (ref->name == NULL) {
|
||||||
{
|
|
||||||
*ref = entry_ref();
|
*ref = entry_ref();
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
|
||||||
ref->set_name(NULL);
|
ref->set_name(NULL);
|
||||||
}
|
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
status_t entry_ref_swap(char* buffer, size_t size)
|
|
||||||
|
status_t
|
||||||
|
entry_ref_swap(char* buffer, size_t size)
|
||||||
{
|
{
|
||||||
if (size < (sizeof (dev_t) + sizeof (ino_t)))
|
if (size < (sizeof (dev_t) + sizeof (ino_t)))
|
||||||
{
|
|
||||||
return B_BAD_DATA;
|
return B_BAD_DATA;
|
||||||
}
|
|
||||||
|
|
||||||
dev_t* dev = (dev_t*)buffer;
|
dev_t* dev = (dev_t*)buffer;
|
||||||
*dev = B_SWAP_INT32(*dev);
|
*dev = B_SWAP_INT32(*dev);
|
||||||
@@ -137,31 +104,27 @@ status_t entry_ref_swap(char* buffer, size_t size)
|
|||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
size_t calc_padding(size_t size, size_t boundary)
|
|
||||||
|
size_t
|
||||||
|
calc_padding(size_t size, size_t boundary)
|
||||||
{
|
{
|
||||||
size_t pad = size % boundary;
|
size_t pad = size % boundary;
|
||||||
if (pad)
|
if (pad)
|
||||||
{
|
|
||||||
pad = boundary - pad;
|
pad = boundary - pad;
|
||||||
}
|
|
||||||
return pad;
|
return pad;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
} // namespace BPrivate
|
} // namespace BPrivate
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
int32 TChecksumHelper::CheckSum()
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
int32
|
||||||
|
TChecksumHelper::CheckSum()
|
||||||
{
|
{
|
||||||
return _checksum_(fBuffer, fBufPtr - fBuffer);
|
return _checksum_(fBuffer, fBufPtr - fBuffer);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/*
|
|
||||||
* $Log $
|
|
||||||
*
|
|
||||||
* $Id $
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user