summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorgbcwbz <[email protected]>2019-02-21 21:18:30 +0800
committergbcwbz <[email protected]>2019-03-10 15:50:03 +0800
commit860f8d954d7f99971fe8c12fd3195870c52940fb (patch)
treef2f84c7a78835c77a5b247973b2665890e1cfdb0 /components
parent6a12704bc6a5ca96a18c15bb6cea0787b8d81e12 (diff)
[finsh] change return type of finsh_getchar from ch to int
finsh_getchar invokes getchar, who's return type is int, and return value may < 0, which means error occurred or EOF. finsh should handle that situation properly, and inform user about the error.
Diffstat (limited to 'components')
-rw-r--r--components/finsh/shell.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/components/finsh/shell.c b/components/finsh/shell.c
index f96e1f8928..61c8d3dd15 100644
--- a/components/finsh/shell.c
+++ b/components/finsh/shell.c
@@ -134,12 +134,12 @@ void finsh_set_prompt_mode(rt_uint32_t prompt_mode)
shell->prompt_mode = prompt_mode;
}
-static char finsh_getchar(void)
+static int finsh_getchar(void)
{
#ifdef RT_USING_POSIX
return getchar();
#else
- char ch;
+ int ch;
RT_ASSERT(shell != RT_NULL);
while (rt_device_read(shell->device, -1, &ch, 1) != 1)
@@ -279,7 +279,7 @@ const char *finsh_get_password(void)
static void finsh_wait_auth(void)
{
- char ch;
+ int ch;
rt_bool_t input_finish = RT_FALSE;
char password[FINSH_PASSWORD_MAX] = { 0 };
rt_size_t cur_pos = 0;
@@ -295,6 +295,11 @@ static void finsh_wait_auth(void)
{
/* read one character from device */
ch = finsh_getchar();
+ if (ch < 0)
+ {
+ rt_kprintf("finsh getchar error\n");
+ continue;
+ }
if (ch >= ' ' && ch <= '~' && cur_pos < FINSH_PASSWORD_MAX)
{
@@ -460,7 +465,7 @@ static void shell_push_history(struct finsh_shell *shell)
void finsh_thread_entry(void *parameter)
{
- char ch;
+ int ch;
/* normal is echo mode */
#ifndef FINSH_ECHO_DISABLE_DEFAULT
@@ -503,6 +508,11 @@ void finsh_thread_entry(void *parameter)
while (1)
{
ch = finsh_getchar();
+ if (ch < 0)
+ {
+ rt_kprintf("finsh getchar error\n");
+ continue;
+ }
/*
* handle control key