Skip to content

Commit 33263d7

Browse files
authored
Merge pull request #5166 from liukangcc/finsh
[update] fix finsh_getchar() 未对 shell->device 为空处理的问题
2 parents 4351507 + c99dfc3 commit 33263d7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

components/finsh/shell.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,19 @@ char finsh_getchar(void)
151151
char ch = 0;
152152

153153
RT_ASSERT(shell != RT_NULL);
154+
if (shell->device == RT_NULL)
155+
{
156+
return -RT_ERROR;
157+
}
154158
while (rt_device_read(shell->device, -1, &ch, 1) != 1)
155159
rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER);
156160

157161
return ch;
158-
#endif
162+
#endif /* RT_USING_POSIX */
159163
#else
160164
extern char rt_hw_console_getchar(void);
161165
return rt_hw_console_getchar();
162-
#endif
166+
#endif /* RT_USING_DEVICE */
163167
}
164168

165169
#if !defined(RT_USING_POSIX) && defined(RT_USING_DEVICE)

0 commit comments

Comments
 (0)