From 038a9f18278a517d28df24d010da4f52fa0338fb Mon Sep 17 00:00:00 2001
From: David Lawrence Ramsey <pooka109@gmail.com>
Date: Mon, 6 Nov 2017 07:13:50 -0600
Subject: [PATCH] tweaks: use printf's z modifier for ssize_t/size_t

Also, properly display numreplaced as signed, since it's ssize_t.
---
 src/files.c   | 26 +++++++++++++-------------
 src/history.c |  4 ++--
 src/rcfile.c  |  2 +-
 src/search.c  |  6 +++---
 src/text.c    | 18 +++++++++---------
 src/utils.c   |  8 ++++----
 src/winio.c   | 16 ++++++++--------
 7 files changed, 40 insertions(+), 40 deletions(-)

diff --git a/src/files.c b/src/files.c
index 42426e33..297db3bf 100644
--- a/src/files.c
+++ b/src/files.c
@@ -891,24 +891,24 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable,
 #ifndef NANO_TINY
     else if (format == 3) {
 	/* TRANSLATORS: Keep the next four messages at most 78 characters. */
-	statusline(HUSH, P_("Read %lu line (Converted from DOS and Mac format)",
-			"Read %lu lines (Converted from DOS and Mac format)",
-			(unsigned long)num_lines), (unsigned long)num_lines);
+	statusline(HUSH, P_("Read %zu line (Converted from DOS and Mac format)",
+			"Read %zu lines (Converted from DOS and Mac format)",
+			num_lines), num_lines);
     } else if (format == 2) {
 	openfile->fmt = MAC_FILE;
-	statusline(HUSH, P_("Read %lu line (Converted from Mac format)",
-			"Read %lu lines (Converted from Mac format)",
-			(unsigned long)num_lines), (unsigned long)num_lines);
+	statusline(HUSH, P_("Read %zu line (Converted from Mac format)",
+			"Read %zu lines (Converted from Mac format)",
+			num_lines), num_lines);
     } else if (format == 1) {
 	openfile->fmt = DOS_FILE;
-	statusline(HUSH, P_("Read %lu line (Converted from DOS format)",
-			"Read %lu lines (Converted from DOS format)",
-			(unsigned long)num_lines), (unsigned long)num_lines);
+	statusline(HUSH, P_("Read %zu line (Converted from DOS format)",
+			"Read %zu lines (Converted from DOS format)",
+			num_lines), num_lines);
     }
 #endif
     else
-	statusline(HUSH, P_("Read %lu line", "Read %lu lines",
-			(unsigned long)num_lines), (unsigned long)num_lines);
+	statusline(HUSH, P_("Read %zu line", "Read %zu lines",
+			num_lines), num_lines);
 
     /* If we inserted less than a screenful, don't center the cursor. */
     if (undoable && less_than_a_screenful(was_lineno, was_leftedge))
@@ -1957,8 +1957,8 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
 	    stat_with_alloc(realname, &openfile->current_stat);
 #endif
 
-	statusline(HUSH, P_("Wrote %lu line", "Wrote %lu lines",
-		(unsigned long)lineswritten), (unsigned long)lineswritten);
+	statusline(HUSH, P_("Wrote %zu line", "Wrote %zu lines",
+		lineswritten), lineswritten);
 	openfile->modified = FALSE;
 	titlebar(NULL);
     }
diff --git a/src/history.c b/src/history.c
index 5ee5091f..84ed5a70 100644
--- a/src/history.c
+++ b/src/history.c
@@ -472,8 +472,8 @@ void save_poshistory(void)
 	    /* Assume 20 decimal positions each for line and column number,
 	     * plus two spaces, plus the line feed, plus the null byte. */
 	    path_and_place = charalloc(strlen(posptr->filename) + 44);
-	    sprintf(path_and_place, "%s %ld %ld\n", posptr->filename,
-			(long)posptr->lineno, (long)posptr->xno);
+	    sprintf(path_and_place, "%s %zd %zd\n", posptr->filename,
+			posptr->lineno, posptr->xno);
 	    length = strlen(path_and_place);
 
 	    /* Encode newlines in filenames as nulls. */
diff --git a/src/rcfile.c b/src/rcfile.c
index c43a286f..3096eb1a 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -145,7 +145,7 @@ void rcfile_error(const char *msg, ...)
 	rcfile_with_errors = strdup(nanorc);
 
     if (lineno > 0)
-	fprintf(stderr, _("Error in %s on line %lu: "), nanorc, (unsigned long)lineno);
+	fprintf(stderr, _("Error in %s on line %zu: "), nanorc, lineno);
 
     va_start(ap, msg);
     vfprintf(stderr, _(msg), ap);
diff --git a/src/search.c b/src/search.c
index a63885f4..378429c0 100644
--- a/src/search.c
+++ b/src/search.c
@@ -778,9 +778,9 @@ void do_replace(void)
     refresh_needed = TRUE;
 
     if (numreplaced >= 0)
-	statusline(HUSH, P_("Replaced %lu occurrence",
-		"Replaced %lu occurrences", (unsigned long)numreplaced),
-		(unsigned long)numreplaced);
+	statusline(HUSH, P_("Replaced %zd occurrence",
+		"Replaced %zd occurrences", numreplaced),
+		numreplaced);
 
     search_replace_abort();
 }
diff --git a/src/text.c b/src/text.c
index 37b52e4a..7cc2539a 100644
--- a/src/text.c
+++ b/src/text.c
@@ -1397,10 +1397,10 @@ void update_undo(undo_type action)
     undo *u;
 
 #ifdef DEBUG
-fprintf(stderr, "  >> Updating... action = %d, openfile->last_action = %d, openfile->current->lineno = %ld",
-		action, openfile->last_action, (long)openfile->current->lineno);
+fprintf(stderr, "  >> Updating... action = %d, openfile->last_action = %d, openfile->current->lineno = %zd",
+		action, openfile->last_action, openfile->current->lineno);
 	if (openfile->current_undo)
-	    fprintf(stderr, ", openfile->current_undo->lineno = %ld\n", (long)openfile->current_undo->lineno);
+	    fprintf(stderr, ", openfile->current_undo->lineno = %zd\n", openfile->current_undo->lineno);
 	else
 	    fprintf(stderr, "\n");
 #endif
@@ -1421,8 +1421,8 @@ fprintf(stderr, "  >> Updating... action = %d, openfile->last_action = %d, openf
     switch (u->type) {
     case ADD: {
 #ifdef DEBUG
-	fprintf(stderr, "  >> openfile->current->data = \"%s\", current_x = %lu, u->begin = %lu\n",
-			openfile->current->data, (unsigned long)openfile->current_x, (unsigned long)u->begin);
+	fprintf(stderr, "  >> openfile->current->data = \"%s\", current_x = %zu, u->begin = %zu\n",
+			openfile->current->data, openfile->current_x, u->begin);
 #endif
 	char *char_buf = charalloc(MAXCHARLEN);
 	int char_len = parse_mbchar(&openfile->current->data[u->mark_begin_x], char_buf, NULL);
@@ -1453,7 +1453,7 @@ fprintf(stderr, "  >> Updating... action = %d, openfile->last_action = %d, openf
 	    return;
 	}
 #ifdef DEBUG
-	fprintf(stderr, "  >> current undo data is \"%s\"\nu->begin = %lu\n", u->strdata, (unsigned long)u->begin);
+	fprintf(stderr, "  >> current undo data is \"%s\"\nu->begin = %zu\n", u->strdata, u->begin);
 #endif
 	break;
     }
@@ -3559,9 +3559,9 @@ void do_wordlinechar_count(void)
     openfile->placewewant = pww_save;
 
     /* Display the total word, line, and character counts on the statusbar. */
-    statusline(HUSH, _("%sWords: %lu  Lines: %ld  Chars: %lu"), old_mark_set ?
-		_("In Selection:  ") : "", (unsigned long)words, (long)nlines,
-		(unsigned long)chars);
+    statusline(HUSH, _("%sWords: %zu  Lines: %zd  Chars: %zu"), old_mark_set ?
+		_("In Selection:  ") : "", words, nlines,
+		chars);
 }
 #endif /* !NANO_TINY */
 
diff --git a/src/utils.c b/src/utils.c
index 530dd2cd..2178ae3e 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -520,8 +520,8 @@ filestruct *fsfromline(ssize_t lineno)
 	    f = f->next;
 
     if (f->lineno != lineno) {
-	statusline(ALERT, _("Internal error: can't match line %ld.  "
-			"Please save your work."), (long)lineno);
+	statusline(ALERT, _("Internal error: can't match line %zd.  "
+			"Please save your work."), lineno);
 	return NULL;
     }
 
@@ -559,7 +559,7 @@ void dump_filestruct(const filestruct *inptr)
 	fprintf(stderr, "Dumping a buffer to stderr...\n");
 
     while (inptr != NULL) {
-	fprintf(stderr, "(%ld) %s\n", (long)inptr->lineno, inptr->data);
+	fprintf(stderr, "(%zd) %s\n", inptr->lineno, inptr->data);
 	inptr = inptr->next;
     }
 }
@@ -570,7 +570,7 @@ void dump_filestruct_reverse(void)
     const filestruct *fileptr = openfile->filebot;
 
     while (fileptr != NULL) {
-	fprintf(stderr, "(%ld) %s\n", (long)fileptr->lineno,
+	fprintf(stderr, "(%zd) %s\n", fileptr->lineno,
 		fileptr->data);
 	fileptr = fileptr->prev;
     }
diff --git a/src/winio.c b/src/winio.c
index cd466d2d..0e6ed77d 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -1341,8 +1341,8 @@ int parse_escape_sequence(WINDOW *win, int kbinput)
     }
 
 #ifdef DEBUG
-    fprintf(stderr, "parse_escape_sequence(): kbinput = %d, seq_len = %lu, retval = %d\n",
-		kbinput, (unsigned long)seq_len, retval);
+    fprintf(stderr, "parse_escape_sequence(): kbinput = %d, seq_len = %zu, retval = %d\n",
+		kbinput, seq_len, retval);
 #endif
 
     return retval;
@@ -2433,7 +2433,7 @@ void edit_draw(filestruct *fileptr, const char *converted,
 	    mvwprintw(edit, row, 0, "%*s", margin - 1, " ");
 	else
 #endif
-	    mvwprintw(edit, row, 0, "%*ld", margin - 1, (long)fileptr->lineno);
+	    mvwprintw(edit, row, 0, "%*zd", margin - 1, fileptr->lineno);
 	wattroff(edit, interface_color_pair[LINE_NUMBER]);
     }
 #endif
@@ -3432,11 +3432,11 @@ void do_cursorpos(bool force)
     charpct = (openfile->totsize == 0) ? 0 : 100 * sum / openfile->totsize;
 
     statusline(HUSH,
-	_("line %ld/%ld (%d%%), col %lu/%lu (%d%%), char %lu/%lu (%d%%)"),
-	(long)openfile->current->lineno,
-	(long)openfile->filebot->lineno, linepct,
-	(unsigned long)cur_xpt, (unsigned long)cur_lenpt, colpct,
-	(unsigned long)sum, (unsigned long)openfile->totsize, charpct);
+	_("line %zd/%zd (%d%%), col %zu/%zu (%d%%), char %zu/%zu (%d%%)"),
+	openfile->current->lineno,
+	openfile->filebot->lineno, linepct,
+	cur_xpt, cur_lenpt, colpct,
+	sum, openfile->totsize, charpct);
 
     /* Displaying the cursor position should not suppress it next time. */
     suppress_cursorpos = FALSE;
-- 
2.14.1

