question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG]: _Noreturn cancels printf

See original GitHub issue

Describe the bug

_Noreturn cancels printf.

Steps to reproduce

https://godbolt.org/z/efvMcnKeq

Expected behavior

Expected output:

xxx
zzz

Actual output:

<nothing>

Reproduction link

https://godbolt.org/z/efvMcnKeq

Screenshots

Not applicable

Operating System

No response

Browser version

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
jeremy-rifkincommented, Apr 25, 2022

It’s undefined to return from a _Noreturn function, I’d say the expected behavior is anything from xxx zzz to summoning the Kraken 😛

That being said the reason nothing happens to show up here is that stdout’s buffer isn’t flushed before the program segfaults. If you add setvbuf(stdout, NULL, _IONBF, 0); to main the output is:

Program returned: 139
xxx
zzz
0reactions
jeremy-rifkincommented, Apr 25, 2022

For glibc at least no flushing is performed https://code.woboq.org/userspace/glibc/stdlib/abort.c.html#abort

Read more comments on GitHub >

github_iconTop Results From Across the Web

Functions with "noreturn" attribute should not return
Unique rules to find Bugs, Vulnerabilities, Security Hotspots, ... Printf-style format strings should not lead to unexpected behavior at runtime. Bug ...
Read more >
Function Attributes - Using the GNU Compiler Collection (GCC)
The following attributes are currently defined for functions on all targets: aligned , alloc_size , noreturn , returns_twice , noinline , noclone ...
Read more >
_Noreturn function specifier in C - Tutorialspoint
The program terminates abnormally [Warning] function declared 'noreturn' has a 'return' statement. Now if it is a normal function it will ...
Read more >
6.26. Declaring Attributes of Functions
The noreturn keyword tells the compiler to assume that fatal cannot return. It can then optimize without regard to what would happen if...
Read more >
Bugs in C - The Craft of Coding
6 printf(“Enter a number: “). 7 scanf(“%d”, &a);. The gcc C compiler might generate the following error message: error.c: In function 'main':.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found