@@ -517,13 +517,18 @@ static int cb_tag_foreach(const char *name, git_oid *oid, void *data)
517517 return 0 ;
518518}
519519
520- static git_pobject * * compute_write_order ( git_packbuilder * pb )
520+ static int compute_write_order ( git_pobject * * * out , git_packbuilder * pb )
521521{
522522 size_t i , wo_end , last_untagged ;
523523 git_pobject * * wo ;
524524
525+ * out = NULL ;
526+
527+ if (!pb -> nr_objects )
528+ return 0 ;
529+
525530 if ((wo = git__mallocarray (pb -> nr_objects , sizeof (* wo ))) == NULL )
526- return NULL ;
531+ return -1 ;
527532
528533 for (i = 0 ; i < pb -> nr_objects ; i ++ ) {
529534 git_pobject * po = pb -> object_list + i ;
@@ -552,7 +557,7 @@ static git_pobject **compute_write_order(git_packbuilder *pb)
552557 */
553558 if (git_tag_foreach (pb -> repo , & cb_tag_foreach , pb ) < 0 ) {
554559 git__free (wo );
555- return NULL ;
560+ return -1 ;
556561 }
557562
558563 /*
@@ -609,10 +614,11 @@ static git_pobject **compute_write_order(git_packbuilder *pb)
609614 if (wo_end != pb -> nr_objects ) {
610615 git__free (wo );
611616 git_error_set (GIT_ERROR_INVALID , "invalid write order" );
612- return NULL ;
617+ return -1 ;
613618 }
614619
615- return wo ;
620+ * out = wo ;
621+ return 0 ;
616622}
617623
618624static int write_pack (git_packbuilder * pb ,
@@ -625,15 +631,15 @@ static int write_pack(git_packbuilder *pb,
625631 struct git_pack_header ph ;
626632 git_oid entry_oid ;
627633 size_t i = 0 ;
628- int error = 0 ;
634+ int error ;
629635
630- write_order = compute_write_order (pb );
631- if (write_order == NULL )
632- return -1 ;
636+ if ((error = compute_write_order (& write_order , pb )) < 0 )
637+ return error ;
633638
634639 if (!git__is_uint32 (pb -> nr_objects )) {
635640 git_error_set (GIT_ERROR_INVALID , "too many objects" );
636- return -1 ;
641+ error = -1 ;
642+ goto done ;
637643 }
638644
639645 /* Write pack header */
0 commit comments