[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.
This commit is contained in:
Fabian Homborg 2018-01-03 12:13:55 +01:00
parent bcd23ff971
commit 485fdbde41

View file

@ -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++;
}