Strict sign conversions

This commit is contained in:
Pavel Kirienko
2014-08-28 02:51:29 +04:00
parent 4cc7dfb2d4
commit d9d6e80aea
23 changed files with 93 additions and 98 deletions
+6 -6
View File
@@ -540,16 +540,16 @@ public:
{
if (new_size > size())
{
unsigned cnt = new_size - size();
while (cnt--)
SizeType cnt = SizeType(new_size - size());
while (cnt-- > 0)
{
push_back(filler);
}
}
else if (new_size < size())
{
unsigned cnt = size() - new_size;
while (cnt--)
SizeType cnt = SizeType(size() - new_size);
while (cnt-- > 0)
{
pop_back();
}
@@ -623,7 +623,7 @@ public:
}
while (*ch)
{
push_back(*ch++);
push_back(ValueType(*ch++)); // Value type is likely to be unsigned char, so conversion may be required.
}
return *this;
}
@@ -642,7 +642,7 @@ public:
}
while (*ch)
{
push_back(*ch++);
push_back(ValueType(*ch++));
}
return *this;
}
@@ -13,7 +13,8 @@
namespace uavcan
{
void bitarrayCopy(const unsigned char* src_org, int src_offset, int src_len, unsigned char* dst_org, int dst_offset);
void bitarrayCopy(const unsigned char* src_org, unsigned src_offset, unsigned src_len,
unsigned char* dst_org, unsigned dst_offset);
/**
* This class treats a chunk of memory as an array of bits.
@@ -24,13 +25,13 @@ class UAVCAN_EXPORT BitStream
static const unsigned MaxBytesPerRW = 16;
ITransferBuffer& buf_;
int bit_offset_;
unsigned bit_offset_;
uint8_t byte_cache_;
static inline unsigned bitlenToBytelen(unsigned bits) { return (bits + 7) / 8; }
static inline void copyBitArray(const uint8_t* src_org, int src_offset, int src_len,
uint8_t* dst_org, int dst_offset)
static inline void copyBitArray(const uint8_t* src_org, unsigned src_offset, unsigned src_len,
uint8_t* dst_org, unsigned dst_offset)
{
bitarrayCopy(reinterpret_cast<const unsigned char*>(src_org), src_offset, src_len,
reinterpret_cast<unsigned char*>(dst_org), dst_offset);
@@ -64,8 +65,8 @@ public:
* Zero - Out of buffer space
* Positive - OK
*/
int write(const uint8_t* bytes, const int bitlen);
int read(uint8_t* bytes, const int bitlen);
int write(const uint8_t* bytes, const unsigned bitlen);
int read(uint8_t* bytes, const unsigned bitlen);
#if UAVCAN_TOSTRING
std::string toString() const;
@@ -86,7 +86,7 @@ private:
}
}
static void truncate(StorageType& value) { value &= mask(); }
static void truncate(StorageType& value) { value = value & StorageType(mask()); }
static void validate()
{