Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

printf stops printing after first newline #44

Closed
jmattsson opened this issue Oct 6, 2016 · 4 comments
Closed

printf stops printing after first newline #44

jmattsson opened this issue Oct 6, 2016 · 4 comments
Labels
Resolution: Done Issue is done internally Resolution: Won't Do This will not be worked on Status: Done Issue is done internally

Comments

@jmattsson
Copy link

It appears that for some strange reason the regular C printf() function stops printing when it encounters the first newline (\n) in a string. This can be trivially reproduced by attempting to print two lines in the one call; see below for a patch to the official 01_hello_world example.

diff --git i/examples/01_hello_world/main/hello_world_main.c w/examples/01_hello_world/main/hello_world_main.c
index ad2c0ac..ca907ea 100644
--- i/examples/01_hello_world/main/hello_world_main.c
+++ w/examples/01_hello_world/main/hello_world_main.c
@@ -14,7 +14,7 @@

 void hello_task(void *pvParameter)
 {
-    printf("Hello world!\n");
+    printf("Hello world!\nHiding in plain sight...\n");
     for (int i = 10; i >= 0; i--) {
         printf("Restarting in %d seconds...\n", i);
         vTaskDelay(1000 / portTICK_RATE_MS);

Despite applying the above patch, the output stays at:

Hello world!

If using the %s modifier, a newline in the argument string also causes printf() to stop outputting characters, effectively cutting short the output. E.g.

printf("Hello%s world!\n", "Hiding\n in plain sight...");

yields the following output:

HelloHiding
@projectgus
Copy link
Contributor

projectgus commented Oct 6, 2016

That @jmattsson . I committed a patch for this into our review queue yesterday, it's a bug in the write syscall.

Because everyone's on holidays this week I'm not sure if we'll get the fix merged to github until next week (review policy), but I might be able to pop up a temporary branch.

@jmattsson
Copy link
Author

Really? I instrumented _write_r() but by the time it got there the string had already been truncated at the \n.

@projectgus
Copy link
Contributor

Yeah it's not an obvious bug though., _write_r should return number of bytes written, but doesn't. Stdout is line buffered by default: so the first line gets sent to _write_r & TXed,, _write_r returns zero, newlib discards the rest of the buffer thinking there was an error.

Fix is incoming now, should be auto-pushed github shortly...

@igrr igrr closed this as completed in 12caaed Oct 6, 2016
@jmattsson
Copy link
Author

Ah, sneaky bug! Glad it was an easy fix though.

igrr added a commit that referenced this issue Nov 29, 2018
Fix VFS unit test failure ("Open & write & close through VFS passes performance test")

Closes #44

See merge request idf/esp-idf!3759
@espressif-bot espressif-bot added the Status: Opened Issue is new label Mar 1, 2022
mikkeldamsgaard pushed a commit to mikkeldamsgaard/esp-idf that referenced this issue Mar 26, 2022
Cherry pixk of bug espressif#7631
See espressif#7631

Co-authored-by: Victor Morales <chipahuac@hotmail.com>
@espressif-bot espressif-bot added Status: In Progress Work is in progress and removed Status: Opened Issue is new labels May 4, 2022
@espressif-bot espressif-bot added Resolution: Won't Do This will not be worked on Status: Done Issue is done internally Status: Opened Issue is new and removed Status: In Progress Work is in progress labels May 27, 2022
@espressif-bot espressif-bot added Status: In Progress Work is in progress and removed Status: Opened Issue is new labels Jun 3, 2022
@espressif-bot espressif-bot added Resolution: Done Issue is done internally and removed Status: In Progress Work is in progress labels Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Resolution: Won't Do This will not be worked on Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

3 participants