aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtin-name-rev.c5
-rw-r--r--git-compat-util.h3
2 files changed, 7 insertions, 1 deletions
diff --git a/builtin-name-rev.c b/builtin-name-rev.c
index c02222436..ef1638590 100644
--- a/builtin-name-rev.c
+++ b/builtin-name-rev.c
@@ -58,7 +58,10 @@ copy_data:
parents = parents->next, parent_number++) {
if (parent_number > 1) {
int len = strlen(tip_name);
- char *new_name = xmalloc(len + 8);
+ char *new_name = xmalloc(len +
+ 1 + decimal_length(generation) + /* ~<n> */
+ 1 + 2 + /* ^NN */
+ 1);
if (len > 2 && !strcmp(tip_name + len - 2, "^0"))
len -= 2;
diff --git a/git-compat-util.h b/git-compat-util.h
index bd93b6257..7ed8b88b1 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -13,6 +13,9 @@
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
+/* Approximation of the length of the decimal representation of this type. */
+#define decimal_length(x) ((int)(sizeof(x) * 2.56 + 0.5) + 1)
+
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#define _XOPEN_SOURCE 600 /* glibc2 and AIX 5.3L need 500, OpenBSD needs 600 for S_ISLNK() */
#define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */