Jeff King schrieb:
quoted hunk ↗ jump to hunk
@@ -209,11 +209,14 @@ static size_t quote_c_style_counted(const char *name, ssize_t maxlen,
size_t len, count = 0;
const char *p = name;
+ if (maxlen < 0)
+ maxlen = strlen(name);
+
for (;;) {
int ch;
len = next_quote_pos(p, maxlen);
- if (len == maxlen || !p[len])
+ if (len == maxlen)
break;
if (!no_dq && p == name)@@ -223,6 +226,7 @@ static size_t quote_c_style_counted(const char *name, ssize_t maxlen,
EMIT('\\');
p += len;
ch = (unsigned char)*p++;
+ maxlen -= len + 1;
Couldn't you just write
if (0 <= maxlen)
maxlen -= len + 1;
to avoid the strlen(), because the rest of the loop is actually OK when
maxlen == -1, isn't it?
-- Hannes