svn commit: r201089 - head/lib/libarchive

Tim Kientzle kientzle at FreeBSD.org
Mon Dec 28 02:20:24 UTC 2009


Author: kientzle
Date: Mon Dec 28 02:20:23 2009
New Revision: 201089
URL: http://svn.freebsd.org/changeset/base/201089

Log:
  Portability: terminate abnormally via abort() instead of segfault,
  watch the return value from write(), and avoid signed arithmetic on
  unsigned values.

Modified:
  head/lib/libarchive/archive_check_magic.c

Modified: head/lib/libarchive/archive_check_magic.c
==============================================================================
--- head/lib/libarchive/archive_check_magic.c	Mon Dec 28 02:18:55 2009	(r201088)
+++ head/lib/libarchive/archive_check_magic.c	Mon Dec 28 02:20:23 2009	(r201089)
@@ -50,7 +50,16 @@ __FBSDID("$FreeBSD$");
 static void
 errmsg(const char *m)
 {
-	write(2, m, strlen(m));
+	size_t s = strlen(m);
+	ssize_t written;
+
+	while (s > 0) {
+		written = write(2, m, strlen(m));
+		if (written <= 0)
+			return;
+		m += written;
+		s -= written;
+	}
 }
 
 static void
@@ -60,8 +69,7 @@ diediedie(void)
 	/* Cause a breakpoint exception  */
 	DebugBreak();
 #endif
-	*(char *)0 = 1;	/* Deliberately segfault and force a coredump. */
-	_exit(1);	/* If that didn't work, just exit with an error. */
+	abort();        /* Terminate the program abnormally. */
 }
 
 static const char *
@@ -85,7 +93,7 @@ write_all_states(unsigned int states)
 	unsigned int lowbit;
 
 	/* A trick for computing the lowest set bit. */
-	while ((lowbit = states & (-states)) != 0) {
+	while ((lowbit = states & (1 + ~states)) != 0) {
 		states &= ~lowbit;		/* Clear the low bit. */
 		errmsg(state_name(lowbit));
 		if (states != 0)


More information about the svn-src-head mailing list