Audit and fix up format strings

This commit is contained in:
Benjamin Barenblat
2022-08-03 19:32:39 -04:00
committed by Benjamin Barenblat
parent 4cd2da5202
commit cd7050613c
3 changed files with 30 additions and 9 deletions
+4 -1
View File
@@ -38,7 +38,10 @@ void hexdump( const void *buf, size_t len, const char *name ) {
const unsigned char *data = (const unsigned char *) buf;
printf( DUMP_NAME_FMT, name );
for ( size_t i = 0; i < len; i++ ) {
printf( "%02x", data[ i ] );
// Although data[i] is an unsigned char, it will be promoted to a signed int
// when passed as an argument. Explicitly cast it back to an unsigned type
// so it can be printed in hex.
printf( "%02x", static_cast<unsigned>( data[ i ] ) );
}
printf( "\n" );
}