From 5dbeef5a959ae7e1f761240921798a25fa2866bd Mon Sep 17 00:00:00 2001 From: Joakim Gebart Date: Mon, 18 May 2015 06:12:10 +0200 Subject: [PATCH] drivers/ng_at86rf2xx: correct array bounds on tx_pow_to_dbm There are only 37 entries in the array in the C file as well as in the table in the data sheet. Fixes the following cppcheck error: drivers/ng_at86rf2xx/ng_at86rf2xx_getset.c:49: error (arrayIndexOutOfBounds): Array 'dbm_to_tx_pow_868[37]' accessed at index 37, which is out of bounds. --- drivers/ng_at86rf2xx/ng_at86rf2xx_getset.c | 28 ++++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/drivers/ng_at86rf2xx/ng_at86rf2xx_getset.c b/drivers/ng_at86rf2xx/ng_at86rf2xx_getset.c index e89a1bcc7..d4bf9ea4b 100644 --- a/drivers/ng_at86rf2xx/ng_at86rf2xx_getset.c +++ b/drivers/ng_at86rf2xx/ng_at86rf2xx_getset.c @@ -29,22 +29,24 @@ #include "debug.h" #ifdef MODULE_NG_AT86RF212B +/* See: Table 9-15. Recommended Mapping of TX Power, Frequency Band, and + * PHY_TX_PWR (register 0x05), AT86RF212B data sheet. */ static const uint8_t dbm_to_tx_pow_868[] = {0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, - 0x17, 0x15, 0x14, 0x13, 0x12, 0x11, - 0x10, 0x0f, 0x31, 0x30, 0x2f, 0x94, - 0x93, 0x91, 0x90, 0x29, 0x49, 0x48, - 0x47, 0xad, 0xcd, 0xcc, 0xcb, 0xea, - 0xe9, 0xe8, 0xe7, 0xe6, 0xe4, 0x80, - 0xa0}; + 0x17, 0x15, 0x14, 0x13, 0x12, 0x11, + 0x10, 0x0f, 0x31, 0x30, 0x2f, 0x94, + 0x93, 0x91, 0x90, 0x29, 0x49, 0x48, + 0x47, 0xad, 0xcd, 0xcc, 0xcb, 0xea, + 0xe9, 0xe8, 0xe7, 0xe6, 0xe4, 0x80, + 0xa0}; static const uint8_t dbm_to_tx_pow_915[] = {0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x17, - 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, - 0x10, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, - 0x09, 0x91, 0x08, 0x07, 0x05, 0x27, - 0x04, 0x03, 0x02, 0x01, 0x00, 0x86, - 0x40, 0x84, 0x83, 0x82, 0x80, 0xc1, - 0xc0}; + 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, + 0x10, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, + 0x09, 0x91, 0x08, 0x07, 0x05, 0x27, + 0x04, 0x03, 0x02, 0x01, 0x00, 0x86, + 0x40, 0x84, 0x83, 0x82, 0x80, 0xc1, + 0xc0}; int16_t tx_pow_to_dbm(ng_at86rf2xx_freq_t freq, uint8_t reg) { - for(int i = 0; i < 38; i++){ + for(int i = 0; i < 37; i++){ if(freq == NG_AT86RF2XX_FREQ_868MHZ){ if (dbm_to_tx_pow_868[i] == reg) { return i -25;