]> git.proxmox.com Git - mirror_frr.git/commitdiff
tests: fix endian bug in test_typelist
authorMark Stapp <mjs@voltanet.io>
Wed, 18 Dec 2019 15:52:08 +0000 (10:52 -0500)
committerMark Stapp <mjs@voltanet.io>
Wed, 18 Dec 2019 19:28:35 +0000 (14:28 -0500)
[7.2 version] Fix a byte-swapping bug that appeared on
big-endian arch but wasn't visible on little-endian.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
tests/lib/test_typelist.h

index 7ff210cae3b1137d7631fcbe55fbf737bc96fe9a..6bb7e922994b544f7e79413559d88db9a6bcd066 100644 (file)
@@ -98,12 +98,13 @@ static void ts_hash(const char *text, const char *expect)
        unsigned i = 0;
        uint8_t hash[32];
        char hashtext[65];
-       uint32_t count;
+       uint32_t swap_count, count;
 
-       count = htonl(list_count(&head));
+       count = list_count(&head);
+       swap_count = htonl(count);
 
        SHA256_Init(&ctx);
-       SHA256_Update(&ctx, &count, sizeof(count));
+       SHA256_Update(&ctx, &swap_count, sizeof(swap_count));
 
        frr_each (list, &head, item) {
                struct {
@@ -115,7 +116,7 @@ static void ts_hash(const char *text, const char *expect)
                };
                SHA256_Update(&ctx, &hashitem, sizeof(hashitem));
                i++;
-               assert(i < count);
+               assert(i <= count);
        }
        SHA256_Final(hash, &ctx);