PERFORCE change 178992 for review

Garrett Cooper gcooper at FreeBSD.org
Mon May 31 01:24:22 UTC 2010


http://p4web.freebsd.org/@@178992?ac=10

Change 178992 by gcooper at gcooper-bayonetta on 2010/05/31 01:23:45

	Actually, instead of just adding useless warnings, let's fix the
	add_plist* APIs to use proper return codes when new_plist_entry fails.

Affected files ...

.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/lib/libpkg/pkg.h#12 edit
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/lib/libpkg/plist.c#10 edit

Differences ...

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/lib/libpkg/pkg.h#12 (text+ko) ====

@@ -193,8 +193,8 @@
 void		free_plist(Package *);
 void		mark_plist(Package *);
 void		csum_plist_entry(char *, PackingList);
-void		add_plist(Package *, plist_t, const char *);
-void		add_plist_top(Package *, plist_t, const char *);
+int		add_plist(Package *, plist_t, const char *);
+int		add_plist_top(Package *, plist_t, const char *);
 void		delete_plist(Package *pkg, Boolean all, plist_t type,
 		    const char *name);
 int		write_plist(Package *, FILE *);

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/lib/libpkg/plist.c#10 (text+ko) ====

@@ -35,19 +35,22 @@
 #include "pkg.h"
 
 /*
- * Add an item to a packing list
+ * Add an item to the tail of a packing list.
  *
- * FIXME: this will `silently fail' until the next point when p is
- * dereferenced.
+ * Returns 0 on success, -1 on failure (errno will be set appropriate to
+ * errors with malloc(3)).
  */
-void
+int
 add_plist(Package *p, plist_t type, const char *arg)
 {
 	PackingList tmp;
+	int retcode = 0;
 
 	tmp = new_plist_entry();
 
-	if (tmp != NULL) {
+	if (tmp == NULL)
+		retcode = -1;
+	else
 
 		tmp->name = copy_string(arg);
 		tmp->type = type;
@@ -74,20 +77,27 @@
 
 	}
 
+	return retcode;
+
 }
 
 /*
- * FIXME: this will `silently fail' until the next point when p is
- * dereferenced.
+ * Add an element to the top of the plist.
+ *
+ * Returns 0 on success, -1 on failure (errno will be set appropriate to
+ * errors with malloc(3)).
  */
-void
+int
 add_plist_top(Package *p, plist_t type, const char *arg)
 {
 	PackingList tmp;
+	int retcode = 0;
 
 	tmp = new_plist_entry();
 
-	if (tmp != NULL) {
+	if (tmp == NULL)
+		retcode = -1;
+	else
 
 		tmp->name = copy_string(arg);
 		tmp->type = type;
@@ -102,6 +112,8 @@
 
 	}
 
+	return retcode;
+
 }
 
 /* Return the last (most recent) entry in a packing list */
@@ -436,11 +448,19 @@
 			 */
 			if (retcode == 0) {
 
-				add_plist(pkg, cmd, cp);
-				start = end;
-				/* We aren't at the end of the line, yet.. */
-				if (start != '\0')
-					start++;
+				if (add_plist(pkg, cmd, cp) == -1)
+					retcode = -1;
+				else {
+
+					start = end;
+					/* 
+					 * We aren't at the end of the line,
+					 * yet..
+					 */
+					if (start != '\0')
+						start++;
+
+				}
 
 			}
 


More information about the p4-projects mailing list