diff options
| author | Xin LI <delphij@FreeBSD.org> | 2006-08-03 03:34:36 +0000 |
|---|---|---|
| committer | Xin LI <delphij@FreeBSD.org> | 2006-08-03 03:34:36 +0000 |
| commit | da4ab3aa26255af5ee62b5cf725dbbec9e4cd8c3 (patch) | |
| tree | 2ee5236a9f6a442cf9b77a7c2cd4753f229485ec /lib | |
| parent | 3e6a93dd95a3a149fc4d2e075d5feba76b9718d3 (diff) | |
Notes
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/libc/uuid/uuid_compare.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/libc/uuid/uuid_compare.c b/lib/libc/uuid/uuid_compare.c index f57a0944ca4a..420f3267191c 100644 --- a/lib/libc/uuid/uuid_compare.c +++ b/lib/libc/uuid/uuid_compare.c @@ -41,7 +41,8 @@ int32_t uuid_compare(const uuid_t *a, const uuid_t *b, uint32_t *status) { - int res; + int res; + int64_t res64; if (status != NULL) *status = uuid_s_ok; @@ -54,10 +55,19 @@ uuid_compare(const uuid_t *a, const uuid_t *b, uint32_t *status) if (b == NULL) return ((uuid_is_nil(a, NULL)) ? 0 : 1); - /* We have to compare the hard way. */ - res = (int)((int64_t)a->time_low - (int64_t)b->time_low); - if (res) - return ((res < 0) ? -1 : 1); + /* + * We have to compare the hard way. + * + * Note that time_low is defined as unsigned 32-bit + * integer, therefore, with a significantly large + * a->time_low and a small b->time_low, we will end + * up with a value which is larger than 0x7fffffff + * which is negative if casted to signed 32-bit + * integer. + */ + res64 = (int64_t)a->time_low - (int64_t)b->time_low; + if (res64) + return ((res64 < 0) ? -1 : 1); res = (int)a->time_mid - (int)b->time_mid; if (res) return ((res < 0) ? -1 : 1); |
