From 3828dbed57fc9f6b620faf29445c43aefcf541c7 Mon Sep 17 00:00:00 2001
From: Mark Whitley <markw@lineo.com>
Date: Tue, 17 Apr 2001 17:47:33 +0000
Subject: Applied patch from I.Q. to fix problem with sort -n.

---
 coreutils/sort.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

(limited to 'coreutils/sort.c')

diff --git a/coreutils/sort.c b/coreutils/sort.c
index 9707efa51..b84453d3a 100644
--- a/coreutils/sort.c
+++ b/coreutils/sort.c
@@ -33,7 +33,8 @@ static int compare_ascii(const void *x, const void *y)
 
 static int compare_numeric(const void *x, const void *y)
 {
-	return atoi(*(char **)x) - atoi(*(char **)y);
+	int z = atoi(*(char **)x) - atoi(*(char **)y);
+	return z ? z : strcmp(*(char **)x, *(char **)y);
 }
 
 int sort_main(int argc, char **argv)
@@ -70,6 +71,7 @@ int sort_main(int argc, char **argv)
 
 		while ((line = get_line_from_file(fp)) != NULL) {
 			lines = xrealloc(lines, sizeof(char *) * (nlines + 1));
+			line[strlen(line) - 1] = '\0';
 			lines[nlines++] = line;
 		}
 	}
@@ -81,10 +83,10 @@ int sort_main(int argc, char **argv)
 #ifdef BB_FEATURE_SORT_REVERSE
 	if (reverse)
 		for (i = nlines - 1; 0 <= i; i--)
-			fputs(lines[i], stdout);
+			puts(lines[i]);
 	else
 #endif
 	for (i = 0; i < nlines; i++)
-		fputs(lines[i], stdout);
+		puts(lines[i]);
 	return EXIT_SUCCESS;
 }
-- 
cgit v1.2.3-55-g6feb