HAL_PX4: Add input parameter check.

This commit is contained in:
murata 2016-11-27 19:59:03 +09:00 committed by Tom Pittenger
parent 696828c144
commit 5f41b09fde

View File

@ -187,15 +187,18 @@ void SPIDevice::do_transfer(const uint8_t *send, uint8_t *recv, uint32_t len)
bool SPIDevice::transfer(const uint8_t *send, uint32_t send_len,
uint8_t *recv, uint32_t recv_len)
{
// Check input parameters
if(0 == send_len || nullptr == send || (nullptr == recv && 0 != recv_len)) {
return false;
}
if (send_len == recv_len && send == recv) {
// simplest cases, needed for DMA
do_transfer(send, recv, recv_len);
return true;
}
uint8_t buf[send_len+recv_len];
if (send_len > 0) {
memcpy(buf, send, send_len);
}
memcpy(buf, send, send_len); // Set Register number, etc..
if (recv_len > 0) {
memset(&buf[send_len], 0, recv_len);
}