1
0
Fork 0

add bounds check to slot address

This commit is contained in:
Kevin Matz 2021-06-19 21:12:40 -04:00
parent b5e4c05922
commit 88c7787f41
2 changed files with 19 additions and 6 deletions

View File

@ -25,7 +25,6 @@
#include "universe.h"
namespace DMX {
using std::copy;
/**
*/
@ -33,6 +32,19 @@ Universe::Universe() {
null_start_data_.fill(0);
}
/**
Get value of a slot.
@param uint16_t address of the requested slot.
@return const uint8_t value of the slot.
*/
const uint8_t Universe::slot (uint16_t address) const
{
if (address > 512) return 0;
return null_start_data_[address];
}
/**
accept new data from receiver
@ -42,7 +54,7 @@ void Universe::set(vector<uint8_t> vect) {
switch (vect.front()) { // start code
case E111_NULL_START:
vect.resize(null_start_data_.size(), 0); // pad shorter, truncate larger
copy(vect.begin(), vect.end(), null_start_data_.begin());
std::copy(vect.begin(), vect.end(), null_start_data_.begin());
for (const auto &cb : callbacks_)
cb(this);
break;

View File

@ -59,10 +59,11 @@ class Universe {
public:
Universe ();
DimmerData * data() { return &null_start_data_; }
void onData (const DataHandler callback);
void set (vector<uint8_t>);
uint8_t slot (uint16_t address) { return null_start_data_[address]; }
const DimmerData * data() const { return &null_start_data_; }
const uint8_t slot (uint16_t address) const;
void set (vector<uint8_t>);
void onData (const DataHandler);
private:
DimmerData null_start_data_;