diff options
author | Evan Green <evgreen@chromium.org> | 2019-08-01 16:04:42 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-10-05 00:47:33 +0000 |
commit | a41fea6b7df1c83072140c0da9e07f09a8b032e4 (patch) | |
tree | 283880db1385c93420de304b410a3bccafa90971 /test | |
parent | 4a29d2ecf4392cb995548e8f174cc85bac8361c1 (diff) | |
download | chrome-ec-a41fea6b7df1c83072140c0da9e07f09a8b032e4.tar.gz |
printf: Fix up %p to %pP
In order to avoid landmines later with future extensions to %p,
disallow %p by itself. The danger is that we'll have something
like: printf("%pFOO", myptr), and then later will add a %pF
extension, but miss this printf (maybe the string is split, maybe
it's just missed).
Missing a conversion during extension is worse than just seeing a
print like <ptr_val>OO, since %pF likely reaches through the
pointer and interprets its contents according to whatever F means.
Convert existing uses of %p to %pP, so they're explicitly printing
a pointer value, giving us flexibility to extend in the future.
BUG=chromium:984041
TEST=make -j buildall
BRANCH=None
Cq-Depend:chrome-internal:1560879
Change-Id: I36a4bee8d41cb9a6139171f8de0d8f2f19468132
Signed-off-by: Evan Green <evgreen@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1730604
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/nvmem.c | 6 | ||||
-rw-r--r-- | test/nvmem_tpm2_mock.c | 4 | ||||
-rw-r--r-- | test/printf.c | 14 | ||||
-rw-r--r-- | test/shmalloc.c | 8 |
4 files changed, 22 insertions, 10 deletions
diff --git a/test/nvmem.c b/test/nvmem.c index df5457273b..8eaad92f23 100644 --- a/test/nvmem.c +++ b/test/nvmem.c @@ -211,8 +211,8 @@ static int iterate_over_flash(void) return EC_SUCCESS; } } - ccprintf("%s:%d bad delimiter location: ph %p, " - "dt.ph %p, offset %d, delim offset %d\n", + ccprintf("%s:%d bad delimiter location: ph %pP, " + "dt.ph %pP, offset %d, delim offset %d\n", __func__, __LINE__, at.mt.ph, at.dt.ph, at.mt.data_offset, at.dt.data_offset); @@ -654,7 +654,7 @@ static size_t fill_obj_offsets(uint16_t *offsets, size_t max_objects) uint32_t *op; op = evictable_offs_to_addr(offsets[i]); - ccprintf("offs %04x:%08x:%08x:%08x addr %p size %d\n", + ccprintf("offs %04x:%08x:%08x:%08x addr %pP size %d\n", offsets[i], op[-1], op[0], op[1], op, (uintptr_t)nvmem_cache_base(NVMEM_TPM) + op[-1] - (uintptr_t)op); diff --git a/test/nvmem_tpm2_mock.c b/test/nvmem_tpm2_mock.c index 070525406d..3b2e5340ad 100644 --- a/test/nvmem_tpm2_mock.c +++ b/test/nvmem_tpm2_mock.c @@ -331,8 +331,8 @@ void drop_evictable_obj(void *obj) obj_addr = (uintptr_t)obj - (uintptr_t)nvmem_cache_base(NVMEM_TPM); read_from_cache(obj_addr - sizeof(next_addr), sizeof(next_addr), &next_addr); - ccprintf("%s:%d dropping obj at cache addr %x, offset %x, addr %p next " - "addr %x aka %x (off s_evictNvStart)\n", + ccprintf("%s:%d dropping obj at cache addr %x, offset %x, addr %pP " + "next addr %x aka %x (off s_evictNvStart)\n", __func__, __LINE__, obj_addr - s_evictNvStart, obj_addr, obj, next_addr, next_addr - s_evictNvStart); diff --git a/test/printf.c b/test/printf.c index 7e857dd55c..cf20be7b31 100644 --- a/test/printf.c +++ b/test/printf.c @@ -196,8 +196,20 @@ test_static int test_vsnprintf_pointers(void) { void *ptr = (void *)0x55005E00; - T(expect_success("55005e00", "%p", ptr)); + T(expect_success("55005e00", "%pP", ptr)); T(expect_success(err_str, "%P", ptr)); + /* %p by itself is invalid */ + T(expect(EC_ERROR_INVAL, NO_BYTES_TOUCHED, + /* given -1 as output size limit */ + false, -1, "%p")); + /* %p with an unknown suffix is invalid */ + T(expect(EC_ERROR_INVAL, NO_BYTES_TOUCHED, + /* given -1 as output size limit */ + false, -1, "%p ")); + /* %p with an unknown suffix is invalid */ + T(expect(EC_ERROR_INVAL, NO_BYTES_TOUCHED, + /* given -1 as output size limit */ + false, -1, "%pQ")); return EC_SUCCESS; } diff --git a/test/shmalloc.c b/test/shmalloc.c index d96579c275..b841d7ae1e 100644 --- a/test/shmalloc.c +++ b/test/shmalloc.c @@ -112,7 +112,7 @@ static int check_for_overlaps(void) } } if (!allocation_match) { - ccprintf("missing match %p!\n", allocations[i].buf); + ccprintf("missing match %pP!\n", allocations[i].buf); return 0; } } @@ -137,7 +137,7 @@ static int shmem_is_ok(int line) struct shm_buffer *pbuf = free_buf_chain; if (pbuf && pbuf->prev_buffer) { - ccprintf("Bad free buffer list start %p\n", pbuf); + ccprintf("Bad free buffer list start %pP\n", pbuf); goto bailout; } @@ -153,13 +153,13 @@ static int shmem_is_ok(int line) if (pbuf->next_buffer) { if (top >= pbuf->next_buffer) { ccprintf("%s:%d" - " - inconsistent buffer size at %p\n", + " - inconsistent buffer size at %pP\n", __func__, __LINE__, pbuf); goto bailout; } if (pbuf->next_buffer->prev_buffer != pbuf) { ccprintf("%s:%d" - " - inconsistent next buffer at %p\n", + " - inconsistent next buffer at %pP\n", __func__, __LINE__, pbuf); goto bailout; } |