From f6978132255b2c415736055823afc88ce2774c80 Mon Sep 17 00:00:00 2001 From: Thomas Nyman Date: Tue, 9 Sep 2025 15:05:42 +0200 Subject: [PATCH 1/2] Fix function definition example to show definition instead of declaration Signed-off-by: Thomas Nyman --- .../Compiler-Annotations-for-C-and-C++.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Compiler-Hardening-Guides/Compiler-Annotations-for-C-and-C++.md b/docs/Compiler-Hardening-Guides/Compiler-Annotations-for-C-and-C++.md index 006c7471..6b13ba44 100644 --- a/docs/Compiler-Hardening-Guides/Compiler-Annotations-for-C-and-C++.md +++ b/docs/Compiler-Hardening-Guides/Compiler-Annotations-for-C-and-C++.md @@ -107,7 +107,7 @@ In `__attribute__` keyword syntax: void my_free(void *ptr); // Denotes that my_malloc will return with a dynamically allocated piece of memory which must be freed using my_free. -void *my_malloc(size_t size) __attribute__ ((malloc, malloc (my_free, 1))); +void *my_malloc(size_t size) __attribute__ ((malloc, malloc (my_free, 1))) { … } ~~~ Note that to benefit both from the associated optimizations and improved detection of memory errors functions should be marked with _both_ the form of the attribute without arguments and the form of the attribute with one or two arguments. [[Extended example at Compiler Explorer](https://godbolt.org/z/bc97ahbnd)] From 13b05bbbaed852ee142a62f10b289cbc1bdb114c Mon Sep 17 00:00:00 2001 From: Thomas Nyman Date: Tue, 9 Sep 2025 15:07:23 +0200 Subject: [PATCH 2/2] Remove redundant code from Compiler Annotations for C and C++ examples Signed-off-by: Thomas Nyman --- .../Compiler-Annotations-for-C-and-C++.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/docs/Compiler-Hardening-Guides/Compiler-Annotations-for-C-and-C++.md b/docs/Compiler-Hardening-Guides/Compiler-Annotations-for-C-and-C++.md index 6b13ba44..787d796e 100644 --- a/docs/Compiler-Hardening-Guides/Compiler-Annotations-for-C-and-C++.md +++ b/docs/Compiler-Hardening-Guides/Compiler-Annotations-for-C-and-C++.md @@ -104,8 +104,6 @@ void * my_malloc(size_t size) [[gnu::malloc]] [[gnu::malloc(my_free, 1)]]; In `__attribute__` keyword syntax: ~~~c -void my_free(void *ptr); - // Denotes that my_malloc will return with a dynamically allocated piece of memory which must be freed using my_free. void *my_malloc(size_t size) __attribute__ ((malloc, malloc (my_free, 1))) { … } ~~~ @@ -365,13 +363,6 @@ In C++11 / C23 attribute syntax: ~~~c // Denotes that fatal will never return void fatal () [[noreturn]]; - -void -fatal (...) -{ - ... /* Print error message. */ ... - exit (1); -} ~~~ In `__attribute__` keyword syntax: