Skip to content

Commit b9de0dd

Browse files
committed
fix various warnings
1 parent 9ae33db commit b9de0dd

File tree

6 files changed

+51
-45
lines changed

6 files changed

+51
-45
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/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
{

tools/build_all.py

Lines changed: 5 additions & 22 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[36mskipped\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

@@ -67,19 +57,12 @@ def build_examples(variant):
6757
elif glob.glob(sketchdir+"/.*.test.only") and not os.path.exists(sketchdir + '/.' + variant + '.test.only'):
6858
success = SKIPPED
6959
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)
60+
build_result = subprocess.run("arduino-cli compile --warnings all --fqbn {} {}".format(fqbn, sketch), shell=True, stdout=PIPE, stderr=PIPE)
7761

7862
# get stderr into a form where len(warningLines) indicates a true warning was output to stderr
7963
warningLines = [];
80-
if all_warnings and build_result.stderr:
81-
tmpWarningLines = build_result.stderr.decode("utf-8").splitlines()
82-
warningLines = list(filter(errorOutputFilter, (tmpWarningLines)))
64+
if build_result.stderr:
65+
warningLines = build_result.stderr.decode("utf-8").splitlines()
8366

8467
if build_result.returncode != 0:
8568
exit_status = build_result.returncode

0 commit comments

Comments
 (0)