go home Coverity, you’re drunk

code refactoring to work around it not recognising the correct code path
This commit is contained in:
tg 2017-08-08 00:03:56 +00:00
parent 23320b7a72
commit d8d8ec4466
1 changed files with 17 additions and 10 deletions

27
edit.c
View File

@ -28,7 +28,7 @@
#ifndef MKSH_NO_CMDLINE_EDITING #ifndef MKSH_NO_CMDLINE_EDITING
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.338 2017/08/07 23:23:12 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/edit.c,v 1.339 2017/08/08 00:03:56 tg Exp $");
/* /*
* in later versions we might use libtermcap for this, but since external * in later versions we might use libtermcap for this, but since external
@ -3385,6 +3385,7 @@ static int nextstate(int);
static int vi_insert(int); static int vi_insert(int);
static int vi_cmd(int, const char *); static int vi_cmd(int, const char *);
static int domove(int, const char *, int); static int domove(int, const char *, int);
static int domovebeg(void);
static int redo_insert(int); static int redo_insert(int);
static void yank_range(int, int); static void yank_range(int, int);
static int bracktype(int); static int bracktype(int);
@ -4185,7 +4186,7 @@ vi_cmd(int argcnt, const char *cmd)
break; break;
case ord('S'): case ord('S'):
vs->cursor = domove(1, "^", 1); vs->cursor = domovebeg();
del_range(vs->cursor, vs->linelen); del_range(vs->cursor, vs->linelen);
modified = 1; modified = 1;
hnum = hlast; hnum = hlast;
@ -4201,9 +4202,7 @@ vi_cmd(int argcnt, const char *cmd)
case ord('d'): case ord('d'):
case ord('y'): case ord('y'):
if (*cmd == cmd[1]) { if (*cmd == cmd[1]) {
c1 = *cmd == 'c' ? domove(1, "^", 1) : 0; c1 = *cmd == 'c' ? domovebeg() : 0;
if (c1 < 0)
return (-1);
c2 = vs->linelen; c2 = vs->linelen;
} else if (!is_move(cmd[1])) } else if (!is_move(cmd[1]))
return (-1); return (-1);
@ -4307,7 +4306,7 @@ vi_cmd(int argcnt, const char *cmd)
case ord('I'): case ord('I'):
modified = 1; modified = 1;
hnum = hlast; hnum = hlast;
vs->cursor = domove(1, "^", 1); vs->cursor = domovebeg();
insert = INSERT; insert = INSERT;
break; break;
@ -4699,10 +4698,7 @@ domove(int argcnt, const char *cmd, int sub)
break; break;
case ord('^'): case ord('^'):
ncursor = 0; ncursor = domovebeg();
while (ncursor < vs->linelen - 1 &&
ctype(vs->cbuf[ncursor], C_SPACE))
ncursor++;
break; break;
case ord('|'): case ord('|'):
@ -4752,6 +4748,17 @@ domove(int argcnt, const char *cmd, int sub)
return (ncursor); return (ncursor);
} }
static int
domovebeg(void)
{
int ncursor = 0;
while (ncursor < vs->linelen - 1 &&
ctype(vs->cbuf[ncursor], C_SPACE))
ncursor++;
return (ncursor);
}
static int static int
redo_insert(int count) redo_insert(int count)
{ {