Skip to content

Commit 7f8a365

Browse files
committed
printf format fix for memDump.
1 parent b95a044 commit 7f8a365

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"initializer_list": "cpp",
1111
"xstring": "cpp",
1212
"xlocale": "cpp",
13-
"ios": "cpp"
13+
"ios": "cpp",
14+
"xmemory": "cpp"
1415
}
1516
}

src/Commander-API.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ SOFTWARE.
157157
/// @param element One element in the system variables table.
158158
/// @param name The name of the int variable.
159159
/// @note Do not use & operator before the name. Just use the name, the macro will handle the rest.
160-
#define systemVariableInt_P( element, name ) { element.name_P = __CONST_TXT__( name ); element.floatData = NULL; element.intData = NULL; element.strData = (char*)name; element.name = NULL; }
160+
#define systemVariableString_P( element, name ) { element.name_P = __CONST_TXT__( name ); element.floatData = NULL; element.intData = NULL; element.strData = (char*)name; element.name = NULL; }
161161

162162
#endif
163163

src/Commander-Database.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ class CommanderDatabase{
142142

143143
/// Find array index by element place.
144144
///
145-
/// This function returns the array index( from 0 to tree size - 1 )
145+
/// This function returns the array index( from 1 to tree size )
146146
/// of an element by its place variable. It can be handy because the
147147
/// actual place not represents the real index in the binary tree.
148148
/// @param place Place of the searched element.
149149
/// @returns The array index of the element if the place is found.
150150
/// If the place is invalid or not found, the returned value
151151
/// will be 0 to avoid bad addressing.
152-
int findIndexByPlace( int place );
152+
uint16_t findIndexByPlace( uint16_t place );
153153

154154
/// Get tree size
155155
///
@@ -242,13 +242,13 @@ int CommanderDatabase< T >::strcmpElementCharArrayRegular( dataRecord_t* element
242242
}
243243

244244
template< typename T >
245-
int CommanderDatabase< T >::findIndexByPlace( int place ){
245+
uint16_t CommanderDatabase< T >::findIndexByPlace( uint16_t place ){
246246

247247
// Generic counter variable
248248
uint16_t i;
249249

250250
// Go through all commands
251-
for( i = 0; i < dataTreeSize; i++ ){
251+
for( i = 1; i <= dataTreeSize; i++ ){
252252

253253
// Check that if we found the desired command
254254
if( dataTree[ i ].place == place ){

src/Commands/Commander-API-Memory-Commands.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ bool commander_memDump_func( char *args, Stream *response, void* parent ){
190190
return false;
191191
}
192192

193-
if( sscanf( &buffer[ 2 ],"%x", &startAddressNumber ) != 1 ){
193+
if( sscanf( &buffer[ 2 ],"%" PRIx32, &startAddressNumber ) != 1 ){
194194
Commander::printArgumentError( response );
195195
response -> print( __CONST_TXT__( " Start address format is not correct! Example: 0x012ABC" ) );
196196
return false;
@@ -239,7 +239,7 @@ bool commander_memDump_func( char *args, Stream *response, void* parent ){
239239
return false;
240240
}
241241

242-
if( sscanf( &buffer[ 2 ],"%x", &endAddressNumber ) != 1 ){
242+
if( sscanf( &buffer[ 2 ],"%" PRIx32, &endAddressNumber ) != 1 ){
243243
return false;
244244
}
245245

@@ -299,11 +299,11 @@ bool commander_memDump_func( char *args, Stream *response, void* parent ){
299299
}
300300

301301
response -> print( __CONST_TXT__( "Start Address: 0x" ) );
302-
snprintf( buffer, sizeof( buffer ), "%08x", startAddressNumber );
302+
snprintf( buffer, sizeof( buffer ), "%08" PRIx32, startAddressNumber );
303303
response -> println( buffer );
304304

305305
response -> print( __CONST_TXT__( "End Address: 0x" ) );
306-
snprintf( buffer, sizeof( buffer ), "%08x", endAddressNumber );
306+
snprintf( buffer, sizeof( buffer ), "%08" PRIx32, endAddressNumber );
307307
response -> println( buffer );
308308

309309
response -> print( __CONST_TXT__( "Number of elements: " ) );
@@ -321,7 +321,7 @@ bool commander_memDump_func( char *args, Stream *response, void* parent ){
321321
}
322322

323323
j = 8 * ( bytesInData - i - 1 );
324-
snprintf( buffer, sizeof( buffer ), " %02d:%02d |", j + 7, j);
324+
snprintf( buffer, sizeof( buffer ), " %02" PRIu32 ":%02" PRIu32 " |", j + 7, j);
325325
buffer[ sizeof( buffer ) - 1 ] = '\0';
326326
response -> print( buffer );
327327

@@ -333,7 +333,7 @@ bool commander_memDump_func( char *args, Stream *response, void* parent ){
333333

334334
dataPointer = (uint32_t)( startAddressNumber + i * bytesInData );
335335
response -> print( __CONST_TXT__( "0x" ) );
336-
snprintf( buffer, sizeof( buffer ), "%08x", dataPointer );
336+
snprintf( buffer, sizeof( buffer ), "%08" PRIx32, dataPointer );
337337
buffer[ sizeof( buffer ) - 1 ] = '\0';
338338
response -> print( buffer );
339339
response -> print( __CONST_TXT__( " |" ) );

0 commit comments

Comments
 (0)