Skip to content

Commit bd9e806

Browse files
committed
printer lyb BUGFIX count byte order
1 parent 20b8b81 commit bd9e806

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

compat/compat.h.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,27 @@
9696
(((val) << 40) & 0x00FF000000000000) | (((val) << 56) & 0xFF00000000000000) )
9797
#endif
9898

99+
#undef le16toh
99100
#undef le32toh
100101
#undef le64toh
102+
#undef htole16
101103
#undef htole32
102104
#undef htole64
103105

104106
#cmakedefine IS_BIG_ENDIAN
105107

106108
#ifdef IS_BIG_ENDIAN
109+
# define le16toh(x) bswap_16(x)
107110
# define le32toh(x) bswap_32(x)
108111
# define le64toh(x) bswap64(x)
112+
# define htole16(x) bswap_16(x)
109113
# define htole32(x) bswap_32(x)
110114
# define htole64(x) bswap64(x)
111115
#else
116+
# define le16toh(x) (x)
112117
# define le32toh(x) (x)
113118
# define le64toh(x) (x)
119+
# define htole16(x) (x)
114120
# define htole32(x) (x)
115121
# define htole64(x) (x)
116122
#endif

src/printer_lyb.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ static LY_ERR
415415
lyb_write_count(uint32_t count, struct lylyb_print_ctx *lybctx)
416416
{
417417
uint8_t prefix_b, num_b, byte_len;
418+
uint16_t buf16;
418419
uint32_t buf;
419420

420421
/* --- no shrink mode --- */
@@ -426,8 +427,8 @@ lyb_write_count(uint32_t count, struct lylyb_print_ctx *lybctx)
426427

427428
/* always write the count on 2 bytes */
428429
byte_len = 2;
429-
buf = htole32(count);
430-
return lyb_write(&buf, byte_len * 8, lybctx);
430+
buf16 = htole16(count);
431+
return lyb_write(&buf16, byte_len * 8, lybctx);
431432
}
432433

433434
/* --- shrink mode ---
@@ -661,8 +662,8 @@ lyb_print_context_hash(struct lylyb_print_ctx *lybctx)
661662
if (lybctx->ctx) {
662663
hash = lyb_truncate_hash_nonzero(ly_ctx_get_modules_hash(lybctx->ctx), LYB_HEADER_CTX_HASH_BITS);
663664

664-
/* correct byte order */
665-
hash = htole32(hash);
665+
/* if LYB_HEADER_CTX_HASH_BITS > 9, then we would need to correct the byte order */
666+
assert(LYB_HEADER_CTX_HASH_BITS < 9);
666667
}
667668

668669
return lyb_write(&hash, LYB_HEADER_CTX_HASH_BITS, lybctx);

0 commit comments

Comments
 (0)