@@ -763,15 +763,13 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)
763763
764764 if (tag_closed && ctx -> cdata ) {
765765 if (!strcmp (ctx -> name , DAV_ACTIVELOCK_OWNER )) {
766- lock -> owner = xmalloc (strlen (ctx -> cdata ) + 1 );
767- strcpy (lock -> owner , ctx -> cdata );
766+ lock -> owner = xstrdup (ctx -> cdata );
768767 } else if (!strcmp (ctx -> name , DAV_ACTIVELOCK_TIMEOUT )) {
769768 const char * arg ;
770769 if (skip_prefix (ctx -> cdata , "Second-" , & arg ))
771770 lock -> timeout = strtol (arg , NULL , 10 );
772771 } else if (!strcmp (ctx -> name , DAV_ACTIVELOCK_TOKEN )) {
773- lock -> token = xmalloc (strlen (ctx -> cdata ) + 1 );
774- strcpy (lock -> token , ctx -> cdata );
772+ lock -> token = xstrdup (ctx -> cdata );
775773
776774 git_SHA1_Init (& sha_ctx );
777775 git_SHA1_Update (& sha_ctx , lock -> token , strlen (lock -> token ));
@@ -852,8 +850,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
852850 struct xml_ctx ctx ;
853851 char * escaped ;
854852
855- url = xmalloc (strlen (repo -> url ) + strlen (path ) + 1 );
856- sprintf (url , "%s%s" , repo -> url , path );
853+ url = xstrfmt ("%s%s" , repo -> url , path );
857854
858855 /* Make sure leading directories exist for the remote ref */
859856 ep = strchr (url + strlen (repo -> url ) + 1 , '/' );
@@ -1125,7 +1122,7 @@ static void remote_ls(const char *path, int flags,
11251122 void (* userFunc )(struct remote_ls_ctx * ls ),
11261123 void * userData )
11271124{
1128- char * url = xmalloc ( strlen ( repo -> url ) + strlen ( path ) + 1 );
1125+ char * url = xstrfmt ( "%s%s" , repo -> url , path );
11291126 struct active_request_slot * slot ;
11301127 struct slot_results results ;
11311128 struct strbuf in_buffer = STRBUF_INIT ;
@@ -1141,8 +1138,6 @@ static void remote_ls(const char *path, int flags,
11411138 ls .userData = userData ;
11421139 ls .userFunc = userFunc ;
11431140
1144- sprintf (url , "%s%s" , repo -> url , path );
1145-
11461141 strbuf_addf (& out_buffer .buf , PROPFIND_ALL_REQUEST );
11471142
11481143 dav_headers = curl_slist_append (dav_headers , "Depth: 1" );
@@ -1544,10 +1539,9 @@ static void update_remote_info_refs(struct remote_lock *lock)
15441539
15451540static int remote_exists (const char * path )
15461541{
1547- char * url = xmalloc ( strlen ( repo -> url ) + strlen ( path ) + 1 );
1542+ char * url = xstrfmt ( "%s%s" , repo -> url , path );
15481543 int ret ;
15491544
1550- sprintf (url , "%s%s" , repo -> url , path );
15511545
15521546 switch (http_get_strbuf (url , NULL , NULL )) {
15531547 case HTTP_OK :
@@ -1567,13 +1561,10 @@ static int remote_exists(const char *path)
15671561
15681562static void fetch_symref (const char * path , char * * symref , unsigned char * sha1 )
15691563{
1570- char * url ;
1564+ char * url = xstrfmt ( "%s%s" , repo -> url , path ) ;
15711565 struct strbuf buffer = STRBUF_INIT ;
15721566 const char * name ;
15731567
1574- url = xmalloc (strlen (repo -> url ) + strlen (path ) + 1 );
1575- sprintf (url , "%s%s" , repo -> url , path );
1576-
15771568 if (http_get_strbuf (url , & buffer , NULL ) != HTTP_OK )
15781569 die ("Couldn't get %s for remote symref\n%s" , url ,
15791570 curl_errorstr );
@@ -1682,8 +1673,7 @@ static int delete_remote_branch(const char *pattern, int force)
16821673 fprintf (stderr , "Removing remote branch '%s'\n" , remote_ref -> name );
16831674 if (dry_run )
16841675 return 0 ;
1685- url = xmalloc (strlen (repo -> url ) + strlen (remote_ref -> name ) + 1 );
1686- sprintf (url , "%s%s" , repo -> url , remote_ref -> name );
1676+ url = xstrfmt ("%s%s" , repo -> url , remote_ref -> name );
16871677 slot = get_active_slot ();
16881678 slot -> results = & results ;
16891679 curl_setup_http_get (slot -> curl , url , DAV_DELETE );
0 commit comments