This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[committed] alpha: Use saturating arithmetic in memchr


Like the PRs for x86 and powerpc, alpha can overflow N
depending on alignment.


r~


	* sysdeps/alpha/memchr.c (__memchr): Use saturating arithmetic
	adjusting the byte count.
 
diff --git a/sysdeps/alpha/memchr.c b/sysdeps/alpha/memchr.c
index 82c42c0..402088d 100644
--- a/sysdeps/alpha/memchr.c
+++ b/sysdeps/alpha/memchr.c
@@ -53,7 +53,10 @@ __memchr (const void *s, int xc, size_t n)
   /* Align the source, and decrement the count by the number
      of bytes searched in the first word.  */
   s_align = (const word *)((word)s & -8);
-  n += ((word)s & 7);
+  {
+    size_t inc = n + ((word)s & 7);
+    n = inc | -(inc < n);
+  }
 
   /* Deal with misalignment in the first word for the comparison.  */
   mask = (1ul << ((word)s & 7)) - 1;
-- 
2.9.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]