You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by je...@apache.org on 2020/04/27 13:29:45 UTC

[incubator-nuttx-apps] 02/02: cle.c: Fix warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false

This is an automated email from the ASF dual-hosted git repository.

jerpelea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit ef19ca0243a128e23e77dc9b08231449b8428c63
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Mon Apr 27 20:24:43 2020 +0800

    cle.c: Fix warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 system/cle/cle.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/system/cle/cle.c b/system/cle/cle.c
index f515699..bb39371 100644
--- a/system/cle/cle.c
+++ b/system/cle/cle.c
@@ -673,22 +673,24 @@ static void cle_closetext(FAR struct cle_s *priv, uint16_t pos,
 
   priv->nchars -= size;
 
-  /* Check if the cursor position is beyond the deleted region */
-
-  if (priv->curpos > pos + size)
+  if (priv->curpos > pos)
     {
-      /* Yes... just subtract the size of the deleted region */
+      /* Check if the cursor position is beyond the deleted region */
 
-      priv->curpos -= size;
-    }
+      if (priv->curpos - pos > size)
+        {
+          /* Yes... just subtract the size of the deleted region */
 
-  /* What if the position is within the deleted region?  Set it to the
-   * beginning of the deleted region.
-   */
+          priv->curpos -= size;
+        }
+      else
+        {
+          /* What if the position is within the deleted region?  Set it to
+           * the beginning of the deleted region.
+           */
 
-  else if (priv->curpos > pos)
-    {
-      priv->curpos = pos;
+        priv->curpos = pos;
+        }
     }
 }
 
@@ -1118,7 +1120,7 @@ static int cle_editloop(FAR struct cle_s *priv)
         case '\n': /* LF terminates line */
 #endif
           {
-            /* Add the newline character to the buffer at the end of the line */
+            /* Add the newline to the buffer at the end of the line */
 
             priv->curpos = priv->nchars;
             cle_insertch(priv, '\n');