We parse the INFINITE_DEPTH constant into a static,
fixed-size buffer using sprintf. This buffer is sufficiently
large for the current constant, but it's a suspicious
pattern, as the constant is defined far away, and it's not
immediately obvious that 12 bytes are large enough to hold
it.

We can just use xstrfmt here, which gets rid of any question
of the buffer size. It also removes any concerns with object
lifetime, which means we do not have to wonder why this
buffer deep within a conditional is marked "static" (we
never free our newly allocated result, of course, but that's
OK; it's global that lasts the lifetime of the whole program
anyway).

Signed-off-by: Jeff King <p...@peff.net>
---
 builtin/fetch.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/builtin/fetch.c b/builtin/fetch.c
index 9a3869f..4703725 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1156,11 +1156,8 @@ int cmd_fetch(int argc, const char **argv, const char 
*prefix)
                        die(_("--depth and --unshallow cannot be used 
together"));
                else if (!is_repository_shallow())
                        die(_("--unshallow on a complete repository does not 
make sense"));
-               else {
-                       static char inf_depth[12];
-                       sprintf(inf_depth, "%d", INFINITE_DEPTH);
-                       depth = inf_depth;
-               }
+               else
+                       depth = xstrfmt("%d", INFINITE_DEPTH);
        }
 
        /* no need to be strict, transport_set_option() will validate it again 
*/
-- 
2.6.0.rc2.408.ga2926b9

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to