fix more cases of x_delete() bytes vs. characters abuse (tested!); fix some int vs. size_t issues (XXX also fix x_cf_glob and friends some day…)
This commit is contained in:
		
							
								
								
									
										62
									
								
								edit.c
									
									
									
									
									
								
							
							
						
						
									
										62
									
								
								edit.c
									
									
									
									
									
								
							| @@ -28,7 +28,7 @@ | |||||||
|  |  | ||||||
| #ifndef MKSH_NO_CMDLINE_EDITING | #ifndef MKSH_NO_CMDLINE_EDITING | ||||||
|  |  | ||||||
| __RCSID("$MirOS: src/bin/mksh/edit.c,v 1.243 2012/07/20 20:33:15 tg Exp $"); | __RCSID("$MirOS: src/bin/mksh/edit.c,v 1.244 2012/07/20 20:50:07 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 | ||||||
| @@ -940,9 +940,9 @@ static int holdlen;		/* length of holdbuf */ | |||||||
| static bool prompt_redraw;	/* false if newline forced after prompt */ | static bool prompt_redraw;	/* false if newline forced after prompt */ | ||||||
|  |  | ||||||
| static int x_ins(const char *); | static int x_ins(const char *); | ||||||
| static void x_delete(int, int); | static void x_delete(size_t, bool); | ||||||
| static int x_bword(void); | static size_t x_bword(void); | ||||||
| static int x_fword(bool); | static size_t x_fword(bool); | ||||||
| static void x_goto(char *); | static void x_goto(char *); | ||||||
| static void x_bs3(char **); | static void x_bs3(char **); | ||||||
| static int x_size_str(char *); | static int x_size_str(char *); | ||||||
| @@ -974,7 +974,7 @@ static int x_fold_case(int); | |||||||
| #endif | #endif | ||||||
| static char *x_lastcp(void); | static char *x_lastcp(void); | ||||||
| static void do_complete(int, Comp_type); | static void do_complete(int, Comp_type); | ||||||
| static int x_nb2nc(int); | static size_t x_nb2nc(size_t); | ||||||
|  |  | ||||||
| static int unget_char = -1; | static int unget_char = -1; | ||||||
|  |  | ||||||
| @@ -1094,8 +1094,8 @@ static struct x_defbindings const x_defbindings[] = { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| /* want size_t, not int */ | /* want size_t, not int */ | ||||||
| static int | static size_t | ||||||
| x_nb2nc(int nb) | x_nb2nc(size_t nb) | ||||||
| { | { | ||||||
| 	char *cp; | 	char *cp; | ||||||
| 	size_t nc = 0; | 	size_t nc = 0; | ||||||
| @@ -1361,7 +1361,7 @@ x_ins(const char *s) | |||||||
| static int | static int | ||||||
| x_del_back(int c MKSH_A_UNUSED) | x_del_back(int c MKSH_A_UNUSED) | ||||||
| { | { | ||||||
| 	int i = 0; | 	ssize_t i = 0; | ||||||
|  |  | ||||||
| 	if (xcp == xbuf) { | 	if (xcp == xbuf) { | ||||||
| 		x_e_putc2(7); | 		x_e_putc2(7); | ||||||
| @@ -1378,7 +1378,7 @@ static int | |||||||
| x_del_char(int c MKSH_A_UNUSED) | x_del_char(int c MKSH_A_UNUSED) | ||||||
| { | { | ||||||
| 	char *cp, *cp2; | 	char *cp, *cp2; | ||||||
| 	int i = 0; | 	ssize_t i = 0; | ||||||
|  |  | ||||||
| 	cp = xcp; | 	cp = xcp; | ||||||
| 	while (i < x_arg) { | 	while (i < x_arg) { | ||||||
| @@ -1399,9 +1399,9 @@ x_del_char(int c MKSH_A_UNUSED) | |||||||
|  |  | ||||||
| /* Delete nc chars to the right of the cursor (including cursor position) */ | /* Delete nc chars to the right of the cursor (including cursor position) */ | ||||||
| static void | static void | ||||||
| x_delete(int nc, int push) | x_delete(size_t nc, bool push) | ||||||
| { | { | ||||||
| 	int i, nb, nw; | 	size_t i, nb, nw; | ||||||
| 	char *cp; | 	char *cp; | ||||||
|  |  | ||||||
| 	if (nc == 0) | 	if (nc == 0) | ||||||
| @@ -1496,10 +1496,10 @@ x_del_fword(int c MKSH_A_UNUSED) | |||||||
| 	return (KSTD); | 	return (KSTD); | ||||||
| } | } | ||||||
|  |  | ||||||
| static int | static size_t | ||||||
| x_bword(void) | x_bword(void) | ||||||
| { | { | ||||||
| 	int nb = 0; | 	size_t nb = 0; | ||||||
| 	char *cp = xcp; | 	char *cp = xcp; | ||||||
|  |  | ||||||
| 	if (cp == xbuf) { | 	if (cp == xbuf) { | ||||||
| @@ -1520,10 +1520,10 @@ x_bword(void) | |||||||
| 	return (x_nb2nc(nb)); | 	return (x_nb2nc(nb)); | ||||||
| } | } | ||||||
|  |  | ||||||
| static int | static size_t | ||||||
| x_fword(bool move) | x_fword(bool move) | ||||||
| { | { | ||||||
| 	int nc; | 	size_t nc; | ||||||
| 	char *cp = xcp; | 	char *cp = xcp; | ||||||
|  |  | ||||||
| 	if (cp == xep) { | 	if (cp == xep) { | ||||||
| @@ -2223,20 +2223,18 @@ x_meta2(int c MKSH_A_UNUSED) | |||||||
| static int | static int | ||||||
| x_kill(int c MKSH_A_UNUSED) | x_kill(int c MKSH_A_UNUSED) | ||||||
| { | { | ||||||
| 	int col = xcp - xbuf; | 	size_t col = xcp - xbuf; | ||||||
| 	int lastcol = xep - xbuf; | 	size_t lastcol = xep - xbuf; | ||||||
| 	int ndel; | 	size_t ndel, narg; | ||||||
|  |  | ||||||
| 	if (x_arg_defaulted) | 	if (x_arg_defaulted || (narg = x_arg) > lastcol) | ||||||
| 		x_arg = lastcol; | 		narg = lastcol; | ||||||
| 	else if (x_arg > lastcol) | 	if (narg < col) { | ||||||
| 		x_arg = lastcol; | 		x_goto(xbuf + narg); | ||||||
| 	ndel = x_arg - col; | 		ndel = col - narg; | ||||||
| 	if (ndel < 0) { | 	} else | ||||||
| 		x_goto(xbuf + x_arg); | 		ndel = narg - col; | ||||||
| 		ndel = -ndel; | 	x_delete(x_nb2nc(ndel), true); | ||||||
| 	} |  | ||||||
| 	x_delete(ndel, true); |  | ||||||
| 	return (KSTD); | 	return (KSTD); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -2284,7 +2282,7 @@ x_meta_yank(int c MKSH_A_UNUSED) | |||||||
| 	} | 	} | ||||||
| 	len = strlen(killstack[killtp]); | 	len = strlen(killstack[killtp]); | ||||||
| 	x_goto(xcp - len); | 	x_goto(xcp - len); | ||||||
| 	x_delete(len, false); | 	x_delete(x_nb2nc(len), false); | ||||||
| 	do { | 	do { | ||||||
| 		if (killtp == 0) | 		if (killtp == 0) | ||||||
| 			killtp = KILLSIZE - 1; | 			killtp = KILLSIZE - 1; | ||||||
| @@ -2604,7 +2602,7 @@ x_set_mark(int c MKSH_A_UNUSED) | |||||||
| static int | static int | ||||||
| x_kill_region(int c MKSH_A_UNUSED) | x_kill_region(int c MKSH_A_UNUSED) | ||||||
| { | { | ||||||
| 	int rsize; | 	size_t rsize; | ||||||
| 	char *xr; | 	char *xr; | ||||||
|  |  | ||||||
| 	if (xmp == NULL) { | 	if (xmp == NULL) { | ||||||
| @@ -2619,7 +2617,7 @@ x_kill_region(int c MKSH_A_UNUSED) | |||||||
| 		xr = xmp; | 		xr = xmp; | ||||||
| 	} | 	} | ||||||
| 	x_goto(xr); | 	x_goto(xr); | ||||||
| 	x_delete(rsize, true); | 	x_delete(x_nb2nc(rsize), true); | ||||||
| 	xmp = xr; | 	xmp = xr; | ||||||
| 	return (KSTD); | 	return (KSTD); | ||||||
| } | } | ||||||
| @@ -2712,7 +2710,7 @@ x_expand(int c MKSH_A_UNUSED) | |||||||
| 		return (KSTD); | 		return (KSTD); | ||||||
| 	} | 	} | ||||||
| 	x_goto(xbuf + start); | 	x_goto(xbuf + start); | ||||||
| 	x_delete(end - start, false); | 	x_delete(x_nb2nc(end - start), false); | ||||||
|  |  | ||||||
| 	i = 0; | 	i = 0; | ||||||
| 	while (i < nwords) { | 	while (i < nwords) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user