From caa4924336f865139c93136fd56ebb4bae5f4260 Mon Sep 17 00:00:00 2001 From: Joe Finney Date: Fri, 26 Feb 2016 16:27:13 +0000 Subject: [PATCH] microbit: Added validation case in MicroBitRadioDatagram::recv() Introduced missed validation case in MicroBitRadioDatagram::recv(). Added PacketBuffer::EmptyPacket as a NULL reference. --- inc/PacketBuffer.h | 2 ++ source/PacketBuffer.cpp | 3 +++ source/ble-services/MicroBitRadioDatagram.cpp | 3 +++ 3 files changed, 8 insertions(+) diff --git a/inc/PacketBuffer.h b/inc/PacketBuffer.h index 7ef932f..a0c40ca 100644 --- a/inc/PacketBuffer.h +++ b/inc/PacketBuffer.h @@ -233,6 +233,8 @@ class PacketBuffer * @endcode */ void setRSSI(uint8_t rssi); + + static PacketBuffer EmptyPacket; }; #endif diff --git a/source/PacketBuffer.cpp b/source/PacketBuffer.cpp index 32cb783..54f8ca7 100644 --- a/source/PacketBuffer.cpp +++ b/source/PacketBuffer.cpp @@ -1,5 +1,8 @@ #include "MicroBit.h" +// Create the EmptyPacket reference. +PacketBuffer PacketBuffer::EmptyPacket = PacketBuffer(1); + /** * Default Constructor. * Creates an empty Packet Buffer. diff --git a/source/ble-services/MicroBitRadioDatagram.cpp b/source/ble-services/MicroBitRadioDatagram.cpp index c6727fd..8f96a73 100644 --- a/source/ble-services/MicroBitRadioDatagram.cpp +++ b/source/ble-services/MicroBitRadioDatagram.cpp @@ -57,6 +57,9 @@ int MicroBitRadioDatagram::recv(uint8_t *buf, int len) */ PacketBuffer MicroBitRadioDatagram::recv() { + if (rxQueue == NULL) + return PacketBuffer::EmptyPacket; + FrameBuffer *p = rxQueue; rxQueue = rxQueue->next;