From 485fdbde414c6ae57612d12d9e679c56d3be8680 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 3 Jan 2018 12:13:55 +0100 Subject: [PATCH] [string] Allow length to handle NULs printf 'a\0b' | string length used to print "1". Now it prints "3". Note that this switches to using C++'s std::string::length, which might give differing results. --- src/builtin_string.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/builtin_string.cpp b/src/builtin_string.cpp index cdfc1c6f9..ae5cae999 100644 --- a/src/builtin_string.cpp +++ b/src/builtin_string.cpp @@ -681,8 +681,8 @@ static int string_length(parser_t &parser, io_streams_t &streams, int argc, wcha int nnonempty = 0; arg_iterator_t aiter(argv, optind, streams); - while (const wchar_t *arg = aiter.next()) { - size_t n = wcslen(arg); + while (auto arg = aiter.nextstr()) { + size_t n = arg->length(); if (n > 0) { nnonempty++; }