Skip to content

Commit 8bb7a54

Browse files
drafnelgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ff55c47 commit 8bb7a54

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

contrib/credential/gnome-keyring/git-credential-gnome-keyring.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,13 @@ static inline char *xstrdup(const char *str)
112112
/* create a special keyring option string, if path is given */
113113
static char* keyring_object(struct credential *c)
114114
{
115-
char* object = NULL;
116-
117115
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;
123117

124118
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);
128120

129-
return object;
121+
return g_strdup_printf("%s/%s", c->host, c->path);
130122
}
131123

132124
static int keyring_get(struct credential *c)

0 commit comments

Comments
 (0)