Ver Fonte

[update] fix finsh_getchar() 未对 shell->device 为空处理的问题

liukangcc há 3 anos atrás
pai
commit
c99dfc3147
1 ficheiros alterados com 6 adições e 2 exclusões
  1. 6 2
      components/finsh/shell.c

+ 6 - 2
components/finsh/shell.c

@@ -151,15 +151,19 @@ char finsh_getchar(void)
     char ch = 0;
     char ch = 0;
 
 
     RT_ASSERT(shell != RT_NULL);
     RT_ASSERT(shell != RT_NULL);
+    if (shell->device == RT_NULL)
+    {
+        return -RT_ERROR;
+    }
     while (rt_device_read(shell->device, -1, &ch, 1) != 1)
     while (rt_device_read(shell->device, -1, &ch, 1) != 1)
         rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER);
         rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER);
 
 
     return ch;
     return ch;
-#endif
+#endif /* RT_USING_POSIX */
 #else
 #else
     extern char rt_hw_console_getchar(void);
     extern char rt_hw_console_getchar(void);
     return rt_hw_console_getchar();
     return rt_hw_console_getchar();
-#endif
+#endif /* RT_USING_DEVICE */
 }
 }
 
 
 #if !defined(RT_USING_POSIX) && defined(RT_USING_DEVICE)
 #if !defined(RT_USING_POSIX) && defined(RT_USING_DEVICE)