diff --git a/src/nano.c b/src/nano.c
index df677aa573f78cbc728ed2cc9e84a8450cad60c3..c505c87e2e22d57ff322d1fc444859e1a4d33a49 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 7b5c104509ada6e3cfef2adc0c08e712f0b45a17..463bce99b62a7921b4282278f87af20a0d71175a 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)++;
+	}
     }
 }