Fix string search commands, so they don't crash when command repeat prefix is too big.

This commit is contained in:
Pasi Kallinen 2013-05-25 12:32:41 +03:00
parent f9ca114072
commit 3c17a9b1bf

59
virus.c
View File

@ -1092,9 +1092,6 @@ key_cmd_mode:
break; break;
case 'N': // N- backward search for last pattern case 'N': // N- backward search for last pattern
if (last_search_pattern == 0) break; if (last_search_pattern == 0) break;
if (cmdcnt-- > 1) {
do_cmd (c);
} // repeat cnt
dir = BACK; // assume BACKWARD search dir = BACK; // assume BACKWARD search
p = dot - 1; p = dot - 1;
if (last_search_pattern[0] == '?') { if (last_search_pattern[0] == '?') {
@ -1106,9 +1103,6 @@ key_cmd_mode:
case 'n': // n- repeat search for last pattern case 'n': // n- repeat search for last pattern
// search rest of text[] starting at next char // search rest of text[] starting at next char
// if search fails return orignal "p" not the "p+1" address // if search fails return orignal "p" not the "p+1" address
if (cmdcnt-- > 1) {
do_cmd (c);
} // repeat cnt
dc3: dc3:
if (last_search_pattern == 0) { if (last_search_pattern == 0) {
msg = (Byte *) "No previous regular expression"; msg = (Byte *) "No previous regular expression";
@ -1123,29 +1117,36 @@ key_cmd_mode:
p = dot - 1; p = dot - 1;
} }
dc4: dc4:
q = char_search (p, last_search_pattern + 1, dir, FULL); msg = NULL;
if (q != NULL) { do {
dot = q; // good search, update "dot" q = char_search (p, last_search_pattern + 1, dir, FULL);
msg = (Byte *) ""; if (q != NULL) {
goto dc2; dot = q; // good search, update "dot"
} if (cmdcnt-- > 1) {
// no pattern found between "dot" and "end"- continue at top p = dot + ((dir == FORWARD) ? 1 : -1);
p = text; goto dc4;
if (dir == BACK) { }
p = end - 1; msg = (Byte *) " ";
} goto dc2;
q = char_search (p, last_search_pattern + 1, dir, FULL); }
if (q != NULL) { // found something // no pattern found between "dot" and "end"- continue at top
dot = q; // found new pattern- goto it p = text;
msg = (Byte *) "search hit BOTTOM, continuing at TOP"; if (dir == BACK) {
if (dir == BACK) { p = end - 1;
msg = (Byte *) "search hit TOP, continuing at BOTTOM"; }
} q = char_search (p, last_search_pattern + 1, dir, FULL);
} else { if (q != NULL) { // found something
msg = (Byte *) "Pattern not found"; dot = q; // found new pattern- goto it
} msg = (Byte *) "search hit BOTTOM, continuing at TOP";
dc2: if (dir == BACK) {
psbs ("%s", msg); msg = (Byte *) "search hit TOP, continuing at BOTTOM";
}
} else {
msg = (Byte *) "Pattern not found";
}
} while (msg == NULL && (cmdcnt-- > 1));
dc2:
psbs ("%s", msg);
break; break;
case '{': // {- move backward paragraph case '{': // {- move backward paragraph
q = char_search (dot, (Byte *) "\n\n", BACK, FULL); q = char_search (dot, (Byte *) "\n\n", BACK, FULL);