[llvm-commits] [compiler-rt] r166774 - in /compiler-rt/trunk/lib/sanitizer_common: sanitizer_libc.cc tests/CMakeLists.txt tests/sanitizer_libc_test.cc
Alexander Potapenko
glider at google.com
Fri Oct 26 06:24:21 PDT 2012
Author: glider
Date: Fri Oct 26 08:24:20 2012
New Revision: 166774
URL: http://llvm.org/viewvc/llvm-project?rev=166774&view=rev
Log:
Fix the internal_memmove() implementation that used to skip src[0] if dst < src.
Added:
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc (with props)
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.cc
compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.cc?rev=166774&r1=166773&r2=166774&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.cc Fri Oct 26 08:24:20 2012
@@ -47,13 +47,14 @@
void *internal_memmove(void *dest, const void *src, uptr n) {
char *d = (char*)dest;
char *s = (char*)src;
- uptr i;
+ sptr i = (sptr)n;
+ CHECK_GE(i, 0);
if (d < s) {
for (i = 0; i < n; ++i)
d[i] = s[i];
} else {
if (d > s && n > 0)
- for (i = n - 1; i > 0 ; --i) {
+ for (i = n - 1; i >= 0 ; --i) {
d[i] = s[i];
}
}
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt?rev=166774&r1=166773&r2=166774&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt Fri Oct 26 08:24:20 2012
@@ -2,6 +2,7 @@
sanitizer_allocator_test.cc
sanitizer_common_test.cc
sanitizer_flags_test.cc
+ sanitizer_libc_test.cc
sanitizer_list_test.cc
sanitizer_stackdepot_test.cc
sanitizer_test_main.cc
Added: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc?rev=166774&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc (added)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc Fri Oct 26 08:24:20 2012
@@ -0,0 +1,22 @@
+//===-- sanitizer_libc_test.cc --------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// Tests for sanitizer_libc.h.
+//===----------------------------------------------------------------------===//
+
+#include "sanitizer_common/sanitizer_libc.h"
+#include "gtest/gtest.h"
+
+// A regression test for internal_memmove() implementation.
+TEST(SanitizerCommon, InternalMemmoveRegression) {
+ char src[] = "Hello World";
+ char *dest = src + 6;
+ __sanitizer::internal_memmove(dest, src, 5);
+ EXPECT_EQ(dest[0], src[0]);
+ EXPECT_EQ(dest[4], src[4]);
+}
Propchange: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc
------------------------------------------------------------------------------
svn:eol-style = LF
More information about the llvm-commits
mailing list