nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit b0f5282de2ca98b5995f60579b00726dcaadd17a
parent fe4158410211609440c8a5ee6a194cfb50a5929c
Author: Chris Allegretta <chrisa@asty.org>
Date:   Thu,  4 Jan 2001 05:20:23 +0000

Fix segfault when width == 0


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@442 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

Diffstat:
Mfiles.c | 22+++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/files.c b/files.c @@ -1197,6 +1197,7 @@ char *do_browser(char *inpath) static char *path = NULL; int numents = 0, i = 0, j = 0, kbinput = 0, longest = 0, abort = 0; int col = 0, selected = 0, editline = 0, width = 0, filecols = 0; + int lineno = 0; char **filelist = (char **) NULL; /* If path isn't the same as inpath, we are being passed a new @@ -1231,6 +1232,12 @@ char *do_browser(char *inpath) blank_statusbar(); editline = 0; col = 0; + + /* Compute line number we're on now so we don't divide by zero later */ + if (width == 0) + lineno = selected; + else + lineno = selected / width; switch (kbinput) { case KEY_UP: @@ -1256,31 +1263,32 @@ char *do_browser(char *inpath) case NANO_PREVPAGE_KEY: case NANO_PREVPAGE_FKEY: case KEY_PPAGE: - if ((selected / width) % editwinrows == 0) { + + if (lineno % editwinrows == 0) { if (selected - (editwinrows * width) >= 0) selected -= editwinrows * width; else selected = 0; } else if (selected - (editwinrows + - (selected / width) % editwinrows) * width >= 0) - selected -= (editwinrows + (selected / width) % - editwinrows) * width; + lineno % editwinrows) * width >= 0) + + selected -= (editwinrows + lineno % editwinrows) * width; else selected = 0; break; case NANO_NEXTPAGE_KEY: case NANO_NEXTPAGE_FKEY: case KEY_NPAGE: - if ((selected / width) % editwinrows == 0) { + if (lineno % editwinrows == 0) { if (selected + (editwinrows * width) <= numents - 1) selected += editwinrows * width; else selected = numents - 1; } else if (selected + (editwinrows - - (selected / width) % editwinrows) * width <= numents - 1) - selected += (editwinrows - (selected / width) % editwinrows) * width; + lineno % editwinrows) * width <= numents - 1) + selected += (editwinrows - lineno % editwinrows) * width; else selected = numents - 1; break;