Bug 917593 - Don't assert for zero-length strings. r=Waldo
☠☠ backed out by 1f690939a3a5 ☠ ☠
authorBobby Holley <bobbyholley@gmail.com>
Tue, 24 Sep 2013 08:03:22 -0700
changeset 163214 74459407359ac077b1290fc66c96c71a91ea43d9
parent 163213 b2a1a3380913819867d041d8a835e9c7407e9179
child 163215 3ff5b10e125bcc303769955cdc0dba93c6212cf5
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs917593
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 917593 - Don't assert for zero-length strings. r=Waldo
mfbt/Endian.h
mfbt/tests/TestEndian.cpp
--- a/mfbt/Endian.h
+++ b/mfbt/Endian.h
@@ -233,19 +233,19 @@ class EndianUtils
     /**
      * Assert that the memory regions [dest, dest+count) and [src, src+count]
      * do not overlap.  count is given in bytes.
      */
     static void assertNoOverlap(const void* dest, const void* src, size_t count)
     {
       DebugOnly<const uint8_t*> byteDestPtr = static_cast<const uint8_t*>(dest);
       DebugOnly<const uint8_t*> byteSrcPtr = static_cast<const uint8_t*>(src);
-      MOZ_ASSERT((byteDestPtr < byteSrcPtr &&
+      MOZ_ASSERT((byteDestPtr <= byteSrcPtr &&
                   byteDestPtr + count <= byteSrcPtr) ||
-                 (byteSrcPtr < byteDestPtr &&
+                 (byteSrcPtr <= byteDestPtr &&
                   byteSrcPtr + count <= byteDestPtr));
     }
 
     template<typename T>
     static void assertAligned(T* ptr)
     {
       MOZ_ASSERT((uintptr_t(ptr) % sizeof(T)) == 0, "Unaligned pointer!");
     }
--- a/mfbt/tests/TestEndian.cpp
+++ b/mfbt/tests/TestEndian.cpp
@@ -391,10 +391,15 @@ main()
 
   TestBulkInPlaceNoSwap(uint16_values);
   TestBulkInPlaceNoSwap(int16_values);
   TestBulkInPlaceNoSwap(uint32_values);
   TestBulkInPlaceNoSwap(int32_values);
   TestBulkInPlaceNoSwap(uint64_values);
   TestBulkInPlaceNoSwap(int64_values);
 
+  // Make sure we don't incorrectly cry overlap for zero-length buffers.
+  uint64_t scratch = 0xdeadbeef;
+  NativeEndian::copyAndSwapFromLittleEndian(&scratch, &scratch, 0);
+  MOZ_ASSERT(scratch == 0xdeadbeef);
+
   return 0;
 }