Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: kionix-kx123-hello rohm-bh1790glc-hello simple-sensor-client rohm-SensorShield-example
Fork of rohm-sensor-hal by
Diff: source/RegisterWriter.cpp
- Revision:
- 14:f33e0914ea36
- Parent:
- 13:3d4508874121
diff -r 3d4508874121 -r f33e0914ea36 source/RegisterWriter.cpp
--- a/source/RegisterWriter.cpp Fri Jun 16 11:54:33 2017 +0000
+++ b/source/RegisterWriter.cpp Mon Feb 18 14:26:35 2019 +0900
@@ -28,7 +28,7 @@
#include "../RegisterWriter/RegisterWriter.h" //prototypes
#define I2C_WRITE 0
#define I2C_READ 1
-
+#define MAX_DATA_LENGTH 6
RegisterWriter::RegisterWriter(I2C &i2c_obj) : i2c_bus(i2c_obj) {
self_created_i2c = false;
@@ -88,7 +88,10 @@
bool RegisterWriter::write_register_single(uint8_t sad, uint8_t reg, uint8_t* data, uint8_t data_len) {
bool error;
- char cmd[data_len+1];
+ char cmd[MAX_DATA_LENGTH+1]; // assume max value of data_len is 6
+ if (data_len>MAX_DATA_LENGTH) {
+ return false;
+ }
cmd[0] = reg;
for (int i = 0; i < data_len; i++) {
