@@ -74,8 +74,13 @@ addItem(xbps_array_t rdeps, const char *pkgn, const char *pkgver)
7474 return item ;
7575
7676 item = malloc (sizeof (* item ));
77- assert (item );
77+ if (!item )
78+ return NULL ;
7879 item -> pkgn = strdup (pkgn );
80+ if (!item -> pkgn ) {
81+ free (item );
82+ return NULL ;
83+ }
7984 item -> pkgver = pkgver ;
8085 item -> rdeps = rdeps ;
8186 item -> dbase = NULL ;
@@ -98,25 +103,33 @@ addDepn(struct item *item, struct item *xitem)
98103 xitem -> dbase = depn ;
99104}
100105
101- static void
106+ static int
102107add_deps_recursive (struct item * item , bool first )
103108{
104109 struct depn * dep ;
105110 xbps_string_t str ;
106111
107112 if (xbps_match_string_in_array (result , item -> pkgver ))
108- return ;
113+ return 0 ;
114+
115+ for (dep = item -> dbase ; dep ; dep = dep -> dnext ) {
116+ int r = add_deps_recursive (dep -> item , false);
117+ if (r < 0 )
118+ return r ;
119+ }
109120
110- for (dep = item -> dbase ; dep ; dep = dep -> dnext )
111- add_deps_recursive (dep -> item , false);
112121
113122 if (first )
114- return ;
123+ return 0 ;
115124
116125 str = xbps_string_create_cstring (item -> pkgver );
117- assert (str );
118- xbps_array_add_first (result , str );
126+ if (!str )
127+ return xbps_error_oom ();
128+
129+ if (!xbps_array_add_first (result , str ))
130+ return xbps_error_oom ();
119131 xbps_object_release (str );
132+ return 0 ;
120133}
121134
122135static void
@@ -154,16 +167,18 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool,
154167
155168 item = lookupItem (pkgname );
156169 if (item ) {
157- add_deps_recursive (item , depth == 0 );
170+ int r = add_deps_recursive (item , depth == 0 );
171+ if (r < 0 )
172+ return NULL ;
158173 return item ;
159174 }
160175
161- if (!xbps_dictionary_get_cstring_nocopy (pkgd , "pkgver" , & pkgver )) {
162- abort ();
163- }
176+ if (!xbps_dictionary_get_cstring_nocopy (pkgd , "pkgver" , & pkgver ))
177+ xbps_unreachable ();
164178
165179 item = addItem (rdeps , pkgname , pkgver );
166- assert (item );
180+ if (!item )
181+ return NULL ;
167182
168183 for (unsigned int i = 0 ; i < xbps_array_count (rdeps ); i ++ ) {
169184 xbps_dictionary_t curpkgd ;
@@ -202,19 +217,17 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool,
202217 continue ;
203218 }
204219 xitem = ordered_depends (xhp , curpkgd , rpool , depth + 1 );
205- if (xitem == NULL ) {
206- /* package depends on missing dependencies */
207- xbps_dbg_printf ("%s: missing dependency '%s'\n" , pkgver , curdep );
208- errno = ENODEV ;
220+ if (!xitem )
209221 return NULL ;
210- }
211- assert (xitem );
212222 addDepn (item , xitem );
213223 }
214224 /* all deps were processed, add item to head */
215225 if (depth > 0 && !xbps_match_string_in_array (result , item -> pkgver )) {
216226 str = xbps_string_create_cstring (item -> pkgver );
217- assert (str );
227+ if (!str ) {
228+ xbps_error_oom ();
229+ return NULL ;
230+ }
218231 xbps_array_add_first (result , str );
219232 xbps_object_release (str );
220233 }
@@ -227,7 +240,10 @@ xbps_get_pkg_fulldeptree(struct xbps_handle *xhp, const char *pkg, bool rpool)
227240 xbps_dictionary_t pkgd ;
228241
229242 result = xbps_array_create ();
230- assert (result );
243+ if (!result ) {
244+ xbps_error_oom ();
245+ return NULL ;
246+ }
231247
232248 if (rpool ) {
233249 if (((pkgd = xbps_rpool_get_pkg (xhp , pkg )) == NULL ) &&
0 commit comments