From ef19ca0243a128e23e77dc9b08231449b8428c63 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Mon, 27 Apr 2020 20:24:43 +0800 Subject: [PATCH] cle.c: Fix warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false Signed-off-by: Xiang Xiao --- 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 f51569956..bb3937131 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');