[asterisk-commits] tilghman: branch 1.8 r281085 - /branches/1.8/main/utils.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Aug 6 13:57:15 CDT 2010


Author: tilghman
Date: Fri Aug  6 13:57:10 2010
New Revision: 281085

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=281085
Log:
Fix alignment of stringfields on the SPARC platform

(closes issue #17789)
 Reported by: Ian Mason
 Patches: 
       20100806__issue17789__2.diff.txt uploaded by tilghman (license 14)
 Tested by: Ian_Mason

Modified:
    branches/1.8/main/utils.c

Modified: branches/1.8/main/utils.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/utils.c?view=diff&rev=281085&r1=281084&r2=281085
==============================================================================
--- branches/1.8/main/utils.c (original)
+++ branches/1.8/main/utils.c Fri Aug  6 13:57:10 2010
@@ -1615,7 +1615,8 @@
 	size_t space = (*pool_head)->size - (*pool_head)->used;
 	size_t to_alloc = needed + sizeof(ast_string_field_allocation);
 
-	if (__builtin_expect(to_alloc > space, 0)) {
+	/* This +1 accounts for alignment on SPARC */
+	if (__builtin_expect(to_alloc + 1 > space, 0)) {
 		size_t new_size = (*pool_head)->size;
 
 		while (new_size < to_alloc) {
@@ -1632,6 +1633,13 @@
 	}
 
 	result = (*pool_head)->base + (*pool_head)->used;
+#ifdef __sparc__
+	/* SPARC requires that the allocation field be aligned. */
+	if ((long) result % sizeof(ast_string_field_allocation)) {
+		result++;
+		(*pool_head)->used++;
+	}
+#endif
 	(*pool_head)->used += to_alloc;
 	(*pool_head)->active += needed;
 	result += sizeof(ast_string_field_allocation);
@@ -1706,6 +1714,12 @@
 		}
 	} else {
 		target = (*pool_head)->base + (*pool_head)->used + sizeof(ast_string_field_allocation);
+#ifdef __sparc__
+		if ((long) target % sizeof(ast_string_field_allocation)) {
+			target++;
+			space--;
+		}
+#endif
 		available = space - sizeof(ast_string_field_allocation);
 	}
 




More information about the asterisk-commits mailing list