Re: cc1plus: note: source object is likely at address zero
Andrew C Aitchison via Gcc-help <[email protected]> Thu, 5 Mar 2026 13:33:27 +0000 (GMT)
| Newsgroups | gmane.comp.gcc.help |
|---|---|
| Message-ID | <[email protected]> |
On Thu, 5 Mar 2026, Jonny Grant wrote:
> Hello
>
> Is there a way to make these "notes" appear as warnings? That can then be upgraded to errors by -Werror
>
> https://godbolt.org/z/4ae71rfj8
>
> #include <string>
> #include <cstdio>
>
> typedef struct a
> {
> int a;
> int b;
> char buf[10];
> } a_t;
>
> int main()
> {
> a_t * i;
> i = nullptr;
> printf("%s\n", i->buf);
> }
>
> <source>: In function 'int main()':
> <source>:18:11: warning: 'int __builtin_puts(const char*)' reading 1 or more bytes from a region of size 0 [-Wstringop-overread]
> 18 | printf("%s\n", i->buf);
> | ~~~~~~^~~~~~~~~~~~~~~~
> cc1plus: note: source object is likely at address zero
> ASM generation compiler returned: 0
> <source>: In function 'int main()':
> <source>:18:11: warning: 'int __builtin_puts(const char*)' reading 1 or more bytes from a region of size 0 [-Wstringop-overread]
> 18 | printf("%s\n", i->buf);
> | ~~~~~~^~~~~~~~~~~~~~~~
> cc1plus: note: source object is likely at address zero
> Execution build compiler returned: 0
> Program returned: 139
That godbolt link uses options
-stdc=c++23 -O1 -Wall
but I get the same output with
-std=c++11 -Og -Wstringop-overread
but with "-O0" or with no -O option at all the warning disappears.
--
Andrew C. Aitchison Kendal, UK
[email protected]