]> git.puffer.fish Git - mirror/frr.git/commitdiff
tests: fix endian bug in test_typelist 5559/head
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 15:52:08 +0000 (10:52 -0500)
Fix a byte-swapping bug that appeared on big-endian arch but
wasn't visible on little-endian runs.

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

index f20bbc52d9bff902b242b0839d66d82de49d4f89..9039fa8a464d56647b9e3f1d6475fce0625d8e0f 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);