contrib/git-credential-gnome-keyring.c: use gnome helpers in keyring_object()

Rather than carefully allocating memory for sprintf() to write into, let's make use of the glib helper function g_strdup_printf(), which makes things a lot easier and less error-prone. Signed-off-by: Brandon Casey <drafnel@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Casey committed Sep 23, 2013 at 11:49 UTC 8bb7a54c57d5bd8113886fc04be8d22d10337eef
1 file changed +3 -11
contrib/credential/gnome-keyring/git-credential-gnome-keyring.c
+3 -11
@@ -112,21 +112,13 @@ static inline char *xstrdup(const char *str)
112 /* create a special keyring option string, if path is given */
113 static char* keyring_object(struct credential *c)
114 {
115 - char* object = NULL;
116 -
115 if (!c->path)
118 - return object;
119 -
120 - object = (char*) malloc(strlen(c->host)+strlen(c->path)+8);
121 - if (!object)
122 - die_errno(errno);
116 + return NULL;
117
118 if (c->port)
125 - sprintf(object,"%s:%hd/%s",c->host,c->port,c->path);
126 - else
127 - sprintf(object,"%s/%s",c->host,c->path);
119 + return g_strdup_printf("%s:%hd/%s", c->host, c->port, c->path);
120
129 - return object;
121 + return g_strdup_printf("%s/%s", c->host, c->path);
122 }
123
124 static int keyring_get(struct credential *c)