diff --git a/src/main/common/utils.h b/src/main/common/utils.h index e585d96277..468e42f6b0 100644 --- a/src/main/common/utils.h +++ b/src/main/common/utils.h @@ -22,6 +22,7 @@ #define ARRAYLEN(x) (sizeof(x) / sizeof((x)[0])) #define ARRAYEND(x) (&(x)[ARRAYLEN(x)]) +#define ZERO_FARRAY(a) memset(a, 0, sizeof(a)) #define CONST_CAST(type, value) ((type)(value)) @@ -92,9 +93,9 @@ static inline int32_t cmp32(uint32_t a, uint32_t b) { return a-b; } #ifdef UNIT_TEST // Call memcpy when building unittest - this is easier that asm symbol name mangling (symbols start with _underscore on win32) #include -static inline void memcpy_fn ( void * destination, const void * source, size_t num ) { memcpy(destination, source, num); }; +static inline void memcpy_fn(void *destination, const void *source, size_t num) { memcpy(destination, source, num); }; #else -void * memcpy_fn ( void * destination, const void * source, size_t num ) asm("memcpy"); +void *memcpy_fn(void *destination, const void *source, size_t num) asm("memcpy"); #endif #if __GNUC__ > 6 diff --git a/src/main/config/config_streamer_ram.c b/src/main/config/config_streamer_ram.c index 9a7e8578ab..420e2a0e6c 100644 --- a/src/main/config/config_streamer_ram.c +++ b/src/main/config/config_streamer_ram.c @@ -41,7 +41,7 @@ int config_streamer_impl_write_word(config_streamer_t *c, config_streamer_buffer } if (c->address == (uintptr_t)&eepromData[0]) { - memset(eepromData, 0, sizeof(eepromData)); + ZERO_FARRAY(eepromData); } config_streamer_buffer_align_type_t *destAddr = (config_streamer_buffer_align_type_t *)c->address; diff --git a/src/main/drivers/pwm_output.c b/src/main/drivers/pwm_output.c index db9e1e3296..7696492bd1 100644 --- a/src/main/drivers/pwm_output.c +++ b/src/main/drivers/pwm_output.c @@ -261,7 +261,7 @@ static pwmOutputPort_t * motorConfigDshot(const timerHardware_t * timerHardware, // Configure timer DMA if (timerPWMConfigChannelDMA(port->tch, port->dmaBuffer, sizeof(port->dmaBuffer[0]), DSHOT_DMA_BUFFER_SIZE)) { // Only mark as DSHOT channel if DMA was set successfully - memset(port->dmaBuffer, 0, sizeof(port->dmaBuffer)); + ZERO_FARRAY(port->dmaBuffer); port->configured = true; } diff --git a/src/main/fc/cli.c b/src/main/fc/cli.c index 53aad4f83f..70dd3f9e50 100644 --- a/src/main/fc/cli.c +++ b/src/main/fc/cli.c @@ -4059,7 +4059,7 @@ void cliProcess(void) bufferIndex = 0; } - memset(cliBuffer, 0, sizeof(cliBuffer)); + ZERO_FARRAY(cliBuffer); // 'exit' will reset this flag, so we don't need to print prompt again if (!cliMode) diff --git a/src/main/fc/fc_msp_box.c b/src/main/fc/fc_msp_box.c index 3577789359..aeb1463164 100644 --- a/src/main/fc/fc_msp_box.c +++ b/src/main/fc/fc_msp_box.c @@ -350,7 +350,7 @@ void initActiveBoxIds(void) void packBoxModeFlags(boxBitmask_t * mspBoxModeFlags) { uint8_t activeBoxes[CHECKBOX_ITEM_COUNT]; - memset(activeBoxes, 0, sizeof(activeBoxes)); + ZERO_FARRAY(activeBoxes); // Serialize the flags in the order we delivered them, ignoring BOXNAMES and BOXINDEXES // Requires new Multiwii protocol version to fix diff --git a/src/main/io/vtx_ffpv24g.c b/src/main/io/vtx_ffpv24g.c index 3cac3acf04..87c29418da 100644 --- a/src/main/io/vtx_ffpv24g.c +++ b/src/main/io/vtx_ffpv24g.c @@ -203,7 +203,7 @@ static void vtxProtoSend(uint8_t cmd, const uint8_t * data) memcpy(vtxState.sendPkt.data, data, sizeof(vtxState.sendPkt.data)); } else { - memset(vtxState.sendPkt.data, 0, sizeof(vtxState.sendPkt.data)); + ZERO_FARRAY(vtxState.sendPkt.data); } vtxState.sendPkt.checksum = vtxCalcChecksum(&vtxState.sendPkt); diff --git a/src/main/telemetry/sim.c b/src/main/telemetry/sim.c index 7fda28cd08..dc88a8c01e 100644 --- a/src/main/telemetry/sim.c +++ b/src/main/telemetry/sim.c @@ -346,7 +346,7 @@ static void sendSMS(void) uint16_t avgSpeed = lrintf(10 * calculateAverageSpeed()); uint32_t now = millis(); - memset(pluscode_url, 0, sizeof(pluscode_url)); + ZERO_FARRAY(pluscode_url); if (sensors(SENSOR_GPS) && STATE(GPS_FIX)) { groundSpeed = gpsSol.groundSpeed / 100; diff --git a/src/test/unit/bitarray_unittest.cc b/src/test/unit/bitarray_unittest.cc index d80f380d82..2c3ae5b813 100644 --- a/src/test/unit/bitarray_unittest.cc +++ b/src/test/unit/bitarray_unittest.cc @@ -10,7 +10,7 @@ extern "C" { TEST(BitArrayTest, TestGetSet) { BITARRAY_DECLARE(p, 32); - memset(p, 0, sizeof(p)); + ZERO_FARRAY(p); bitArraySet(p, 14); EXPECT_EQ(bitArrayGet(p, 14), true); @@ -25,7 +25,7 @@ TEST(BitArrayTest, TestGetSet) TEST(BitArrayTest, TestClr) { BITARRAY_DECLARE(p, 32); - memset(p, 0, sizeof(p)); + ZERO_FARRAY(p); bitArraySet(p, 31); EXPECT_EQ(bitArrayGet(p, 31), true); @@ -37,8 +37,8 @@ TEST(BitArrayTest, TestClr) TEST(BitArrayTest, TestFind) { - BITARRAY_DECLARE(p, 32*4); - memset(p, 0, sizeof(p)); + BITARRAY_DECLARE(p, 32 * 4); + ZERO_FARRAY(p); EXPECT_EQ(bitArrayFindFirstSet(p, 0, sizeof(p)), -1);