Fix surfaceflinger on integer sanitized builds.

Refactors unsigned integer overflows in do_compare to fix integer
overflow sanitized builds. Also disables sanitization in
Layer::makeTraversalList.

Test: Compiled and checked output from sanitizer.
Bug: 30969751
Change-Id: I1a6d73435495e8b3ba3edb2587f62e4a0f2662f3
Merged-In: I1a6d73435495e8b3ba3edb2587f62e4a0f2662f3
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index ca9a546..7a6d204 100755
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -70,7 +70,7 @@
     :   contentDirty(false),
         sequence(uint32_t(android_atomic_inc(&sSequence))),
         mFlinger(flinger),
-        mTextureName(-1U),
+        mTextureName(UINT32_MAX),
         mPremultipliedAlpha(true),
         mName("unnamed"),
         mFormat(PIXEL_FORMAT_NONE),
@@ -2659,6 +2659,7 @@
     return mDrawingState.z;
 }
 
+__attribute__((no_sanitize("unsigned-integer-overflow")))
 LayerVector Layer::makeTraversalList(LayerVector::StateSet stateSet) {
     LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid,
                         "makeTraversalList received invalid stateSet");