diff --git a/ChangeLog.txt b/ChangeLog.txt index a9450b5d3..7a1caf2a6 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -813,8 +813,7 @@ 6.34 2014-xx-xx Gregory Nutt * apps/system/cle: Add a EMACS-like command line editor. This CLE, - is really more like readline than the NuttX readline is! Not fully - fully on initial checkout (2014-02-02). + is really more like readline than the NuttX readline is! (2014-02-02). * apps/nshlib: Use of the standard tiney readline (about .25KB) is now an option and can be replaces with the EMACX-like CLE (about 2KB) (2014-02-02). diff --git a/system/cle/cle.c b/system/cle/cle.c index 04d24bbec..f978327ea 100644 --- a/system/cle/cle.c +++ b/system/cle/cle.c @@ -536,7 +536,8 @@ static void cle_clrtoeol(FAR struct cle_s *priv) * * Description: * Make space for new text of size 'increment' at the specified cursor - * position. + * position. This function will not allow text grow beyound (linelen - 1) + * in size. * ****************************************************************************/ @@ -550,8 +551,9 @@ static bool cle_opentext(FAR struct cle_s *priv, uint16_t pos, uint16_t incremen * of 'increment' */ - if (priv->nchars + increment > priv->linelen) + if (priv->nchars + increment >= priv->linelen) { + CLE_BEL(priv); return false; } @@ -641,7 +643,7 @@ static void cle_showtext(FAR struct cle_s *priv) /* Loop for each column */ - for (column = 0; column < priv->nchars && column < priv->linelen; ) + for (column = 0; column < priv->nchars; ) { /* Perform TAB expansion */ @@ -937,5 +939,10 @@ int cle(FAR char *line, uint16_t linelen, FILE *instream, FILE *outstream) /* The editor loop */ - return cle_editloop(&priv); + ret = cle_editloop(&priv); + + /* Make sure that the line is NUL terminated */ + + line[priv.nchars] = '\0'; + return ret; }