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

libraries/SPI/SPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ void SPIClass::transfer(const void *tx_buf, void *rx_buf, size_t count)
206206
while (count)
207207
{
208208
// each transfer can only up to 64KB (16-bit) bytes
209-
const size_t xfer_len = min(count, UINT16_MAX);
209+
const size_t xfer_len = min((uint16_t) count, UINT16_MAX);
210210

211211
nrfx_spim_xfer_desc_t xfer_desc =
212212
{

libraries/SoftwareSerial/SoftwareSerial.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class SoftwareSerial : public Stream
5959
static SoftwareSerial *active_object;
6060

6161
// private methods
62-
void recv() __attribute__((__always_inline__));
62+
void recv();
6363
uint32_t rx_pin_read();
6464
void tx_pin_write(uint8_t pin_state) __attribute__((__always_inline__));
6565
void setTX(uint8_t transmitPin);

tools/build_all.py

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77

88
SUCCEEDED = "\033[32msucceeded\033[0m"
99
FAILED = "\033[31mfailed\033[0m"
10-
SKIPPED = "\033[33mskipped\033[0m"
11-
WARNING = "\033[31mwarnings\033[0m"
10+
SKIPPED = "\033[35mskipped\033[0m"
11+
WARNING = "\033[33mwarnings\033[0m "
1212

13-
all_warnings = False
1413
exit_status = 0
1514
success_count = 0
1615
fail_count = 0
@@ -31,15 +30,6 @@
3130
all_examples = list(glob.iglob('libraries/**/*.ino', recursive=True))
3231
all_examples.sort()
3332

34-
def errorOutputFilter(line):
35-
if len(line) == 0:
36-
return False
37-
if line.isspace(): # Note: empty string does not match here!
38-
return False
39-
# TODO: additional items to remove?
40-
return True
41-
42-
4333
def build_examples(variant):
4434
global exit_status, success_count, fail_count, skip_count, build_format, build_separator
4535

@@ -64,49 +54,37 @@ def build_examples(variant):
6454
sketchdir = os.path.dirname(sketch)
6555
if os.path.exists(sketchdir + '/.all.test.skip') or os.path.exists(sketchdir + '/.' + variant + '.test.skip'):
6656
success = SKIPPED
57+
skip_count += 1
6758
elif glob.glob(sketchdir+"/.*.test.only") and not os.path.exists(sketchdir + '/.' + variant + '.test.only'):
6859
success = SKIPPED
60+
skip_count += 1
6961
else:
70-
# TODO - preferably, would have STDERR show up in **both** STDOUT and STDERR.
71-
# preferably, would use Python logging handler to get both distinct outputs and one merged output
72-
# for now, split STDERR when building with all warnings enabled, so can detect warning/error output.
73-
if all_warnings:
74-
build_result = subprocess.run("arduino-cli compile --warnings all --fqbn {} {}".format(fqbn, sketch), shell=True, stdout=PIPE, stderr=PIPE)
75-
else:
76-
build_result = subprocess.run("arduino-cli compile --warnings default --fqbn {} {}".format(fqbn, sketch), shell=True, stdout=PIPE, stderr=PIPE)
77-
78-
# get stderr into a form where len(warningLines) indicates a true warning was output to stderr
79-
warningLines = [];
80-
if all_warnings and build_result.stderr:
81-
tmpWarningLines = build_result.stderr.decode("utf-8").splitlines()
82-
warningLines = list(filter(errorOutputFilter, (tmpWarningLines)))
62+
build_result = subprocess.run("arduino-cli compile --warnings all --fqbn {} {}".format(fqbn, sketch), shell=True, stdout=PIPE, stderr=PIPE)
8363

64+
# get stderr into a form where warning/error was output to stderr
8465
if build_result.returncode != 0:
8566
exit_status = build_result.returncode
8667
success = FAILED
8768
fail_count += 1
88-
elif len(warningLines) != 0:
89-
exit_status = -1
90-
success = WARNING
91-
fail_count += 1
9269
else:
93-
success = SUCCEEDED
9470
success_count += 1
71+
if build_result.stderr:
72+
success = WARNING
73+
else:
74+
success = SUCCEEDED
9575

9676
build_duration = time.monotonic() - start_time
9777

9878
print(build_format.format(sketch.split(os.path.sep)[1], os.path.basename(sketch), success, '{:5.2f}s'.format(build_duration)))
9979

10080
if success != SKIPPED:
81+
# Build failed
10182
if build_result.returncode != 0:
10283
print(build_result.stdout.decode("utf-8"))
103-
if (build_result.stderr):
104-
print(build_result.stderr.decode("utf-8"))
105-
if len(warningLines) != 0:
106-
for line in warningLines:
107-
print(line)
108-
else:
109-
skip_count += 1
84+
85+
# Build with warnings
86+
if build_result.stderr:
87+
print(build_result.stderr.decode("utf-8"))
11088

11189
build_time = time.monotonic()
11290

0 commit comments

Comments
 (0)