Added -Wzero-as-null-pointer-constant, replaced NULL --> UAVCAN_NULLPTR. All changes are automatic, no manual edits to the library code.

This commit is contained in:
Pavel Kirienko
2016-07-29 15:39:24 +03:00
parent b6fa34fed5
commit 38a241a90a
69 changed files with 306 additions and 274 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ int GenericPublisherBase::doInit(DataTypeKind dtkind, const char* dtname, CanTxQ
GlobalDataTypeRegistry::instance().freeze();
const DataTypeDescriptor* const descr = GlobalDataTypeRegistry::instance().find(dtkind, dtname);
if (descr == NULL)
if (descr == UAVCAN_NULLPTR)
{
UAVCAN_TRACE("GenericPublisher", "Type [%s] is not registered", dtname);
return -ErrUnknownDataType;
+2 -2
View File
@@ -10,7 +10,7 @@ namespace uavcan
int GenericSubscriberBase::genericStart(TransferListener* listener,
bool (Dispatcher::*registration_method)(TransferListener*))
{
if (listener == NULL)
if (listener == UAVCAN_NULLPTR)
{
UAVCAN_ASSERT(0);
return -ErrLogic;
@@ -26,7 +26,7 @@ int GenericSubscriberBase::genericStart(TransferListener* listener,
void GenericSubscriberBase::stop(TransferListener* listener)
{
if (listener != NULL)
if (listener != UAVCAN_NULLPTR)
{
node_.getDispatcher().unregisterMessageListener(listener);
node_.getDispatcher().unregisterServiceRequestListener(listener);
@@ -23,7 +23,7 @@ GlobalDataTypeRegistry::List* GlobalDataTypeRegistry::selectList(DataTypeKind ki
else
{
UAVCAN_ASSERT(0);
return NULL;
return UAVCAN_NULLPTR;
}
}
@@ -144,7 +144,7 @@ void GlobalDataTypeRegistry::freeze()
const DataTypeDescriptor* GlobalDataTypeRegistry::find(const char* name) const
{
const DataTypeDescriptor* desc = find(DataTypeKindMessage, name);
if (desc == NULL)
if (desc == UAVCAN_NULLPTR)
{
desc = find(DataTypeKindService, name);
}
@@ -156,13 +156,13 @@ const DataTypeDescriptor* GlobalDataTypeRegistry::find(DataTypeKind kind, const
if (!name)
{
UAVCAN_ASSERT(0);
return NULL;
return UAVCAN_NULLPTR;
}
const List* list = selectList(kind);
if (!list)
{
UAVCAN_ASSERT(0);
return NULL;
return UAVCAN_NULLPTR;
}
Entry* p = list->get();
while (p)
@@ -173,7 +173,7 @@ const DataTypeDescriptor* GlobalDataTypeRegistry::find(DataTypeKind kind, const
}
p = p->getNextListNode();
}
return NULL;
return UAVCAN_NULLPTR;
}
const DataTypeDescriptor* GlobalDataTypeRegistry::find(DataTypeKind kind, DataTypeID dtid) const
@@ -182,7 +182,7 @@ const DataTypeDescriptor* GlobalDataTypeRegistry::find(DataTypeKind kind, DataTy
if (!list)
{
UAVCAN_ASSERT(0);
return NULL;
return UAVCAN_NULLPTR;
}
Entry* p = list->get();
while (p)
@@ -193,7 +193,7 @@ const DataTypeDescriptor* GlobalDataTypeRegistry::find(DataTypeKind kind, DataTy
}
p = p->getNextListNode();
}
return NULL;
return UAVCAN_NULLPTR;
}
}
+4 -4
View File
@@ -13,7 +13,7 @@ void ServiceClientBase::CallState::handleDeadline(MonotonicTime)
{
UAVCAN_TRACE("ServiceClient::CallState", "Timeout from nid=%d, tid=%d, dtname=%s",
int(id_.server_node_id.get()), int(id_.transfer_id.get()),
(owner_.data_type_descriptor_ == NULL) ? "???" : owner_.data_type_descriptor_->getFullName());
(owner_.data_type_descriptor_ == UAVCAN_NULLPTR) ? "???" : owner_.data_type_descriptor_->getFullName());
/*
* What we're doing here is relaying execution from this call stack to a different one.
* We need it because call registry cannot release memory from this callback, because this will destroy the
@@ -46,18 +46,18 @@ int ServiceClientBase::prepareToCall(INode& node,
/*
* Determining the Data Type ID
*/
if (data_type_descriptor_ == NULL)
if (data_type_descriptor_ == UAVCAN_NULLPTR)
{
GlobalDataTypeRegistry::instance().freeze();
data_type_descriptor_ = GlobalDataTypeRegistry::instance().find(DataTypeKindService, dtname);
if (data_type_descriptor_ == NULL)
if (data_type_descriptor_ == UAVCAN_NULLPTR)
{
UAVCAN_TRACE("ServiceClient", "Type [%s] is not registered", dtname);
return -ErrUnknownDataType;
}
UAVCAN_TRACE("ServiceClient", "Data type descriptor inited: %s", data_type_descriptor_->toString().c_str());
}
UAVCAN_ASSERT(data_type_descriptor_ != NULL);
UAVCAN_ASSERT(data_type_descriptor_ != UAVCAN_NULLPTR);
/*
* Determining the Transfer ID
@@ -23,7 +23,7 @@ int16_t CanAcceptanceFilterConfigurator::loadInputConfiguration(AnonymousMessage
CanFilterConfig anon_frame_cfg;
anon_frame_cfg.id = DefaultAnonMsgID | CanFrame::FlagEFF;
anon_frame_cfg.mask = DefaultAnonMsgMask | CanFrame::FlagEFF | CanFrame::FlagRTR | CanFrame::FlagERR;
if (multiset_configs_.emplace(anon_frame_cfg) == NULL)
if (multiset_configs_.emplace(anon_frame_cfg) == UAVCAN_NULLPTR)
{
return -ErrMemory;
}
@@ -33,18 +33,18 @@ int16_t CanAcceptanceFilterConfigurator::loadInputConfiguration(AnonymousMessage
service_cfg.id = DefaultFilterServiceID;
service_cfg.id |= (static_cast<uint32_t>(node_.getNodeID().get()) << 8) | CanFrame::FlagEFF;
service_cfg.mask = DefaultFilterServiceMask | CanFrame::FlagEFF | CanFrame::FlagRTR | CanFrame::FlagERR;
if (multiset_configs_.emplace(service_cfg) == NULL)
if (multiset_configs_.emplace(service_cfg) == UAVCAN_NULLPTR)
{
return -ErrMemory;
}
const TransferListener* p = node_.getDispatcher().getListOfMessageListeners().get();
while (p != NULL)
while (p != UAVCAN_NULLPTR)
{
CanFilterConfig cfg;
cfg.id = (static_cast<uint32_t>(p->getDataTypeDescriptor().getID().get()) << 8) | CanFrame::FlagEFF;
cfg.mask = DefaultFilterMsgMask | CanFrame::FlagEFF | CanFrame::FlagRTR | CanFrame::FlagERR;
if (multiset_configs_.emplace(cfg) == NULL)
if (multiset_configs_.emplace(cfg) == UAVCAN_NULLPTR)
{
return -ErrMemory;
}
@@ -149,7 +149,7 @@ int CanAcceptanceFilterConfigurator::applyConfiguration(void)
for (uint8_t i = 0; i < node_.getDispatcher().getCanIOManager().getNumIfaces(); i++)
{
ICanIface* iface = can_driver.getIface(i);
if (iface == NULL)
if (iface == UAVCAN_NULLPTR)
{
UAVCAN_TRACE("CanAcceptanceFilter", "Failed to apply HW filter configuration");
return -ErrDriver;
@@ -202,7 +202,7 @@ uint16_t CanAcceptanceFilterConfigurator::getNumFilters() const
for (uint8_t i = 0; i < node_.getDispatcher().getCanIOManager().getNumIfaces(); i++)
{
const ICanIface* iface = can_driver.getIface(i);
if (iface == NULL)
if (iface == UAVCAN_NULLPTR)
{
UAVCAN_ASSERT(0);
out = 0;
@@ -226,7 +226,7 @@ uint16_t CanAcceptanceFilterConfigurator::getNumFilters() const
int CanAcceptanceFilterConfigurator::addFilterConfig(const CanFilterConfig& config)
{
if (multiset_configs_.emplace<const CanFilterConfig&>(config) == NULL)
if (multiset_configs_.emplace<const CanFilterConfig&>(config) == UAVCAN_NULLPTR)
{
return -ErrMemory;
}
+14 -14
View File
@@ -30,11 +30,11 @@ std::string CanRxFrame::toString(StringRepresentation mode) const
*/
void CanTxQueue::Entry::destroy(Entry*& obj, IPoolAllocator& allocator)
{
if (obj != NULL)
if (obj != UAVCAN_NULLPTR)
{
obj->~Entry();
allocator.deallocate(obj);
obj = NULL;
obj = UAVCAN_NULLPTR;
}
}
@@ -117,7 +117,7 @@ void CanTxQueue::push(const CanFrame& frame, MonotonicTime tx_deadline, Qos qos,
}
void* praw = allocator_.allocate(sizeof(Entry));
if (praw == NULL)
if (praw == UAVCAN_NULLPTR)
{
UAVCAN_TRACE("CanTxQueue", "Push OOM #1, cleanup");
// No memory left in the pool, so we try to remove expired frames
@@ -136,14 +136,14 @@ void CanTxQueue::push(const CanFrame& frame, MonotonicTime tx_deadline, Qos qos,
praw = allocator_.allocate(sizeof(Entry)); // Try again
}
if (praw == NULL)
if (praw == UAVCAN_NULLPTR)
{
UAVCAN_TRACE("CanTxQueue", "Push OOM #2, QoS arbitration");
registerRejectedFrame();
// Find a frame with lowest QoS
Entry* p = queue_.get();
if (p == NULL)
if (p == UAVCAN_NULLPTR)
{
UAVCAN_TRACE("CanTxQueue", "Push rejected: Nothing to replace");
return;
@@ -168,7 +168,7 @@ void CanTxQueue::push(const CanFrame& frame, MonotonicTime tx_deadline, Qos qos,
praw = allocator_.allocate(sizeof(Entry)); // Try again
}
if (praw == NULL)
if (praw == UAVCAN_NULLPTR)
{
return; // Seems that there is no memory at all.
}
@@ -196,12 +196,12 @@ CanTxQueue::Entry* CanTxQueue::peek()
return p;
}
}
return NULL;
return UAVCAN_NULLPTR;
}
void CanTxQueue::remove(Entry*& entry)
{
if (entry == NULL)
if (entry == UAVCAN_NULLPTR)
{
UAVCAN_ASSERT(0);
return;
@@ -212,13 +212,13 @@ void CanTxQueue::remove(Entry*& entry)
const CanFrame* CanTxQueue::getTopPriorityPendingFrame() const
{
return (queue_.get() == NULL) ? NULL : &queue_.get()->frame;
return (queue_.get() == UAVCAN_NULLPTR) ? UAVCAN_NULLPTR : &queue_.get()->frame;
}
bool CanTxQueue::topPriorityHigherOrEqual(const CanFrame& rhs_frame) const
{
const Entry* entry = queue_.get();
if (entry == NULL)
if (entry == UAVCAN_NULLPTR)
{
return false;
}
@@ -232,7 +232,7 @@ int CanIOManager::sendToIface(uint8_t iface_index, const CanFrame& frame, Monoto
{
UAVCAN_ASSERT(iface_index < MaxCanIfaces);
ICanIface* const iface = driver_.getIface(iface_index);
if (iface == NULL)
if (iface == UAVCAN_NULLPTR)
{
UAVCAN_ASSERT(0); // Nonexistent interface
return -ErrLogic;
@@ -254,7 +254,7 @@ int CanIOManager::sendFromTxQueue(uint8_t iface_index)
{
UAVCAN_ASSERT(iface_index < MaxCanIfaces);
CanTxQueue::Entry* entry = tx_queues_[iface_index]->peek();
if (entry == NULL)
if (entry == UAVCAN_NULLPTR)
{
return 0;
}
@@ -323,7 +323,7 @@ uint8_t CanIOManager::makePendingTxMask() const
CanIfacePerfCounters CanIOManager::getIfacePerfCounters(uint8_t iface_index) const
{
ICanIface* const iface = driver_.getIface(iface_index);
if (iface == NULL || iface_index >= MaxCanIfaces)
if (iface == UAVCAN_NULLPTR || iface_index >= MaxCanIfaces)
{
UAVCAN_ASSERT(0);
return CanIfacePerfCounters();
@@ -475,7 +475,7 @@ int CanIOManager::receive(CanRxFrame& out_frame, MonotonicTime blocking_deadline
if (masks.read & (1 << i))
{
ICanIface* const iface = driver_.getIface(i);
if (iface == NULL)
if (iface == UAVCAN_NULLPTR)
{
UAVCAN_ASSERT(0); // Nonexistent interface
continue;
+1 -1
View File
@@ -211,7 +211,7 @@ void Dispatcher::handleLoopbackFrame(const CanRxFrame& can_frame)
void Dispatcher::notifyRxFrameListener(const CanRxFrame& can_frame, CanIOFlags flags)
{
if (rx_listener_ != NULL)
if (rx_listener_ != UAVCAN_NULLPTR)
{
rx_listener_->handleRxFrame(can_frame, flags);
}
+1 -1
View File
@@ -157,7 +157,7 @@ bool Frame::compile(CanFrame& out_can_frame) const
tail |= (1U << 5);
}
UAVCAN_ASSERT(payload_len_ < sizeof(static_cast<CanFrame*>(NULL)->data));
UAVCAN_ASSERT(payload_len_ < sizeof(static_cast<CanFrame*>(UAVCAN_NULLPTR)->data));
out_can_frame.dlc = static_cast<uint8_t>(payload_len_);
(void)copy(payload_, payload_ + payload_len_, out_can_frame.data);
@@ -29,12 +29,12 @@ TransferID* OutgoingTransferRegistry::accessOrCreate(const OutgoingTransferRegis
{
UAVCAN_ASSERT(!new_deadline.isZero());
Value* p = map_.access(key);
if (p == NULL)
if (p == UAVCAN_NULLPTR)
{
p = map_.insert(key, Value());
if (p == NULL)
if (p == UAVCAN_NULLPTR)
{
return NULL;
return UAVCAN_NULLPTR;
}
UAVCAN_TRACE("OutgoingTransferRegistry", "Created %s", key.toString().c_str());
}
@@ -44,7 +44,7 @@ TransferID* OutgoingTransferRegistry::accessOrCreate(const OutgoingTransferRegis
bool OutgoingTransferRegistry::exists(DataTypeID dtid, TransferType tt) const
{
return NULL != map_.find(ExistenceCheckingPredicate(dtid, tt));
return UAVCAN_NULLPTR != map_.find(ExistenceCheckingPredicate(dtid, tt));
}
void OutgoingTransferRegistry::cleanup(MonotonicTime ts)
+21 -21
View File
@@ -79,20 +79,20 @@ TransferBufferManagerEntry::Block*
TransferBufferManagerEntry::Block::instantiate(IPoolAllocator& allocator)
{
void* const praw = allocator.allocate(sizeof(Block));
if (praw == NULL)
if (praw == UAVCAN_NULLPTR)
{
return NULL;
return UAVCAN_NULLPTR;
}
return new (praw) Block;
}
void TransferBufferManagerEntry::Block::destroy(Block*& obj, IPoolAllocator& allocator)
{
if (obj != NULL)
if (obj != UAVCAN_NULLPTR)
{
obj->~Block();
allocator.deallocate(obj);
obj = NULL;
obj = UAVCAN_NULLPTR;
}
}
@@ -131,20 +131,20 @@ TransferBufferManagerEntry* TransferBufferManagerEntry::instantiate(IPoolAllocat
uint16_t max_size)
{
void* const praw = allocator.allocate(sizeof(TransferBufferManagerEntry));
if (praw == NULL)
if (praw == UAVCAN_NULLPTR)
{
return NULL;
return UAVCAN_NULLPTR;
}
return new (praw) TransferBufferManagerEntry(allocator, max_size);
}
void TransferBufferManagerEntry::destroy(TransferBufferManagerEntry*& obj, IPoolAllocator& allocator)
{
if (obj != NULL)
if (obj != UAVCAN_NULLPTR)
{
obj->~TransferBufferManagerEntry();
allocator.deallocate(obj);
obj = NULL;
obj = UAVCAN_NULLPTR;
}
}
@@ -206,7 +206,7 @@ int TransferBufferManagerEntry::write(unsigned offset, const uint8_t* data, unsi
unsigned left_to_write = len;
const uint8_t* inptr = data;
Block* p = blocks_.get();
Block* last_written_block = NULL;
Block* last_written_block = UAVCAN_NULLPTR;
// First we need to write the part that is already allocated
while (p)
@@ -224,20 +224,20 @@ int TransferBufferManagerEntry::write(unsigned offset, const uint8_t* data, unsi
while (left_to_write > 0)
{
// cppcheck-suppress nullPointer
UAVCAN_ASSERT(p == NULL);
UAVCAN_ASSERT(p == UAVCAN_NULLPTR);
// Allocating the chunk
Block* new_block = Block::instantiate(allocator_);
if (new_block == NULL)
if (new_block == UAVCAN_NULLPTR)
{
break; // We're in deep shit.
}
// Appending the chain with the new block
if (last_written_block != NULL)
if (last_written_block != UAVCAN_NULLPTR)
{
UAVCAN_ASSERT(last_written_block->getNextListNode() == NULL); // Because it is last in the chain
UAVCAN_ASSERT(last_written_block->getNextListNode() == UAVCAN_NULLPTR); // Because it is last in the chain
last_written_block->setNextListNode(new_block);
new_block->setNextListNode(NULL);
new_block->setNextListNode(UAVCAN_NULLPTR);
}
else
{
@@ -284,7 +284,7 @@ TransferBufferManagerEntry* TransferBufferManager::findFirst(const TransferBuffe
}
dyn = dyn->getNextListNode();
}
return NULL;
return UAVCAN_NULLPTR;
}
TransferBufferManager::~TransferBufferManager()
@@ -304,7 +304,7 @@ ITransferBuffer* TransferBufferManager::access(const TransferBufferManagerKey& k
if (key.isEmpty())
{
UAVCAN_ASSERT(0);
return NULL;
return UAVCAN_NULLPTR;
}
return findFirst(key);
}
@@ -314,21 +314,21 @@ ITransferBuffer* TransferBufferManager::create(const TransferBufferManagerKey& k
if (key.isEmpty())
{
UAVCAN_ASSERT(0);
return NULL;
return UAVCAN_NULLPTR;
}
remove(key);
TransferBufferManagerEntry* tbme = TransferBufferManagerEntry::instantiate(allocator_, max_buf_size_);
if (tbme == NULL)
if (tbme == UAVCAN_NULLPTR)
{
return NULL; // Epic fail.
return UAVCAN_NULLPTR; // Epic fail.
}
buffers_.insert(tbme);
UAVCAN_TRACE("TransferBufferManager", "Buffer created [num=%u], %s", getNumBuffers(), key.toString().c_str());
if (tbme != NULL)
if (tbme != UAVCAN_NULLPTR)
{
UAVCAN_ASSERT(tbme->isEmpty());
tbme->reset(key);
@@ -341,7 +341,7 @@ void TransferBufferManager::remove(const TransferBufferManagerKey& key)
UAVCAN_ASSERT(!key.isEmpty());
TransferBufferManagerEntry* dyn = findFirst(key);
if (dyn != NULL)
if (dyn != UAVCAN_NULLPTR)
{
UAVCAN_TRACE("TransferBufferManager", "Buffer deleted, %s", key.toString().c_str());
buffers_.remove(dyn);
@@ -32,7 +32,7 @@ SingleFrameIncomingTransfer::SingleFrameIncomingTransfer(const RxFrame& frm)
int SingleFrameIncomingTransfer::read(unsigned offset, uint8_t* data, unsigned len) const
{
if (data == NULL)
if (data == UAVCAN_NULLPTR)
{
UAVCAN_ASSERT(0);
return -ErrInvalidParam;
@@ -71,7 +71,7 @@ MultiFrameIncomingTransfer::MultiFrameIncomingTransfer(MonotonicTime ts_mono, Ut
int MultiFrameIncomingTransfer::read(unsigned offset, uint8_t* data, unsigned len) const
{
const ITransferBuffer* const tbb = const_cast<TransferBufferAccessor&>(buf_acc_).access();
if (tbb == NULL)
if (tbb == UAVCAN_NULLPTR)
{
UAVCAN_TRACE("MultiFrameIncomingTransfer", "Read failed: no such buffer");
return -ErrLogic;
@@ -153,7 +153,7 @@ void TransferListener::handleReception(TransferReceiver& receiver, const RxFrame
{
perf_.addRxTransfer();
const ITransferBuffer* tbb = tba.access();
if (tbb == NULL)
if (tbb == UAVCAN_NULLPTR)
{
UAVCAN_TRACE("TransferListener", "Buffer access failure, last frame: %s", frame.toString().c_str());
break;
@@ -206,7 +206,7 @@ void TransferListener::handleFrame(const RxFrame& frame)
const TransferBufferManagerKey key(frame.getSrcNodeID(), frame.getTransferType());
TransferReceiver* recv = receivers_.access(key);
if (recv == NULL)
if (recv == UAVCAN_NULLPTR)
{
if (!frame.isStartOfTransfer())
{
@@ -215,7 +215,7 @@ void TransferListener::handleFrame(const RxFrame& frame)
TransferReceiver new_recv;
recv = receivers_.insert(key, new_recv);
if (recv == NULL)
if (recv == UAVCAN_NULLPTR)
{
UAVCAN_TRACE("TransferListener", "Receiver registration failed; frame %s", frame.toString().c_str());
return;
@@ -242,7 +242,7 @@ void TransferListener::handleFrame(const RxFrame& frame)
*/
void TransferListenerWithFilter::handleFrame(const RxFrame& frame)
{
if (filter_ != NULL)
if (filter_ != UAVCAN_NULLPTR)
{
if (filter_->shouldAcceptFrame(frame))
{
@@ -148,11 +148,11 @@ TransferReceiver::ResultCode TransferReceiver::receive(const RxFrame& frame, Tra
// Payload write
ITransferBuffer* buf = tba.access();
if (buf == NULL)
if (buf == UAVCAN_NULLPTR)
{
buf = tba.create();
}
if (buf == NULL)
if (buf == UAVCAN_NULLPTR)
{
UAVCAN_TRACE("TransferReceiver", "Failed to access the buffer, %s", frame.toString().c_str());
prepareForNextTransfer();
@@ -156,7 +156,7 @@ int TransferSender::send(const uint8_t* payload, unsigned payload_len, Monotonic
OutgoingTransferRegistry::MinEntryLifetime);
TransferID* const tid = dispatcher_.getOutgoingTransferRegistry().accessOrCreate(otr_key, otr_deadline);
if (tid == NULL)
if (tid == UAVCAN_NULLPTR)
{
UAVCAN_TRACE("TransferSender", "OTR access failure, dtid=%d tt=%i",
int(data_type_id_.get()), int(transfer_type));
+1 -1
View File
@@ -100,7 +100,7 @@ const unsigned DataTypeDescriptor::MaxFullNameLen;
bool DataTypeDescriptor::isValid() const
{
return id_.isValidForDataTypeKind(kind_) &&
(full_name_ != NULL) &&
(full_name_ != UAVCAN_NULLPTR) &&
(*full_name_ != '\0');
}
+1 -1
View File
@@ -18,7 +18,7 @@ void* LimitedPoolAllocator::allocate(std::size_t size)
}
else
{
return NULL;
return UAVCAN_NULLPTR;
}
}