Skip to content

Commit 04a8087

Browse files
authored
Merge pull request #647 from adafruit/fix-warning
Fix warning
2 parents 9ae33db + 7f843df commit 04a8087

File tree

13 files changed

+73
-68
lines changed

13 files changed

+73
-68
lines changed

cores/nRF5/HardwarePWM.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,16 @@ bool HardwarePWM::takeOwnership(uint32_t token)
266266
bool const thread_mode = !isInISR();
267267

268268
if (token == 0) {
269-
if (thread_mode) LOG_LV1("HwPWM", "zero is not a valid ownership token (attempted use in takeOwnership)");
269+
if (thread_mode) {
270+
LOG_LV1("HwPWM", "zero is not a valid ownership token (attempted use in takeOwnership)");
271+
}
270272
return false;
271273
}
272274

273275
if (token == this->_owner_token) {
274-
if (thread_mode) LOG_LV1("HwPWM", "failing to acquire ownership because already owned by requesting token (cannot take ownership twice)");
276+
if (thread_mode) {
277+
LOG_LV1("HwPWM", "failing to acquire ownership because already owned by requesting token (cannot take ownership twice)");
278+
}
275279
return false;
276280
}
277281

@@ -290,22 +294,30 @@ bool HardwarePWM::releaseOwnership(uint32_t token)
290294
bool const thread_mode = !isInISR();
291295

292296
if (token == 0) {
293-
if (thread_mode) LOG_LV1("HwPWM", "zero is not a valid ownership token (attempted use in releaseOwnership)");
297+
if (thread_mode) {
298+
LOG_LV1("HwPWM", "zero is not a valid ownership token (attempted use in releaseOwnership)");
299+
}
294300
return false;
295301
}
296302

297303
if (!this->isOwner(token)) {
298-
if (thread_mode) LOG_LV1("HwPWM", "attempt to release ownership when not the current owner");
304+
if (thread_mode) {
305+
LOG_LV1("HwPWM", "attempt to release ownership when not the current owner");
306+
}
299307
return false;
300308
}
301309

302310
if (this->usedChannelCount() != 0) {
303-
if (thread_mode) LOG_LV1("HwPWM", "attempt to release ownership when at least on channel is still connected");
311+
if (thread_mode) {
312+
LOG_LV1("HwPWM", "attempt to release ownership when at least on channel is still connected");
313+
}
304314
return false;
305315
}
306316

307317
if (this->enabled()) {
308-
if (thread_mode) LOG_LV1("HwPWM", "attempt to release ownership when PWM peripheral is still enabled");
318+
if (thread_mode) {
319+
LOG_LV1("HwPWM", "attempt to release ownership when PWM peripheral is still enabled");
320+
}
309321
return false; // if it's enabled, do not allow ownership to be released, even with no pins in use
310322
}
311323

cores/nRF5/Tone.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ constexpr static uint64_t _calculate_pulse_count(uint32_t frequency, uint32_t du
109109
(((uint64_t)duration) * frequency / 1000ULL);
110110
};
111111

112-
static int _bits_used(unsigned long x) {
113-
if (0 == x) return 0;
114-
unsigned int result = 0;
115-
do {
116-
result++;
117-
} while (x >>= 1);
118-
return result;
119-
}
112+
//static int _bits_used(unsigned long x) {
113+
// if (0 == x) return 0;
114+
// unsigned int result = 0;
115+
// do {
116+
// result++;
117+
// } while (x >>= 1);
118+
// return result;
119+
//}
120120

121121
static int _bits_used(unsigned long long x) {
122122
if (0 == x) return 0;

cores/nRF5/WString.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -693,13 +693,22 @@ void String::remove(unsigned int index){
693693
}
694694

695695
void String::remove(unsigned int index, unsigned int count){
696-
if (index >= len) { return; }
697-
if (count <= 0) { return; }
698-
if (count > len - index) { count = len - index; }
699-
char *writeTo = buffer + index;
700-
len = len - count;
701-
strncpy(writeTo, buffer + index + count,len - index);
702-
buffer[len] = 0;
696+
// removes characters from the middle of a string.
697+
if (count <= 0) { return; } // exit if nothing to remove
698+
if (index >= len) { return; } // ensure start is within string length; thus, ensures (len-index >= 1)
699+
if (count > len - index) { // ensure characters to remove is no larger than total length remaining
700+
count = len - index;
701+
}
702+
char *writeTo = buffer + index;
703+
char *copyFrom = buffer + index + count;
704+
len = len - count;
705+
706+
// strncpy() cannot be used with overlapping buffers, so copy one char at a time
707+
unsigned int charactersToMove = len - index; // yes, uses post-adjusted length
708+
for (unsigned int i = 0; i < charactersToMove; i++, writeTo++, copyFrom++) {
709+
*writeTo = *copyFrom;
710+
}
711+
buffer[len] = 0;
703712
}
704713

705714
void String::toLowerCase(void)

libraries/Adafruit_TinyUSB_Arduino

libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class BLEAdafruitSensor : public BLEService
4444
void setNotifyCallback(notify_callback_t fp);
4545

4646
protected:
47-
BLECharacteristic _period;
4847
BLECharacteristic _measurement;
48+
BLECharacteristic _period;
4949

5050
Adafruit_Sensor* _sensor;
5151

libraries/Bluefruit52Lib/examples/Central/central_pairing/central_pairing.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ void pairing_complete_callback(uint16_t conn_handle, uint8_t auth_status)
310310
}else
311311
{
312312
Serial.println("Failed");
313+
314+
// disconnect
315+
conn->disconnect();
313316
}
314317

315318
#ifdef USE_ARCADA
@@ -321,9 +324,6 @@ void pairing_complete_callback(uint16_t conn_handle, uint8_t auth_status)
321324
{
322325
tft->setTextColor(ARCADA_RED);
323326
tft->print("Failed ");
324-
325-
// disconnect
326-
conn->disconnect();
327327
}
328328

329329
tft->setTextColor(ARCADA_WHITE);

libraries/Bluefruit52Lib/examples/Peripheral/ancs_oled/ancs_oled.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ void displayNotification(int index)
241241
}else
242242
{
243243
// Text size = 1, max char is 21. Text size = 2, max char is 10
244-
char tempbuf[22];
244+
char tempbuf[30];
245245
sprintf(tempbuf, "%-15s %02d/%02d", myNtf->app_name, index+1, notifCount);
246246

247247
oled.println(tempbuf);

libraries/Bluefruit52Lib/examples/Peripheral/arduino_science_journal/arduino_science_journal.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void onPDMdata() {
8484

8585
uint16_t getSoundAverage() {
8686
uint32_t avg = 0;
87-
for (int i = 0; i < sizeof(soundSampleBuffer)/sizeof(soundSampleBuffer[0]); i++) {
87+
for (uint32_t i = 0; i < sizeof(soundSampleBuffer)/sizeof(soundSampleBuffer[0]); i++) {
8888
avg += soundSampleBuffer[i]*soundSampleBuffer[i];
8989
}
9090
return sqrt(avg);

libraries/Bluefruit52Lib/examples/Peripheral/image_eink_transfer/image_eink_transfer.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ void bleuart_rx_callback(uint16_t conn_hdl)
207207
red = (c565 & 0xf800) >> 8;
208208
green = (c565 & 0x07e0) >> 3;
209209
blue = (c565 & 0x001f) << 3;
210+
}else
211+
{
212+
Serial.println("Error: incorrect color bits ");
213+
while(1) yield();
210214
}
211215

212216
// Convert RGB into Eink Color

libraries/Bluefruit52Lib/src/utility/bonding.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@ bool bond_load_cccd(uint8_t role, uint16_t conn_hdl, ble_gap_addr_t const* id_ad
288288

289289
file.close();
290290

291-
if ( !loaded ) LOG_LV1("BOND", "CCCD setting not found");
291+
if ( !loaded ) {
292+
LOG_LV1("BOND", "CCCD setting not found");
293+
}
292294
return loaded;
293295
}
294296

0 commit comments

Comments
 (0)