Skip to content

Commit b9d586b

Browse files
authored
Merge pull request #347 from henrygab/PatchMulti
Compile without warnings
2 parents 8dbe7d9 + 31180ec commit b9d586b

File tree

10 files changed

+104
-32
lines changed

10 files changed

+104
-32
lines changed

cores/nRF5/common_func.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ const char* dbg_err_str(int32_t err_id); // TODO move to other place
171171

172172
#define ADALOG_BUFFER(_tag, _buf, _n) \
173173
do {\
174-
if ( _tag ) PRINTF("%-6s: len = %d\n", _tag, _n);\
174+
const char * _xtag = _tag;\
175+
if ( _xtag ) PRINTF("%-6s: len = %d\n", _xtag, _n);\
175176
dbgDumpMemory(_buf, 1, _n, true);\
176177
}while(0)
177178

cores/nRF5/verify.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ extern "C"
6262
do { \
6363
const char* (*_fstr)(int32_t) = _funcstr;\
6464
printf("%s: %d: verify failed, error = ", __PRETTY_FUNCTION__, __LINE__);\
65-
if (_fstr) printf(_fstr(_status)); else printf("%d", _status);\
65+
if (_fstr) printf(_fstr(_status)); else printf("%ld", _status);\
6666
printf("\n");\
6767
}while(0)
6868
#else

libraries/Adafruit_LittleFS/src/Adafruit_LittleFS.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ const char* dbg_strerr_lfs (int32_t err)
179179

180180
default:
181181
static char errcode[10];
182-
sprintf(errcode, "%d", err);
182+
sprintf(errcode, "%ld", err);
183183
return errcode;
184184
}
185185

libraries/Adafruit_LittleFS/src/Adafruit_LittleFS.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class Adafruit_LittleFS
8383
#define PRINT_LFS_ERR(_err)
8484
#else
8585
#define VERIFY_LFS(...) _GET_3RD_ARG(__VA_ARGS__, VERIFY_ERR_2ARGS, VERIFY_ERR_1ARGS)(__VA_ARGS__, dbg_strerr_lfs)
86-
#define PRINT_LFS_ERR(_err) VERIFY_MESS(_err, dbg_strerr_lfs)
86+
#define PRINT_LFS_ERR(_err) VERIFY_MESS((long int)_err, dbg_strerr_lfs) // LFS_ERR are of type int, VERIFY_MESS expects long_int
8787

8888
const char* dbg_strerr_lfs (int32_t err);
8989
#endif

libraries/Bluefruit52Lib/src/BLEDiscovery.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ bool BLEDiscovery::_discoverService(uint16_t conn_handle, BLEClientService& svc,
8484
// timeout or has no data (due to GATT Error)
8585
if ( bytecount <= 0 )
8686
{
87-
LOG_LV1("DISC", "[SVC] timeout or error", start_handle);
87+
LOG_LV1("DISC", "[SVC] timeout or error %ud", start_handle);
8888
return false;
8989
}
9090

libraries/Bluefruit52Lib/src/BLEGatt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ void BLEGatt::_eventHandler(ble_evt_t* evt)
211211

212212
if (rd_rsp->count)
213213
{
214-
ble_gattc_handle_value_t hdl_value;
214+
ble_gattc_handle_value_t hdl_value = { 0, nullptr };
215215

216216
if ( ERROR_NONE == sd_ble_gattc_evt_char_val_by_uuid_read_rsp_iter(&evt->evt.gattc_evt, &hdl_value) )
217217
{

libraries/Bluefruit52Lib/src/bluefruit.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void AdafruitBluefruit::configUuid128Count(uint8_t uuid128_max)
205205

206206
void AdafruitBluefruit::configAttrTableSize(uint32_t attr_table_size)
207207
{
208-
_sd_cfg.attr_table_size = align4( maxof(attr_table_size, BLE_GATTS_ATTR_TAB_SIZE_MIN) );
208+
_sd_cfg.attr_table_size = align4( maxof(attr_table_size, (uint32_t)(BLE_GATTS_ATTR_TAB_SIZE_MIN)) );
209209
}
210210

211211
void AdafruitBluefruit::configPrphConn(uint16_t mtu_max, uint16_t event_len, uint8_t hvn_qsize, uint8_t wrcmd_qsize)
@@ -437,11 +437,11 @@ bool AdafruitBluefruit::begin(uint8_t prph_count, uint8_t central_count)
437437
if ( err )
438438
{
439439
LOG_LV1("CFG", "SoftDevice config require more SRAM than provided by linker.\n"
440-
"App Ram Start must be at least 0x%08X (provided 0x%08X)\n"
440+
"App Ram Start must be at least 0x%08lX (provided 0x%08lX)\n"
441441
"Please update linker file or re-config SoftDevice", ram_start, (uint32_t) __data_start__);
442442
}
443443

444-
LOG_LV1("CFG", "SoftDevice's RAM requires: 0x%08X", ram_start);
444+
LOG_LV1("CFG", "SoftDevice's RAM requires: 0x%08lX", ram_start);
445445
VERIFY_STATUS(err, false);
446446

447447
/*------------- Configure BLE Option -------------*/

libraries/Bluefruit52Lib/src/services/BLEMidi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ bool BLEMidi::isStatusByte( uint8_t b )
314314
bool BLEMidi::oneByteMessage( uint8_t status )
315315
{
316316
// system messages
317-
if (status >= 0xF4 && status <= 0xFF) return true;
317+
if (status >= 0xF4) return true;
318318

319319
// system common
320320
if (status == 0xF1) return true;

libraries/Bluefruit52Lib/src/utility/bonding.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static void bond_save_keys_dfr (uint8_t role, uint16_t conn_hdl, bond_keys_t* bk
123123

124124
bdata_write(&file, devname, strlen(devname)+1); // save also null char
125125

126-
BOND_LOG("Saved keys for \"%s\" to file %s ( %d bytes )", devname, filename, file.size());
126+
BOND_LOG("Saved keys for \"%s\" to file %s ( %ld bytes )", devname, filename, file.size());
127127

128128
file.close();
129129
}
@@ -178,7 +178,7 @@ static void bond_save_cccd_dfr (uint8_t role, uint16_t conn_hdl, uint16_t ediv)
178178

179179
bdata_write(&file, sys_attr, len);
180180

181-
BOND_LOG("Saved CCCD setting to file %s ( offset = %d, len = %d bytes )", filename, file.size() - (len + 1), len);
181+
BOND_LOG("Saved CCCD setting to file %s ( offset = %ld, len = %d bytes )", filename, file.size() - (len + 1), len);
182182

183183
file.close();
184184
}
@@ -217,7 +217,7 @@ bool bond_load_cccd(uint8_t role, uint16_t conn_hdl, uint16_t ediv)
217217
if ( ERROR_NONE == sd_ble_gatts_sys_attr_set(conn_hdl, sys_attr, len, SVC_CONTEXT_FLAG) )
218218
{
219219
loaded = true;
220-
BOND_LOG("Loaded CCCD from file %s ( offset = %d, len = %d bytes )", filename, file.size() - (len + 1), len);
220+
BOND_LOG("Loaded CCCD from file %s ( offset = %ld, len = %d bytes )", filename, file.size() - (len + 1), len);
221221
}
222222
}
223223
}

libraries/InternalFileSytem/src/flash/flash_cache.c

Lines changed: 90 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,34 +97,105 @@ void flash_cache_flush (flash_cache_t* fc)
9797

9898
void flash_cache_read (flash_cache_t* fc, void* dst, uint32_t addr, uint32_t count)
9999
{
100+
// there is no check for overflow / wraparound for dst + count, addr + count.
101+
// this might be a useful thing to add for at least debug builds.
102+
100103
// overwrite with cache value if available
101-
if ( (fc->cache_addr != FLASH_CACHE_INVALID_ADDR) &&
102-
!(addr < fc->cache_addr && addr + count <= fc->cache_addr) &&
103-
!(addr >= fc->cache_addr + FLASH_CACHE_SIZE) )
104+
if ( (fc->cache_addr != FLASH_CACHE_INVALID_ADDR) && // cache is not valid
105+
!(addr < fc->cache_addr && addr + count <= fc->cache_addr) && // starts before, ends before cache area
106+
!(addr >= fc->cache_addr + FLASH_CACHE_SIZE) ) // starts after end of cache area
104107
{
105-
int dst_off = fc->cache_addr - addr;
106-
int src_off = 0;
107-
108-
if ( dst_off < 0 )
108+
// This block is entered only when the read overlaps the cache area by at least one byte.
109+
// If the read starts before the cache area, it's further guaranteed
110+
// that count is large enough to cause the read to enter
111+
// the cache area by at least 1 byte.
112+
uint32_t dst_off = 0;
113+
uint32_t src_off = 0;
114+
if (addr < fc->cache_addr)
109115
{
110-
src_off = -dst_off;
111-
dst_off = 0;
116+
dst_off = fc->cache_addr - addr;
117+
// Read the bytes prior to the cache address
118+
fc->read(dst, addr, dst_off);
112119
}
113-
114-
int cache_bytes = minof(FLASH_CACHE_SIZE-src_off, count - dst_off);
115-
116-
// start to cached
117-
if ( dst_off ) fc->read(dst, addr, dst_off);
118-
119-
// cached
120+
else
121+
{
122+
src_off = addr - fc->cache_addr;
123+
}
124+
125+
// Thus, after the above code block executes:
126+
// *** AT MOST ***, only one of src_off and dst_off are non-zero;
127+
// (Both may be zero when the read starts at the start of the cache area.)
128+
// dst_off corresponds to the number of bytes already read from PRIOR to the cache area.
129+
// src_off corresponds to the byte offset to start reading at, from WITHIN the cache area.
130+
131+
// How many bytes to memcpy from flash area?
132+
// Remember that, AT MOST, one of src_off and dst_off are non-zero.
133+
// If src_off is non-zero, then dst_off is zero, representing that the
134+
// read starts inside the cache. In this case:
135+
// PARAM1 := FLASH_CACHE_SIZE - src_off == maximum possible bytes to read from cache
136+
// PARAM2 := count
137+
// Thus, taking the minimum of the two gives the number of bytes to read from cache,
138+
// in the range [ 1 .. FLASH_CACHE_SIZE-src_off ].
139+
// Else if dst_off is non-zero, then src_off is zero, representing that the
140+
// read started prior to the cache area. In this case:
141+
// PARAM1 := FLASH_CACHE_SIZE == full size of the cache
142+
// PARAM2 := count - dst_off == total bytes requested, minus the count of those already read
143+
// Because the original request is guaranteed to overlap the cache, the range for
144+
// PARAM2 is ensured to be [ 1 .. count-1 ].
145+
// Thus, taking the minimum of the two gives the number of bytes to read from cache,
146+
// in the range [ 1 .. FLASH_CACHE_SIZE ]
147+
// Else both src_off and dst_off are zero, representing that the read is starting
148+
// exactly aligned to the cache.
149+
// PARAM1 := FLASH_CACHE_SIZE
150+
// PARAM2 := count
151+
// Thus, taking the minimum of the two gives the number of bytes to read from cache,
152+
// in the range [ 1 .. FLASH_CACHE_SIZE ]
153+
//
154+
// Therefore, in all cases, there is assurance that cache_bytes
155+
// will be in the final range [1..FLASH_CACHE_SIZE].
156+
uint32_t cache_bytes = minof(FLASH_CACHE_SIZE-src_off, count - dst_off);
157+
158+
// Use memcpy to read cached data into the buffer
159+
// If src_off is non-zero, then dst_off is zero, representing that the
160+
// read starts inside the cache. In this case:
161+
// PARAM1 := dst
162+
// PARAM2 := fc->cache_buf + src_off
163+
// PARAM3 := cache_bytes
164+
// Thus, all works as expected when starting in the midst of the cache.
165+
// Else if dst_off is non-zero, then src_off is zero, representing that the
166+
// read started prior to the cache. In this case:
167+
// PARAM1 := dst + dst_off == destination offset by number of bytes already read
168+
// PARAM2 := fc->cache_buf
169+
// PARAM3 := cache_bytes
170+
// Thus, all works as expected when starting prior to the cache.
171+
// Else both src_off and dst_off are zero, representing that the read is starting
172+
// exactly aligned to the cache.
173+
// PARAM1 := dst
174+
// PARAM2 := fc->cache_buf
175+
// PARAM3 := cache_bytes
176+
// Thus, all works as expected when starting exactly at the cache boundary
177+
//
178+
// Therefore, in all cases, there is assurance that cache_bytes
179+
// will be in the final range [1..FLASH_CACHE_SIZE].
120180
memcpy(dst + dst_off, fc->cache_buf + src_off, cache_bytes);
121181

122-
// cached to end
123-
int copied = dst_off + cache_bytes;
124-
if ( copied < count ) fc->read(dst + copied, addr + copied, count - copied);
182+
// Read any final bytes from flash
183+
// As noted above, dst_off represents the count of bytes read prior to the cache
184+
// while cache_bytes represents the count of bytes read from the cache;
185+
// This code block is guaranteed to overlap the cache area by at least one byte.
186+
// Thus, copied will correspond to the total bytes already copied,
187+
// and is guaranteed to be in the range [ 1 .. count ].
188+
uint32_t copied = dst_off + cache_bytes;
189+
190+
//
191+
if ( copied < count )
192+
{
193+
fc->read(dst + copied, addr + copied, count - copied);
194+
}
125195
}
126196
else
127197
{
198+
// not using the cache, so just forward to read from flash
128199
fc->read(dst, addr, count);
129200
}
130201
}

0 commit comments

Comments
 (0)