Skip to content

Commit

Permalink
Address crashes on linput's use of printf.
Browse files Browse the repository at this point in the history
On an empty line input, a C3 with UART console would panic while attempting
to output the new Lua prompt. The backtrace shows a xQueueSemaphoreTake
with uxItemSize==0 as the panic cause, deep inside the uart driver, invoked
via vfs_uart and vfs_console layers, from printf.
Similarly, the printf for outputting a backspace/erase sequence would also
trigger a panic.

This workaround (of not mixing fflush() with printf) is likely merely hiding
a deeper issue, but it appears to be consistent. Plus, printf with no args
and a user-supplied format string is a no-no and should be fixed anyway.
  • Loading branch information
jmattsson committed Feb 28, 2024
1 parent 0c9a7a2 commit bae0174
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions components/lua/common/linput.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "lua.h"
#include "lauxlib.h"
#include <stdio.h>
#include <string.h>

static struct input_state {
char *data;
Expand Down Expand Up @@ -59,7 +60,7 @@ size_t feed_lua_input(const char *buf, size_t n)
/* backspace key */
if (ch == DEL || ch == BS) {
if (ins.line_pos > 0) {
if(input_echo) printf(BS_OVER);
if(input_echo) fwrite(BS_OVER, strlen(BS_OVER), 1, stdout);
ins.line_pos--;
}
ins.data[ins.line_pos] = 0;
Expand All @@ -73,7 +74,7 @@ size_t feed_lua_input(const char *buf, size_t n)
if (input_echo) putchar(LF);
if (ins.line_pos == 0) {
/* Get a empty line, then go to get a new line */
printf(ins.prompt);
fwrite(ins.prompt, strlen(ins.prompt), 1, stdout);
fflush(stdout);
} else {
ins.data[ins.line_pos++] = LF;
Expand Down

0 comments on commit bae0174

Please sign in to comment.