about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-10-19 15:24:10 +0200
committerLeah Neukirchen <leah@vuxu.org>2017-10-19 15:24:10 +0200
commit9dc36f2b1a3267f9dc52c9b59ee6167cb503611b (patch)
treefc31c0ddc5cc0117b72b13c795541ea5bc2149b5
parent1a6145ed267ef9e4db44282ca613abc992c0e359 (diff)
downloadnecho-9dc36f2b1a3267f9dc52c9b59ee6167cb503611b.tar.gz
necho-9dc36f2b1a3267f9dc52c9b59ee6167cb503611b.tar.xz
necho-9dc36f2b1a3267f9dc52c9b59ee6167cb503611b.zip
fix secho without arguments
-rw-r--r--necho.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/necho.c b/necho.c
index 56fdf4d..c02561d 100644
--- a/necho.c
+++ b/necho.c
@@ -97,15 +97,19 @@ main(int argc, char *argv[])
 		}
 	} else if (*style == 'j' || (*style == 's' || *style == 'e')) {
 		struct iovec iov[SENSIBLE_IOV_MAX];
-		int j;
+		int j = 0;
 
-		for (i = 1; i < argc; ) {
+		i = 1;
+		if (argc == 1 && *style != 'j')
+			goto just_nl;
+		while (i < argc) {
 			for (j = 0; i < argc && j < SENSIBLE_IOV_MAX - 1; j++) {
 				iov[j].iov_base = argv[i];
 				iov[j].iov_len = strlen(argv[i]);
 				i++;
 				if (*style != 'j') {
 					j++;
+just_nl:
 					iov[j].iov_base = i == argc ? "\n" : " ";
 					iov[j].iov_len = 1;
 				}