Fixed memcmp error (checks 1 more byte than it should)
[tpg/acess2.git] / Kernel / arch / x86 / lib.c
index f3f190d..1f56394 100644 (file)
@@ -85,7 +85,7 @@ void SHORTLOCK(struct sShortSpinlock *Lock)
                        : "=a"(v)
                        : "a"(0), "r"(cpu), "r"(&Lock->Lock)
                        );
-               #elseif STACKED_LOCKS == 2
+               #elif STACKED_LOCKS == 2
                __ASM__("lock cmpxchgl %2, (%3)"
                        : "=a"(v)
                        : "a"(0), "r"(thread), "r"(&Lock->Lock)
@@ -189,13 +189,16 @@ void *memsetd(void *Dest, Uint32 Val, size_t Num)
  */
 int memcmp(const void *m1, const void *m2, size_t Num)
 {
+       if( Num == 0 )  return 0;       // No bytes are always identical
+       
        while(Num--)
        {
-               if(*(Uint8*)m1 != *(Uint8*)m2)  break;
+               if(*(Uint8*)m1 != *(Uint8*)m2)
+                       return *(Uint8*)m1 - *(Uint8*)m2;
                m1 ++;
                m2 ++;
        }
-       return *(Uint8*)m1 - *(Uint8*)m2;
+       return 0;
 }
 
 /**

UCC git Repository :: git.ucc.asn.au