From 04b8418b54a80b0560f29c9ed4bb06e9aab71af8 Mon Sep 17 00:00:00 2001 From: Stefan Kalkowski Date: Tue, 22 Jan 2013 10:51:32 +0100 Subject: [PATCH] Let memcmp correspond to the C standard (fix #628) By now, the memcmp implementation of Genode's basic string utilities just returned whether two memory blocks are equal or differ. It gave no hint which block is greater, or lesser than the other one. This isn't the behaviour anticipated by implementations that rely on the C standard memcmp, e.g. GCC's libsupc++, or the nic_bridge's AVL tree implementation. --- base/include/util/string.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/base/include/util/string.h b/base/include/util/string.h index eea652e25..f47f7dc23 100644 --- a/base/include/util/string.h +++ b/base/include/util/string.h @@ -154,19 +154,18 @@ namespace Genode { /** * Compare memory blocks * - * \retval 0 memory blocks are equal - * \retval 1 memory blocks differ - * - * NOTE: This function is not fully compatible to the C standard. + * \retval 0 memory blocks are equal + * \retval <0 first memory block is less than second one + * \retval >0 first memory block is greater than second one */ inline int memcmp(const void *p0, const void *p1, size_t size) { - char *c0 = (char *)p0; - char *c1 = (char *)p1; + const unsigned char *c0 = (const unsigned char *)p0; + const unsigned char *c1 = (const unsigned char *)p1; size_t i; for (i = 0; i < size; i++) - if (c0[i] != c1[i]) return 1; + if (c0[i] != c1[i]) return c0[i] - c1[i]; return 0; }