From b8e093dbaae99d2dc12157fcce1bb12ba26b8d3e Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 1 Nov 2018 06:58:18 -0700 Subject: linenoise: guard against setting cols to zero. * linenoise/linenoise.c (get_columns): Avoid the situation that cols is zero or negative. The cols value is involved in a modulo calculation (position % cols), which requires cols not to be zero. The situation hasn't been observed; this is just defensive coding. --- linenoise/linenoise.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index 3aaf7b80..f3784597 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -342,7 +342,7 @@ static int get_columns(mem_t *ifs, mem_t *ofs) { if (!lino_os.puts_fn(ofs, L"\x1b[999C")) goto failed; cols = get_cursor_position(ifs, ofs); - if (cols == -1) goto failed; + if (cols <= 0) goto failed; /* Restore position. */ if (cols > start) { -- cgit v1.2.3