Skip to content

Commit 7e67f93

Browse files
committed
Use PRIu32 and PRIx32 format specifiers to fix warnings
When using "%d" or "%x" with uint32_t types, arm-none-eabi-gcc reports warnings like below: -- >8 -- >8 -- >8 -- >8 -- >8 -- >8 -- In file included from lfs.c:8: lfs_util.h:45:12: warning: format '%d' expects argument of type 'int', but argument 4 has type 'lfs_block_t' {aka 'long unsigned int'} [-Wformat=] printf("lfs debug:%d: " fmt "\n", __LINE__, __VA_ARGS__) ^~~~~~~~~~~~~~~~ lfs.c:2512:21: note: in expansion of macro 'LFS_DEBUG' LFS_DEBUG("Found partial move %d %d", ^~~~~~~~~ lfs.c:2512:55: note: format string is defined here LFS_DEBUG("Found partial move %d %d", ~^ %ld -- >8 -- >8 -- >8 -- >8 -- >8 -- >8 -- Fix this by replacing "%d" and "%x" with `"%" PRIu32` and `"%" PRIx32`.
1 parent 5a17fa4 commit 7e67f93

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

emubd/lfs_emubd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <unistd.h>
1717
#include <assert.h>
1818
#include <stdbool.h>
19+
#include <inttypes.h>
1920

2021

2122
// Block device emulated on existing filesystem
@@ -85,7 +86,7 @@ int lfs_emubd_read(const struct lfs_config *cfg, lfs_block_t block,
8586
memset(data, 0, size);
8687

8788
// Read data
88-
snprintf(emu->child, LFS_NAME_MAX, "%x", block);
89+
snprintf(emu->child, LFS_NAME_MAX, "%" PRIx32, block);
8990

9091
FILE *f = fopen(emu->path, "rb");
9192
if (!f && errno != ENOENT) {
@@ -124,7 +125,7 @@ int lfs_emubd_prog(const struct lfs_config *cfg, lfs_block_t block,
124125
assert(block < cfg->block_count);
125126

126127
// Program data
127-
snprintf(emu->child, LFS_NAME_MAX, "%x", block);
128+
snprintf(emu->child, LFS_NAME_MAX, "%" PRIx32, block);
128129

129130
FILE *f = fopen(emu->path, "r+b");
130131
if (!f) {
@@ -171,7 +172,7 @@ int lfs_emubd_erase(const struct lfs_config *cfg, lfs_block_t block) {
171172
assert(block < cfg->block_count);
172173

173174
// Erase the block
174-
snprintf(emu->child, LFS_NAME_MAX, "%x", block);
175+
snprintf(emu->child, LFS_NAME_MAX, "%" PRIx32, block);
175176
struct stat st;
176177
int err = stat(emu->path, &st);
177178
if (err && errno != ENOENT) {
@@ -239,4 +240,3 @@ int lfs_emubd_sync(const struct lfs_config *cfg) {
239240

240241
return 0;
241242
}
242-

lfs.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "lfs.h"
88
#include "lfs_util.h"
99

10+
#include <inttypes.h>
11+
1012

1113
/// Caching block device operations ///
1214
static int lfs_cache_read(lfs_t *lfs, lfs_cache_t *rcache,
@@ -308,7 +310,8 @@ static int lfs_alloc(lfs_t *lfs, lfs_block_t *block) {
308310

309311
// check if we have looked at all blocks since last ack
310312
if (lfs->free.ack == 0) {
311-
LFS_WARN("No more free space %d", lfs->free.i + lfs->free.off);
313+
LFS_WARN("No more free space %" PRIu32,
314+
lfs->free.i + lfs->free.off);
312315
return LFS_ERR_NOSPC;
313316
}
314317

@@ -478,7 +481,8 @@ static int lfs_dir_fetch(lfs_t *lfs,
478481
}
479482

480483
if (!valid) {
481-
LFS_ERROR("Corrupted dir pair at %d %d", tpair[0], tpair[1]);
484+
LFS_ERROR("Corrupted dir pair at %" PRIu32 " %" PRIu32 ,
485+
tpair[0], tpair[1]);
482486
return LFS_ERR_CORRUPT;
483487
}
484488

@@ -601,15 +605,16 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_dir_t *dir,
601605
break;
602606
relocate:
603607
//commit was corrupted
604-
LFS_DEBUG("Bad block at %d", dir->pair[0]);
608+
LFS_DEBUG("Bad block at %" PRIu32, dir->pair[0]);
605609

606610
// drop caches and prepare to relocate block
607611
relocated = true;
608612
lfs_cache_drop(lfs, &lfs->pcache);
609613

610614
// can't relocate superblock, filesystem is now frozen
611615
if (lfs_paircmp(oldpair, (const lfs_block_t[2]){0, 1}) == 0) {
612-
LFS_WARN("Superblock %d has become unwritable", oldpair[0]);
616+
LFS_WARN("Superblock %" PRIu32 " has become unwritable",
617+
oldpair[0]);
613618
return LFS_ERR_CORRUPT;
614619
}
615620

@@ -622,7 +627,7 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_dir_t *dir,
622627

623628
if (relocated) {
624629
// update references if we relocated
625-
LFS_DEBUG("Relocating %d %d to %d %d",
630+
LFS_DEBUG("Relocating %" PRIu32 " %" PRIu32 " to %" PRIu32 " %" PRIu32,
626631
oldpair[0], oldpair[1], dir->pair[0], dir->pair[1]);
627632
int err = lfs_relocate(lfs, oldpair, dir->pair);
628633
if (err) {
@@ -1227,7 +1232,7 @@ static int lfs_ctz_extend(lfs_t *lfs,
12271232
}
12281233

12291234
relocate:
1230-
LFS_DEBUG("Bad block at %d", nblock);
1235+
LFS_DEBUG("Bad block at %" PRIu32, nblock);
12311236

12321237
// just clear cache and try a new block
12331238
lfs_cache_drop(lfs, &lfs->pcache);
@@ -1384,7 +1389,7 @@ int lfs_file_close(lfs_t *lfs, lfs_file_t *file) {
13841389

13851390
static int lfs_file_relocate(lfs_t *lfs, lfs_file_t *file) {
13861391
relocate:
1387-
LFS_DEBUG("Bad block at %d", file->block);
1392+
LFS_DEBUG("Bad block at %" PRIu32, file->block);
13881393

13891394
// just relocate what exists into new block
13901395
lfs_block_t nblock;
@@ -2395,7 +2400,8 @@ static int lfs_relocate(lfs_t *lfs,
23952400

23962401
// update internal root
23972402
if (lfs_paircmp(oldpair, lfs->root) == 0) {
2398-
LFS_DEBUG("Relocating root %d %d", newpair[0], newpair[1]);
2403+
LFS_DEBUG("Relocating root %" PRIu32 " %" PRIu32,
2404+
newpair[0], newpair[1]);
23992405
lfs->root[0] = newpair[0];
24002406
lfs->root[1] = newpair[1];
24012407
}
@@ -2451,7 +2457,7 @@ int lfs_deorphan(lfs_t *lfs) {
24512457

24522458
if (!res) {
24532459
// we are an orphan
2454-
LFS_DEBUG("Found orphan %d %d",
2460+
LFS_DEBUG("Found orphan %" PRIu32 " %" PRIu32,
24552461
pdir.d.tail[0], pdir.d.tail[1]);
24562462

24572463
pdir.d.tail[0] = cwd.d.tail[0];
@@ -2467,7 +2473,7 @@ int lfs_deorphan(lfs_t *lfs) {
24672473

24682474
if (!lfs_pairsync(entry.d.u.dir, pdir.d.tail)) {
24692475
// we have desynced
2470-
LFS_DEBUG("Found desync %d %d",
2476+
LFS_DEBUG("Found desync %" PRIu32 " %" PRIu32,
24712477
entry.d.u.dir[0], entry.d.u.dir[1]);
24722478

24732479
pdir.d.tail[0] = entry.d.u.dir[0];
@@ -2502,14 +2508,14 @@ int lfs_deorphan(lfs_t *lfs) {
25022508
}
25032509

25042510
if (moved) {
2505-
LFS_DEBUG("Found move %d %d",
2511+
LFS_DEBUG("Found move %" PRIu32 " %" PRIu32,
25062512
entry.d.u.dir[0], entry.d.u.dir[1]);
25072513
err = lfs_dir_remove(lfs, &cwd, &entry);
25082514
if (err) {
25092515
return err;
25102516
}
25112517
} else {
2512-
LFS_DEBUG("Found partial move %d %d",
2518+
LFS_DEBUG("Found partial move %" PRIu32 " %" PRIu32,
25132519
entry.d.u.dir[0], entry.d.u.dir[1]);
25142520
entry.d.type &= ~0x80;
25152521
err = lfs_dir_update(lfs, &cwd, &entry, NULL);
@@ -2525,4 +2531,3 @@ int lfs_deorphan(lfs_t *lfs) {
25252531

25262532
return 0;
25272533
}
2528-

0 commit comments

Comments
 (0)