Skip to content

Commit 8069517

Browse files
committed
Fixed all compilation warnings
Use %zu / %zx when printing stuff of size_t. Explicit typecast when using strtol/strtoul and a long is not wanted. Treat all warnings as errors when compiling.
1 parent c1bde59 commit 8069517

File tree

7 files changed

+23
-23
lines changed

7 files changed

+23
-23
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# along with mfterm. If not, see <http://www.gnu.org/licenses/>.
1717

1818
CC = gcc
19-
CFLAGS = -g -Wall -Wconversion -std=c99
19+
CFLAGS = -g -Wall -Wconversion -std=c99 -Werror
2020
LDFLAGS = -g -lreadline -lnfc -lssl -lcrypto
2121

2222
LEX = flex

mac.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ int compute_mac(const unsigned char* input,
7171
* If update is * nonzero, the mac of the current tag is updated. If
7272
* not, the MAC is simply printed.
7373
*/
74-
unsigned char* compute_block_mac(int block,
74+
unsigned char* compute_block_mac(unsigned int block,
7575
const unsigned char* key,
7676
int update) {
7777

mac.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int compute_mac(const unsigned char* input,
4343
* If update is * nonzero, the mac of the current tag is updated. If
4444
* not, the MAC is simply printed.
4545
*/
46-
unsigned char* compute_block_mac(int block,
46+
unsigned char* compute_block_mac(unsigned int block,
4747
const unsigned char* key,
4848
int update);
4949

mifare_ctrl.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ bool mf_read_tag_internal(mf_tag_t* tag,
342342
uint8_t* key = key_from_tag(keys, key_type, block);
343343
if (!mf_authenticate(block, key, key_type)) {
344344
// Progress indication and error report
345-
printf("0x%02x", block_to_sector(block));
345+
printf("0x%02zx", block_to_sector(block));
346346
if (block != 3) printf(".");
347347
fflush(stdout);
348348

@@ -360,7 +360,7 @@ bool mf_read_tag_internal(mf_tag_t* tag,
360360
memcpy(buffer_tag.amb[block].mbt.abtAccessBits,
361361
mp.mpd.abtData + 6, 4);
362362
} else {
363-
printf ("\nUnable to read trailer block: 0x%02x.\n", block);
363+
printf ("\nUnable to read trailer block: 0x%02zx.\n", block);
364364
return false;
365365
}
366366
printf("."); fflush(stdout); // Progress indicator
@@ -370,7 +370,7 @@ bool mf_read_tag_internal(mf_tag_t* tag,
370370
else { // I.e. not a sector trailer
371371
// Try to read out the block
372372
if (!nfc_initiator_mifare_cmd(device, MC_READ, (uint8_t)block, &mp)) {
373-
printf("\nUnable to read block: 0x%02x.\n", block);
373+
printf("\nUnable to read block: 0x%02zx.\n", block);
374374
return false;
375375
}
376376
memcpy(buffer_tag.amb[block].mbd.abtData, mp.mpd.abtData, 0x10);
@@ -412,7 +412,7 @@ bool mf_write_tag_internal(const mf_tag_t* tag,
412412
if (!mf_authenticate(header_block, key, key_type)) {
413413
// Progress indication and error report
414414
if (header_block != 0) printf(".");
415-
printf("0x%02x", block_to_sector(header_block));
415+
printf("0x%02zx", block_to_sector(header_block));
416416
fflush(stdout);
417417

418418
error = 1;
@@ -442,7 +442,7 @@ bool mf_write_tag_internal(const mf_tag_t* tag,
442442

443443
// Write the data block
444444
if (!nfc_initiator_mifare_cmd(device, MC_WRITE, (uint8_t)block, &mp)) {
445-
printf("\nUnable to write block: 0x%02x.\n", block);
445+
printf("\nUnable to write block: 0x%02zx.\n", block);
446446
return false;
447447
}
448448
}
@@ -455,7 +455,7 @@ bool mf_write_tag_internal(const mf_tag_t* tag,
455455

456456
// Try to write the trailer
457457
if (!nfc_initiator_mifare_cmd(device, MC_WRITE, (uint8_t)trailer_block, &mp)) {
458-
printf("\nUnable to write block: 0x%02x.\n", trailer_block);
458+
printf("\nUnable to write block: 0x%02zx.\n", trailer_block);
459459
return false;
460460
}
461461

@@ -485,7 +485,7 @@ bool mf_dictionary_attack_internal(mf_tag_t* tag) {
485485
block_it = sector_header_iterator(size)) {
486486
size_t block = (size_t)block_it;
487487

488-
printf("Working on sector: %02x [", block_to_sector(block));
488+
printf("Working on sector: %02zx [", block_to_sector(block));
489489

490490
const uint8_t* key_a = NULL;
491491
const uint8_t* key_b = NULL;
@@ -566,7 +566,7 @@ bool mf_test_auth_internal(const mf_tag_t* keys,
566566
size_t block = (size_t)block_it;
567567

568568
uint8_t* key = key_from_tag(keys, key_type, block);
569-
printf("%02x %c %s ",
569+
printf("%02zx %c %s ",
570570
block_to_sector(block),
571571
key_type,
572572
sprint_key(key));

spec_syntax.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ void print_instance_tree() {
557557
return;
558558
}
559559

560-
printf("[%d, %d] [%d, %d] -- . (root)\n",
560+
printf("[%zu, %zu] [%zu, %zu] -- . (root)\n",
561561
instance_root->offset_bytes,
562562
instance_root->offset_bits,
563563
instance_root->size_bytes,
@@ -590,7 +590,7 @@ void print_instance_tree_(instance_t* root, int indent) {
590590

591591
void print_instance_(instance_t* i) {
592592
if (i->field->type == &byte_type) {
593-
printf("[%d, %d] [%d, %d] -- Byte[%d] %s\n",
593+
printf("[%zu, %zu] [%zu, %zu] -- Byte[%zu] %s\n",
594594
i->offset_bytes,
595595
i->offset_bits,
596596
i->size_bytes,
@@ -599,7 +599,7 @@ void print_instance_(instance_t* i) {
599599
i->field->name);
600600
}
601601
else if (i->field->type == &bit_type) {
602-
printf("[%d, %d] [%d, %d] -- Bit[%d] %s\n",
602+
printf("[%zu, %zu] [%zu, %zu] -- Bit[%zu] %s\n",
603603
i->offset_bytes,
604604
i->offset_bits,
605605
i->size_bytes,
@@ -608,7 +608,7 @@ void print_instance_(instance_t* i) {
608608
i->field->name);
609609
}
610610
else {
611-
printf("[%d, %d] [%d, %d] -- %s[%d] %s\n",
611+
printf("[%zu, %zu] [%zu, %zu] -- %s[%zu] %s\n",
612612
i->offset_bytes,
613613
i->offset_bits,
614614
i->size_bytes,

tag.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void print_tag_bytes(size_t first_byte, size_t last_byte) {
167167
void print_tag_data_range(size_t byte_offset, size_t bit_offset,
168168
size_t byte_len, size_t bit_len) {
169169

170-
printf("Offset: [%d, %d] Length: [%d, %d]\n",
170+
printf("Offset: [%zu, %zu] Length: [%zu, %zu]\n",
171171
byte_offset, bit_offset, byte_len, bit_len);
172172

173173
// Print partial first byte
@@ -216,11 +216,11 @@ void print_tag_block_range(size_t first, size_t last) {
216216
for (size_t block = first; block <= last; ++block) {
217217

218218
// Sector number
219-
printf("%02x ",
219+
printf("%02zx ",
220220
block < 0x10*4 ? block / 4 : 0x10 + (block - 0x10*4) / 0x10);
221221

222222
// Block number
223-
printf("%02x ", block);
223+
printf("%02zx ", block);
224224

225225
// then print the block data
226226
print_hex_array_sep(current_tag.amb[block].mbd.abtData,
@@ -293,11 +293,11 @@ void print_ac(const mf_tag_t* tag) {
293293
for (size_t block = 0; block < 0x10 * 4; ++block) {
294294

295295
// Sector number
296-
printf("%02x ",
296+
printf("%02zx ",
297297
block < 0x10*4 ? block / 4 : 0x10 + (block - 0x10*4) / 0x10);
298298

299299
// Block number
300-
printf("%02x ", block);
300+
printf("%02zx ", block);
301301

302302
const uint8_t* ac = tag->amb[block_to_trailer(block)].mbt.abtAccessBits;
303303

term_cmd.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ int com_set(char* arg) {
277277
return -1;
278278
}
279279

280-
int block = strtol(block_str, &block_str, 16);
280+
unsigned int block = (unsigned int) strtoul(block_str, &block_str, 16);
281281
if (*block_str != '\0') {
282282
printf("Invalid block character (non hex): %s\n", block_str);
283283
return -1;
@@ -287,7 +287,7 @@ int com_set(char* arg) {
287287
return -1;
288288
}
289289

290-
int offset = strtol(offset_str, &offset_str, 16);
290+
unsigned int offset = (unsigned int) strtoul(offset_str, &offset_str, 16);
291291
if (*offset_str != '\0') {
292292
printf("Invalid offset character (non hex): %s\n", offset_str);
293293
return -1;
@@ -636,7 +636,7 @@ int com_mac_block_compute_impl(char* arg, int update) {
636636
return -1;
637637
}
638638

639-
int block = strtol(block_str, &block_str, 16);
639+
unsigned int block = (unsigned int) strtoul(block_str, &block_str, 16);
640640
if (*block_str != '\0') {
641641
printf("Invalid block character (non hex): %s\n", block_str);
642642
return -1;

0 commit comments

Comments
 (0)