xhh233 commented on issue #4108:
URL: https://github.com/apache/nuttx-apps/issues/4108#issuecomment-7075483800
Patch (applies to master 7196658d; git apply --check rc=0):
```diff
--- a/system/cle/cle.c
+++ b/system/cle/cle.c
@@ -116,6 +116,7 @@
uint16_t coloffs; /* Left cursor offset */
uint16_t linelen; /* Size of the line buffer */
uint16_t nchars; /* Size of data in the line buffer */
+ bool overflow; /* Discarding an overlong line until EOL */
int infd; /* Input file handle */
int outfd; /* Output file handle */
FAR char *line; /* Line buffer */
@@ -993,6 +994,19 @@
case '\n': /* LF terminates line */
{
+ if (priv->overflow)
+ {
+ /* Discard the whole overlong line; never submit its
+ * truncated prefix as a command.
+ */
+
+ priv->overflow = false;
+ priv->nchars = 0;
+ priv->curpos = 0;
+ cle_write(priv, "\r\n", 2);
+ return OK;
+ }
+
/* Add the newline to the buffer at the end of the line */
priv->curpos = priv->nchars;
@@ -1009,15 +1023,31 @@
if (!iscntrl(ch) || ch == '\t')
{
- /* Insert the filtered character into the buffer */
+ if (priv->overflow)
+ {
+ /* Already discarding: consume until EOL. */
+ }
+ else if (priv->nchars + 1 >= priv->linelen)
+ {
+ /* Buffer full: do not keep a truncated prefix that will
+ * be submitted at EOL. Mark overflow and discard.
+ */
- cle_insertch(priv, ch);
+ priv->overflow = true;
+ CLE_BEL(priv);
+ }
+ else
+ {
+ /* Insert the filtered character into the buffer */
- /* Printable character will change the cursor position in */
+ cle_insertch(priv, ch);
- if (ch != '\t')
- {
- priv->realpos++;
+ /* Printable character will change cursor position in */
+
+ if (ch != '\t')
+ {
+ priv->realpos++;
+ }
}
}
else
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]