From 3f35864b10060e89671bc486adb92faa8d7b6960 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Mon, 22 Nov 2004 16:04:18 +0000 Subject: [PATCH] fix get_totals() so it properly handles NULL parameters, and restore totlines after marked spell-check the way the justify routine does instead of saving it and readding it later git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2118 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- src/nano.c | 24 +++++++++--------------- src/utils.c | 26 ++++++++++++++++---------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/nano.c b/src/nano.c index df677aa5..c505c87e 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1885,9 +1885,6 @@ const char *do_alt_speller(char *tempfile_name) * the alternate spell command. The line that mark_beginbuf * points to will be freed, so we save the line number and * restore afterwards. */ - int old_totlines = totlines; - /* Our saved value of totlines, used when we spell-check a - * marked selection. */ long old_totsize = totsize; /* Our saved value of totsize, used when we spell-check a marked * selection. */ @@ -1949,7 +1946,6 @@ const char *do_alt_speller(char *tempfile_name) #ifndef NANO_SMALL if (old_mark_set) { - int part_totlines; long part_totsize; /* If the mark was on, partition the filestruct so that it @@ -1961,11 +1957,10 @@ const char *do_alt_speller(char *tempfile_name) filepart = partition_filestruct(top, top_x, bot, bot_x); added_magicline = (filebot->data[0] != '\0'); - /* Get the number of lines and the number of characters in the - * marked text, and subtract them from the saved values of - * totlines and totsize. */ - get_totals(top, bot, &part_totlines, &part_totsize); - old_totlines -= part_totlines; + /* Get the number of characters in the marked text, and subtract + * it from the saved value of totsize. Note that we don't need + * to save totlines. */ + get_totals(top, bot, NULL, &part_totsize); old_totsize -= part_totsize; } #endif @@ -2009,14 +2004,13 @@ const char *do_alt_speller(char *tempfile_name) unpartition_filestruct(&filepart); /* Renumber starting with the beginning line of the old - * partition. Also add the number of lines and characters in - * the spell-checked marked text to the saved values of totlines - * and totsize, and then make those saved values the actual - * values. */ + * partition. Also set totlines to the new number of lines in + * the file, add the number of characters in the spell-checked + * marked text to the saved value of totsize, and then make that + * saved value the actual value. */ renumber(top_save); - old_totlines += totlines; + totlines = filebot->lineno; old_totsize += totsize; - totlines = old_totlines; totsize = old_totsize; /* Assign mark_beginbuf to the line where the mark began diff --git a/src/utils.c b/src/utils.c index 7b5c1045..463bce99 100644 --- a/src/utils.c +++ b/src/utils.c @@ -471,27 +471,33 @@ void get_totals(const filestruct *begin, const filestruct *end, int /* Go through the lines from begin to end->prev, if we can. */ for (f = begin; f != NULL && f != end; f = f->next) { /* Count this line. */ - (*lines)++; + if (lines != NULL) + (*lines)++; /* Count the number of characters on this line. */ - *size += strlen(f->data); + if (size != NULL) { + *size += strlen(f->data); - /* Count the newline if we have one. */ - if (f->next != NULL) - (*size)++; + /* Count the newline if we have one. */ + if (f->next != NULL) + (*size)++; + } } /* Go through the line at end, if we can. */ if (f != NULL) { /* Count this line. */ - (*lines)++; + if (lines != NULL) + (*lines)++; /* Count the number of characters on this line. */ - *size += strlen(f->data); + if (size != NULL) { + *size += strlen(f->data); - /* Count the newline if we have one. */ - if (f->next != NULL) - (*size)++; + /* Count the newline if we have one. */ + if (f->next != NULL) + (*size)++; + } } } -- 2.39.5