mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-22 01:40:35 +08:00
Null pointer checks
This commit is contained in:
@@ -37,10 +37,14 @@ class UAVCAN_EXPORT GlobalDataTypeRegistry : Noncopyable
|
|||||||
struct EntryInsertionComparator
|
struct EntryInsertionComparator
|
||||||
{
|
{
|
||||||
const DataTypeID id;
|
const DataTypeID id;
|
||||||
explicit EntryInsertionComparator(Entry* dtd) : id(dtd->descriptor.getID()) { }
|
explicit EntryInsertionComparator(const Entry* dtd)
|
||||||
|
: id((dtd == NULL) ? DataTypeID() : dtd->descriptor.getID())
|
||||||
|
{
|
||||||
|
assert(dtd != NULL);
|
||||||
|
}
|
||||||
bool operator()(const Entry* entry) const
|
bool operator()(const Entry* entry) const
|
||||||
{
|
{
|
||||||
assert(entry);
|
assert(entry != NULL);
|
||||||
return entry->descriptor.getID() > id;
|
return entry->descriptor.getID() > id;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ namespace uavcan
|
|||||||
|
|
||||||
void ScalarCodec::swapByteOrder(uint8_t* const bytes, const unsigned len)
|
void ScalarCodec::swapByteOrder(uint8_t* const bytes, const unsigned len)
|
||||||
{
|
{
|
||||||
|
assert(bytes);
|
||||||
for (int i = 0, j = len - 1; i < j; i++, j--)
|
for (int i = 0, j = len - 1; i < j; i++, j--)
|
||||||
{
|
{
|
||||||
const uint8_t c = bytes[i];
|
const uint8_t c = bytes[i];
|
||||||
@@ -19,6 +20,7 @@ void ScalarCodec::swapByteOrder(uint8_t* const bytes, const unsigned len)
|
|||||||
|
|
||||||
int ScalarCodec::encodeBytesImpl(uint8_t* const bytes, const unsigned bitlen)
|
int ScalarCodec::encodeBytesImpl(uint8_t* const bytes, const unsigned bitlen)
|
||||||
{
|
{
|
||||||
|
assert(bytes);
|
||||||
// Underlying stream class assumes that more significant bits have lower index, so we need to shift some.
|
// Underlying stream class assumes that more significant bits have lower index, so we need to shift some.
|
||||||
if (bitlen % 8)
|
if (bitlen % 8)
|
||||||
{
|
{
|
||||||
@@ -29,6 +31,7 @@ int ScalarCodec::encodeBytesImpl(uint8_t* const bytes, const unsigned bitlen)
|
|||||||
|
|
||||||
int ScalarCodec::decodeBytesImpl(uint8_t* const bytes, const unsigned bitlen)
|
int ScalarCodec::decodeBytesImpl(uint8_t* const bytes, const unsigned bitlen)
|
||||||
{
|
{
|
||||||
|
assert(bytes);
|
||||||
const int read_res = stream_.read(bytes, bitlen);
|
const int read_res = stream_.read(bytes, bitlen);
|
||||||
if (read_res > 0)
|
if (read_res > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user