Jeff King <peff@xxxxxxxx> writes: > We compute the length of a subset of a string, but then use that length > only to feed a "%.*s" printf placeholder for the same string. We can > just use "%s" to achieve the same thing. Heh, makes readers wonder why the original author wrote such a convoluted code. > The variable became useless in cb891a5989 (Use a strbuf for building up > section header and key/value pair strings., 2007-12-14), which swapped > out a write() which _did_ use the length for a strbuf_addf() call. And that history, i.e. the %.*s formatter being a direct translation from write(2), explains it. Thanks. > Signed-off-by: Jeff King <peff@xxxxxxxx> > --- > config.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/config.c b/config.c > index ff7998df46..7ea588a7e0 100644 > --- a/config.c > +++ b/config.c > @@ -2545,7 +2545,6 @@ static ssize_t write_pair(int fd, const char *key, const char *value, > { > int i; > ssize_t ret; > - int length = strlen(key + store->baselen + 1); > const char *quote = ""; > struct strbuf sb = STRBUF_INIT; > > @@ -2564,8 +2563,7 @@ static ssize_t write_pair(int fd, const char *key, const char *value, > if (i && value[i - 1] == ' ') > quote = "\""; > > - strbuf_addf(&sb, "\t%.*s = %s", > - length, key + store->baselen + 1, quote); > + strbuf_addf(&sb, "\t%s = %s", key + store->baselen + 1, quote); > > for (i = 0; value[i]; i++) > switch (value[i]) {