mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] test: self: malloc: hide allocation size from compiler
@ 2023-11-09 13:38 Ahmad Fatoum
  2023-11-10 13:25 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2023-11-09 13:38 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Once we start annotating malloc with __attribute((alloc_size)), GCC will
detect that we intentionally buffers that are too big.

Avoid the warning by hiding the size using the RELOC_HIDE macro.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 test/self/malloc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/test/self/malloc.c b/test/self/malloc.c
index 47c225ac6a10..0feec810185f 100644
--- a/test/self/malloc.c
+++ b/test/self/malloc.c
@@ -85,11 +85,11 @@ static void test_malloc(void)
 	free(p);
 
 	if (mem_malloc_size) {
-		tmp = expect_alloc_fail(malloc(SIZE_MAX));
+		tmp = expect_alloc_fail(malloc(RELOC_HIDE(SIZE_MAX, 0)));
 		free(tmp);
 
 		if (0xf0000000 > mem_malloc_size) {
-			tmp = expect_alloc_fail(malloc(0xf0000000));
+			tmp = expect_alloc_fail(malloc(RELOC_HIDE(0xf0000000, 0)));
 			free(tmp);
 		}
 	} else {
@@ -111,11 +111,11 @@ static void test_malloc(void)
 		free(tmp);
 
 		if (0xf0000000 > mem_malloc_size) {
-			tmp = expect_alloc_fail(realloc(p, 0xf0000000));
+			tmp = expect_alloc_fail(realloc(p, RELOC_HIDE(0xf0000000, 0)));
 			free(tmp);
 		}
 
-		tmp = expect_alloc_fail(realloc(p, SIZE_MAX));
+		tmp = expect_alloc_fail(realloc(p, RELOC_HIDE(SIZE_MAX, 0)));
 		free(tmp);
 
 	} else {
-- 
2.39.2




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] test: self: malloc: hide allocation size from compiler
  2023-11-09 13:38 [PATCH] test: self: malloc: hide allocation size from compiler Ahmad Fatoum
@ 2023-11-10 13:25 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2023-11-10 13:25 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Thu, Nov 09, 2023 at 02:38:12PM +0100, Ahmad Fatoum wrote:
> Once we start annotating malloc with __attribute((alloc_size)), GCC will
> detect that we intentionally buffers that are too big.
> 
> Avoid the warning by hiding the size using the RELOC_HIDE macro.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  test/self/malloc.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/test/self/malloc.c b/test/self/malloc.c
> index 47c225ac6a10..0feec810185f 100644
> --- a/test/self/malloc.c
> +++ b/test/self/malloc.c
> @@ -85,11 +85,11 @@ static void test_malloc(void)
>  	free(p);
>  
>  	if (mem_malloc_size) {
> -		tmp = expect_alloc_fail(malloc(SIZE_MAX));
> +		tmp = expect_alloc_fail(malloc(RELOC_HIDE(SIZE_MAX, 0)));
>  		free(tmp);
>  
>  		if (0xf0000000 > mem_malloc_size) {
> -			tmp = expect_alloc_fail(malloc(0xf0000000));
> +			tmp = expect_alloc_fail(malloc(RELOC_HIDE(0xf0000000, 0)));
>  			free(tmp);
>  		}
>  	} else {
> @@ -111,11 +111,11 @@ static void test_malloc(void)
>  		free(tmp);
>  
>  		if (0xf0000000 > mem_malloc_size) {
> -			tmp = expect_alloc_fail(realloc(p, 0xf0000000));
> +			tmp = expect_alloc_fail(realloc(p, RELOC_HIDE(0xf0000000, 0)));
>  			free(tmp);
>  		}
>  
> -		tmp = expect_alloc_fail(realloc(p, SIZE_MAX));
> +		tmp = expect_alloc_fail(realloc(p, RELOC_HIDE(SIZE_MAX, 0)));
>  		free(tmp);
>  
>  	} else {
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-11-10 13:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-09 13:38 [PATCH] test: self: malloc: hide allocation size from compiler Ahmad Fatoum
2023-11-10 13:25 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox