|
|
75e927 |
From 168275c3f4ffe9d0e09ed7a3789b45b440416f73 Mon Sep 17 00:00:00 2001
|
|
|
75e927 |
From: Nikolai Kondrashov <Nikolai.Kondrashov@redhat.com>
|
|
|
75e927 |
Date: Wed, 1 Oct 2014 16:32:11 +0300
|
|
|
75e927 |
Subject: [PATCH 4/4] Don't assume little-endian in fr_prints_uint128
|
|
|
75e927 |
|
|
|
75e927 |
Add handling of big-endian architectures to fr_prints_uint128.
|
|
|
75e927 |
---
|
|
|
75e927 |
src/lib/misc.c | 13 ++++++++++---
|
|
|
75e927 |
1 file changed, 10 insertions(+), 3 deletions(-)
|
|
|
75e927 |
|
|
|
75e927 |
diff --git a/src/lib/misc.c b/src/lib/misc.c
|
|
|
75e927 |
index 66171ff..d0ccd6c 100644
|
|
|
75e927 |
--- a/src/lib/misc.c
|
|
|
75e927 |
+++ b/src/lib/misc.c
|
|
|
75e927 |
@@ -1366,6 +1366,13 @@ size_t fr_prints_uint128(char *out, size_t outlen, uint128_t const num)
|
|
|
75e927 |
uint64_t n[2];
|
|
|
75e927 |
char *p = buff;
|
|
|
75e927 |
int i;
|
|
|
75e927 |
+#ifdef RADIUS_LITTLE_ENDIAN
|
|
|
75e927 |
+ const size_t l = 0;
|
|
|
75e927 |
+ const size_t h = 1;
|
|
|
75e927 |
+#else
|
|
|
75e927 |
+ const size_t l = 1;
|
|
|
75e927 |
+ const size_t h = 0;
|
|
|
75e927 |
+#endif
|
|
|
75e927 |
|
|
|
75e927 |
memset(buff, '0', sizeof(buff) - 1);
|
|
|
75e927 |
buff[sizeof(buff) - 1] = '\0';
|
|
|
75e927 |
@@ -1376,11 +1383,11 @@ size_t fr_prints_uint128(char *out, size_t outlen, uint128_t const num)
|
|
|
75e927 |
ssize_t j;
|
|
|
75e927 |
int carry;
|
|
|
75e927 |
|
|
|
75e927 |
- carry = (n[1] >= 0x8000000000000000);
|
|
|
75e927 |
+ carry = (n[h] >= 0x8000000000000000);
|
|
|
75e927 |
|
|
|
75e927 |
// Shift n[] left, doubling it
|
|
|
75e927 |
- n[1] = ((n[1] << 1) & 0xffffffffffffffff) + (n[0] >= 0x8000000000000000);
|
|
|
75e927 |
- n[0] = ((n[0] << 1) & 0xffffffffffffffff);
|
|
|
75e927 |
+ n[h] = ((n[h] << 1) & 0xffffffffffffffff) + (n[l] >= 0x8000000000000000);
|
|
|
75e927 |
+ n[l] = ((n[l] << 1) & 0xffffffffffffffff);
|
|
|
75e927 |
|
|
|
75e927 |
// Add s[] to itself in decimal, doubling it
|
|
|
75e927 |
for (j = sizeof(buff) - 2; j >= 0; j--) {
|
|
|
75e927 |
--
|
|
|
75e927 |
2.1.0
|
|
|
75e927 |
|