diff mbox series

kasan: use %zd format for printing size_t

Message ID 20230201071312.2224452-1-arnd@kernel.org (mailing list archive)
State New
Headers show
Series kasan: use %zd format for printing size_t | expand

Commit Message

Arnd Bergmann Feb. 1, 2023, 7:13 a.m. UTC
From: Arnd Bergmann <arnd@arndb.de>

The size_t type depends on the architecture, so %lu does not work
on most 32-bit ones:

In file included from include/kunit/assert.h:13,
                 from include/kunit/test.h:12,
                 from mm/kasan/report.c:12:
mm/kasan/report.c: In function 'describe_object_addr':
include/linux/kern_levels.h:5:25: error: format '%lu' expects argument of type 'long unsigned int', but argument 5 has type 'size_t' {aka 'unsigned int'} [-Werror=format=]
mm/kasan/report.c:270:9: note: in expansion of macro 'pr_err'
  270 |         pr_err("The buggy address is located %d bytes %s of\n"
      |         ^~~~~~

Fixes: 0e301731f558 ("kasan: infer allocation size by scanning metadata")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 mm/kasan/report.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Randy Dunlap Feb. 4, 2023, 6:27 a.m. UTC | #1
On 1/31/23 23:13, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> The size_t type depends on the architecture, so %lu does not work
> on most 32-bit ones:
> 
> In file included from include/kunit/assert.h:13,
>                  from include/kunit/test.h:12,
>                  from mm/kasan/report.c:12:
> mm/kasan/report.c: In function 'describe_object_addr':
> include/linux/kern_levels.h:5:25: error: format '%lu' expects argument of type 'long unsigned int', but argument 5 has type 'size_t' {aka 'unsigned int'} [-Werror=format=]
> mm/kasan/report.c:270:9: note: in expansion of macro 'pr_err'
>   270 |         pr_err("The buggy address is located %d bytes %s of\n"
>       |         ^~~~~~
> 
> Fixes: 0e301731f558 ("kasan: infer allocation size by scanning metadata")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Reviewed-by: Randy Dunlap <rdunlap@infradead.org>
Tested-by: Randy Dunlap <rdunlap@infradead.org>

Thanks.

> ---
>  mm/kasan/report.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/kasan/report.c b/mm/kasan/report.c
> index e0492124e90a..89078f912827 100644
> --- a/mm/kasan/report.c
> +++ b/mm/kasan/report.c
> @@ -268,7 +268,7 @@ static void describe_object_addr(const void *addr, struct kasan_report_info *inf
>  	}
>  
>  	pr_err("The buggy address is located %d bytes %s of\n"
> -	       " %s%lu-byte region [%px, %px)\n",
> +	       " %s%zu-byte region [%px, %px)\n",
>  	       rel_bytes, rel_type, region_state, info->alloc_size,
>  	       (void *)object_addr, (void *)(object_addr + info->alloc_size));
>  }
Andrey Konovalov Feb. 9, 2023, 10:21 p.m. UTC | #2
On Wed, Feb 1, 2023 at 8:13 AM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> The size_t type depends on the architecture, so %lu does not work
> on most 32-bit ones:
>
> In file included from include/kunit/assert.h:13,
>                  from include/kunit/test.h:12,
>                  from mm/kasan/report.c:12:
> mm/kasan/report.c: In function 'describe_object_addr':
> include/linux/kern_levels.h:5:25: error: format '%lu' expects argument of type 'long unsigned int', but argument 5 has type 'size_t' {aka 'unsigned int'} [-Werror=format=]
> mm/kasan/report.c:270:9: note: in expansion of macro 'pr_err'
>   270 |         pr_err("The buggy address is located %d bytes %s of\n"
>       |         ^~~~~~
>
> Fixes: 0e301731f558 ("kasan: infer allocation size by scanning metadata")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  mm/kasan/report.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/kasan/report.c b/mm/kasan/report.c
> index e0492124e90a..89078f912827 100644
> --- a/mm/kasan/report.c
> +++ b/mm/kasan/report.c
> @@ -268,7 +268,7 @@ static void describe_object_addr(const void *addr, struct kasan_report_info *inf
>         }
>
>         pr_err("The buggy address is located %d bytes %s of\n"
> -              " %s%lu-byte region [%px, %px)\n",
> +              " %s%zu-byte region [%px, %px)\n",
>                rel_bytes, rel_type, region_state, info->alloc_size,
>                (void *)object_addr, (void *)(object_addr + info->alloc_size));
>  }
> --
> 2.39.0
>

Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com>

Thanks!
diff mbox series

Patch

diff --git a/mm/kasan/report.c b/mm/kasan/report.c
index e0492124e90a..89078f912827 100644
--- a/mm/kasan/report.c
+++ b/mm/kasan/report.c
@@ -268,7 +268,7 @@  static void describe_object_addr(const void *addr, struct kasan_report_info *inf
 	}
 
 	pr_err("The buggy address is located %d bytes %s of\n"
-	       " %s%lu-byte region [%px, %px)\n",
+	       " %s%zu-byte region [%px, %px)\n",
 	       rel_bytes, rel_type, region_state, info->alloc_size,
 	       (void *)object_addr, (void *)(object_addr + info->alloc_size));
 }