summaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-03-21 22:31:24 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-03-21 22:31:24 +0000
commit2a51af257957bef9206b594f0e7fb8846ea7070b (patch)
treefc811054243e0e7638a822c2c18cc6fd06a1cb27 /editors
parent9a1fa8cf07f66cc2585d8ff11eb07d6f5ca0e2b2 (diff)
downloadbusybox-w32-2a51af257957bef9206b594f0e7fb8846ea7070b.tar.gz
busybox-w32-2a51af257957bef9206b594f0e7fb8846ea7070b.tar.bz2
busybox-w32-2a51af257957bef9206b594f0e7fb8846ea7070b.zip
vi: fix signed char-induced potential bugs
Diffstat (limited to 'editors')
-rw-r--r--editors/vi.c62
1 files changed, 32 insertions, 30 deletions
diff --git a/editors/vi.c b/editors/vi.c
index bd169b09d..863735e31 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -28,33 +28,34 @@
28#if ENABLE_LOCALE_SUPPORT 28#if ENABLE_LOCALE_SUPPORT
29#define Isprint(c) isprint((c)) 29#define Isprint(c) isprint((c))
30#else 30#else
31#define Isprint(c) ( (c) >= ' ' && (c) != 127 && (c) != ((unsigned char)'\233') ) 31/* 0x9b is Meta-ESC */
32#define Isprint(c) ((unsigned char)(c) >= ' ' && (c) != 0x7f && (unsigned char)(c) != 0x9b)
32#endif 33#endif
33 34
34#define MAX_SCR_COLS BUFSIZ 35#define MAX_SCR_COLS BUFSIZ
35 36
36// Misc. non-Ascii keys that report an escape sequence 37// Misc. non-Ascii keys that report an escape sequence
37#define VI_K_UP 128 // cursor key Up 38#define VI_K_UP (char)128 // cursor key Up
38#define VI_K_DOWN 129 // cursor key Down 39#define VI_K_DOWN (char)129 // cursor key Down
39#define VI_K_RIGHT 130 // Cursor Key Right 40#define VI_K_RIGHT (char)130 // Cursor Key Right
40#define VI_K_LEFT 131 // cursor key Left 41#define VI_K_LEFT (char)131 // cursor key Left
41#define VI_K_HOME 132 // Cursor Key Home 42#define VI_K_HOME (char)132 // Cursor Key Home
42#define VI_K_END 133 // Cursor Key End 43#define VI_K_END (char)133 // Cursor Key End
43#define VI_K_INSERT 134 // Cursor Key Insert 44#define VI_K_INSERT (char)134 // Cursor Key Insert
44#define VI_K_PAGEUP 135 // Cursor Key Page Up 45#define VI_K_PAGEUP (char)135 // Cursor Key Page Up
45#define VI_K_PAGEDOWN 136 // Cursor Key Page Down 46#define VI_K_PAGEDOWN (char)136 // Cursor Key Page Down
46#define VI_K_FUN1 137 // Function Key F1 47#define VI_K_FUN1 (char)137 // Function Key F1
47#define VI_K_FUN2 138 // Function Key F2 48#define VI_K_FUN2 (char)138 // Function Key F2
48#define VI_K_FUN3 139 // Function Key F3 49#define VI_K_FUN3 (char)139 // Function Key F3
49#define VI_K_FUN4 140 // Function Key F4 50#define VI_K_FUN4 (char)140 // Function Key F4
50#define VI_K_FUN5 141 // Function Key F5 51#define VI_K_FUN5 (char)141 // Function Key F5
51#define VI_K_FUN6 142 // Function Key F6 52#define VI_K_FUN6 (char)142 // Function Key F6
52#define VI_K_FUN7 143 // Function Key F7 53#define VI_K_FUN7 (char)143 // Function Key F7
53#define VI_K_FUN8 144 // Function Key F8 54#define VI_K_FUN8 (char)144 // Function Key F8
54#define VI_K_FUN9 145 // Function Key F9 55#define VI_K_FUN9 (char)145 // Function Key F9
55#define VI_K_FUN10 146 // Function Key F10 56#define VI_K_FUN10 (char)146 // Function Key F10
56#define VI_K_FUN11 147 // Function Key F11 57#define VI_K_FUN11 (char)147 // Function Key F11
57#define VI_K_FUN12 148 // Function Key F12 58#define VI_K_FUN12 (char)148 // Function Key F12
58 59
59/* vt102 typical ESC sequence */ 60/* vt102 typical ESC sequence */
60/* terminal standout start/normal ESC sequence */ 61/* terminal standout start/normal ESC sequence */
@@ -840,7 +841,7 @@ static void colon(char * buf)
840 int c_is_no_print; 841 int c_is_no_print;
841 842
842 c = *q; 843 c = *q;
843 c_is_no_print = c > 127 && !Isprint(c); 844 c_is_no_print = (c & 0x80) && !Isprint(c);
844 if (c_is_no_print) { 845 if (c_is_no_print) {
845 c = '.'; 846 c = '.';
846 standout_start(); 847 standout_start();
@@ -1922,7 +1923,7 @@ static inline void print_literal(char * buf, const char * s) // copy s to buf, c
1922 int c_is_no_print; 1923 int c_is_no_print;
1923 1924
1924 c = *s; 1925 c = *s;
1925 c_is_no_print = c > 127 && !Isprint(c); 1926 c_is_no_print = (c & 0x80) && !Isprint(c);
1926 if (c_is_no_print) { 1927 if (c_is_no_print) {
1927 strcat(buf, SOn); 1928 strcat(buf, SOn);
1928 c = '.'; 1929 c = '.';
@@ -2735,7 +2736,7 @@ static void format_line(char *dest, char *src, int li)
2735 char c; 2736 char c;
2736 2737
2737 for (co = 0; co < MAX_SCR_COLS; co++) { 2738 for (co = 0; co < MAX_SCR_COLS; co++) {
2738 c= ' '; // assume blank 2739 c = ' '; // assume blank
2739 if (li > 0 && co == 0) { 2740 if (li > 0 && co == 0) {
2740 c = '~'; // not first line, assume Tilde 2741 c = '~'; // not first line, assume Tilde
2741 } 2742 }
@@ -2745,10 +2746,10 @@ static void format_line(char *dest, char *src, int li)
2745 } 2746 }
2746 if (c == '\n') 2747 if (c == '\n')
2747 break; 2748 break;
2748 if (c > 127 && !Isprint(c)) { 2749 if ((c & 0x80) && !Isprint(c)) {
2749 c = '.'; 2750 c = '.';
2750 } 2751 }
2751 if (c < ' ' || c == 127) { 2752 if ((unsigned char)(c) < ' ' || c == 0x7f) {
2752 if (c == '\t') { 2753 if (c == '\t') {
2753 c = ' '; 2754 c = ' ';
2754 // co % 8 != 7 2755 // co % 8 != 7
@@ -2757,7 +2758,7 @@ static void format_line(char *dest, char *src, int li)
2757 } 2758 }
2758 } else { 2759 } else {
2759 dest[co++] = '^'; 2760 dest[co++] = '^';
2760 if (c == 127) 2761 if (c == 0x7f)
2761 c = '?'; 2762 c = '?';
2762 else 2763 else
2763 c += '@'; // make it visible 2764 c += '@'; // make it visible
@@ -2939,7 +2940,8 @@ static void do_cmd(char c)
2939 2940
2940 if (cmd_mode == 2) { 2941 if (cmd_mode == 2) {
2941 // flip-flop Insert/Replace mode 2942 // flip-flop Insert/Replace mode
2942 if (c == VI_K_INSERT) goto dc_i; 2943 if (c == VI_K_INSERT)
2944 goto dc_i;
2943 // we are 'R'eplacing the current *dot with new char 2945 // we are 'R'eplacing the current *dot with new char
2944 if (*dot == '\n') { 2946 if (*dot == '\n') {
2945 // don't Replace past E-o-l 2947 // don't Replace past E-o-l
@@ -3048,7 +3050,7 @@ static void do_cmd(char c)
3048 case 'h': // h- move left 3050 case 'h': // h- move left
3049 case VI_K_LEFT: // cursor key Left 3051 case VI_K_LEFT: // cursor key Left
3050 case 8: // ctrl-H- move left (This may be ERASE char) 3052 case 8: // ctrl-H- move left (This may be ERASE char)
3051 case 127: // DEL- move left (This may be ERASE char) 3053 case 0x7f: // DEL- move left (This may be ERASE char)
3052 if (cmdcnt-- > 1) { 3054 if (cmdcnt-- > 1) {
3053 do_cmd(c); 3055 do_cmd(c);
3054 } // repeat cnt 3056 } // repeat cnt