mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 09:44:18 +00:00 
			
		
		
		
	When I wrote this I somehow forgot that the cursor could helpfully sit at sx
(one character off the right of the screen), so there are several out-of-bounds issues. Add some additional checking.
This commit is contained in:
		@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: screen-write.c,v 1.20 2009-01-08 21:22:01 nicm Exp $ */
 | 
					/* $Id: screen-write.c,v 1.21 2009-01-08 21:55:12 nicm Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -139,7 +139,6 @@ screen_write_cursorup(struct screen_write_ctx *ctx, u_int ny)
 | 
				
			|||||||
	if (ny == 0)
 | 
						if (ny == 0)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	log_debug("cursor up: %u + %u", s->cy, ny);
 | 
					 | 
				
			||||||
	s->cy -= ny;
 | 
						s->cy -= ny;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (ctx->write != NULL)
 | 
						if (ctx->write != NULL)
 | 
				
			||||||
@@ -160,7 +159,6 @@ screen_write_cursordown(struct screen_write_ctx *ctx, u_int ny)
 | 
				
			|||||||
	if (ny == 0)
 | 
						if (ny == 0)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	log_debug("cursor down: %u + %u", s->cy, ny);
 | 
					 | 
				
			||||||
	s->cy += ny;
 | 
						s->cy += ny;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (ctx->write != NULL)
 | 
						if (ctx->write != NULL)
 | 
				
			||||||
@@ -181,7 +179,6 @@ screen_write_cursorright(struct screen_write_ctx *ctx, u_int nx)
 | 
				
			|||||||
	if (nx == 0)
 | 
						if (nx == 0)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	log_debug("cursor right: %u + %u", s->cx, nx);
 | 
					 | 
				
			||||||
	s->cx += nx;
 | 
						s->cx += nx;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (ctx->write != NULL)
 | 
						if (ctx->write != NULL)
 | 
				
			||||||
@@ -202,7 +199,6 @@ screen_write_cursorleft(struct screen_write_ctx *ctx, u_int nx)
 | 
				
			|||||||
	if (nx == 0)
 | 
						if (nx == 0)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	log_debug("cursor left: %u + %u", s->cx, nx);
 | 
					 | 
				
			||||||
	s->cx -= nx;
 | 
						s->cx -= nx;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (ctx->write != NULL)
 | 
						if (ctx->write != NULL)
 | 
				
			||||||
@@ -223,6 +219,7 @@ screen_write_insertcharacter(struct screen_write_ctx *ctx, u_int nx)
 | 
				
			|||||||
	if (nx == 0)
 | 
						if (nx == 0)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (s->cx <= screen_size_x(s) - 1)
 | 
				
			||||||
		grid_view_insert_cells(s->grid, s->cx, s->cy, nx);
 | 
							grid_view_insert_cells(s->grid, s->cx, s->cy, nx);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (ctx->write != NULL)
 | 
						if (ctx->write != NULL)
 | 
				
			||||||
@@ -243,6 +240,7 @@ screen_write_deletecharacter(struct screen_write_ctx *ctx, u_int nx)
 | 
				
			|||||||
	if (nx == 0)
 | 
						if (nx == 0)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (s->cx <= screen_size_x(s) - 1)
 | 
				
			||||||
		grid_view_delete_cells(s->grid, s->cx, s->cy, nx);
 | 
							grid_view_delete_cells(s->grid, s->cx, s->cy, nx);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (ctx->write != NULL)
 | 
						if (ctx->write != NULL)
 | 
				
			||||||
@@ -316,8 +314,12 @@ void
 | 
				
			|||||||
screen_write_clearendofline(struct screen_write_ctx *ctx)
 | 
					screen_write_clearendofline(struct screen_write_ctx *ctx)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct screen	*s = ctx->s;
 | 
						struct screen	*s = ctx->s;
 | 
				
			||||||
 | 
						u_int		 sx;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	grid_view_clear(s->grid, s->cx, s->cy, screen_size_x(s) - s->cx, 1);
 | 
						sx = screen_size_x(s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (s->cx <= sx - 1)
 | 
				
			||||||
 | 
							grid_view_clear(s->grid, s->cx, s->cy, sx - s->cx, 1);
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	if (ctx->write != NULL)
 | 
						if (ctx->write != NULL)
 | 
				
			||||||
		ctx->write(ctx->data, TTY_CLEARENDOFLINE);
 | 
							ctx->write(ctx->data, TTY_CLEARENDOFLINE);
 | 
				
			||||||
@@ -328,7 +330,13 @@ void
 | 
				
			|||||||
screen_write_clearstartofline(struct screen_write_ctx *ctx)
 | 
					screen_write_clearstartofline(struct screen_write_ctx *ctx)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct screen	*s = ctx->s;
 | 
						struct screen	*s = ctx->s;
 | 
				
			||||||
 | 
						u_int		 sx;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sx = screen_size_x(s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (s->cx > sx - 1)
 | 
				
			||||||
 | 
							grid_view_clear(s->grid, 0, s->cy, sx, 1);
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
		grid_view_clear(s->grid, 0, s->cy, s->cx + 1, 1);
 | 
							grid_view_clear(s->grid, 0, s->cy, s->cx + 1, 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (ctx->write != NULL)
 | 
						if (ctx->write != NULL)
 | 
				
			||||||
@@ -505,6 +513,7 @@ screen_write_clearendofscreen(struct screen_write_ctx *ctx)
 | 
				
			|||||||
	sx = screen_size_x(s);
 | 
						sx = screen_size_x(s);
 | 
				
			||||||
	sy = screen_size_y(s);
 | 
						sy = screen_size_y(s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (s->cx <= sx - 1)
 | 
				
			||||||
		grid_view_clear(s->grid, s->cx, s->cy, sx - s->cx, 1);
 | 
							grid_view_clear(s->grid, s->cx, s->cy, sx - s->cx, 1);
 | 
				
			||||||
	grid_view_clear(s->grid, 0, s->cy + 1, sx, sy - (s->cy + 1));
 | 
						grid_view_clear(s->grid, 0, s->cy + 1, sx, sy - (s->cy + 1));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -523,6 +532,9 @@ screen_write_clearstartofscreen(struct screen_write_ctx *ctx)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	if (s->cy > 0)
 | 
						if (s->cy > 0)
 | 
				
			||||||
		grid_view_clear(s->grid, 0, 0, sx, s->cy - 1);
 | 
							grid_view_clear(s->grid, 0, 0, sx, s->cy - 1);
 | 
				
			||||||
 | 
						if (s->cx > sx - 1)
 | 
				
			||||||
 | 
							grid_view_clear(s->grid, 0, s->cy, sx, 1);
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
		grid_view_clear(s->grid, 0, s->cy, s->cx, 1);
 | 
							grid_view_clear(s->grid, 0, s->cy, s->cx, 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (ctx->write != NULL)
 | 
						if (ctx->write != NULL)
 | 
				
			||||||
@@ -563,7 +575,7 @@ screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Check this will fit on the current line; scroll if not. */
 | 
						/* Check this will fit on the current line; scroll if not. */
 | 
				
			||||||
	if (s->cx >= screen_size_x(s) + 1 - width) {
 | 
						if (s->cx > screen_size_x(s) - width) {
 | 
				
			||||||
		screen_write_carriagereturn(ctx);
 | 
							screen_write_carriagereturn(ctx);
 | 
				
			||||||
		screen_write_linefeed(ctx);
 | 
							screen_write_linefeed(ctx);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user