From 9dc36f2b1a3267f9dc52c9b59ee6167cb503611b Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Thu, 19 Oct 2017 15:24:10 +0200 Subject: fix secho without arguments --- necho.c | 8 ++++++-- 1 file 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; } -- cgit 1.4.1