@matheusbsbs / matheus-bagliano / commits / 6c7e6963c1
Fork 0

config: drop useless length variable in write_pair()

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. 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. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Apr 10, 2020 at 15:44 UTC 6c7e6963c1b6d9a5344345d55dd537e4ab45158f
1 file changed +1 -3
config.c
+1 -3
@@ -2545,7 +2545,6 @@ static ssize_t write_pair(int fd, const char *key, const char *value,
2545 {
2546 int i;
2547 ssize_t ret;
2548 - int length = strlen(key + store->baselen + 1);
2548 const char *quote = "";
2549 struct strbuf sb = STRBUF_INIT;
2550
@@ -2564,8 +2563,7 @@ static ssize_t write_pair(int fd, const char *key, const char *value,
2563 if (i && value[i - 1] == ' ')
2564 quote = "\"";
2565
2567 - strbuf_addf(&sb, "\t%.*s = %s",
2568 - length, key + store->baselen + 1, quote);
2566 + strbuf_addf(&sb, "\t%s = %s", key + store->baselen + 1, quote);
2567
2568 for (i = 0; value[i]; i++)
2569 switch (value[i]) {