Skip to content

Commit 8a43b23

Browse files
Roytakmichalvasko
authored andcommitted
lyb BUGFIX count byte order
1 parent c1a3281 commit 8a43b23

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

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/parser_lyb.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,14 @@ static void
155155
lyb_read_count(uint32_t *count, struct lylyb_parse_ctx *lybctx)
156156
{
157157
uint8_t prefix = 0, pref_len = 0, byte_len = 0;
158+
uint16_t count16 = 0;
158159

159160
/* --- no shrink mode --- */
160161
if (!lybctx->shrink) {
161162
/* always use 2 bytes for the count */
162163
byte_len = 2;
163-
lyb_read(count, byte_len * 8, lybctx);
164-
*count = le32toh(*count);
164+
lyb_read(&count16, byte_len * 8, lybctx);
165+
*count = le16toh(count16);
165166
return;
166167
}
167168

src/printer_lyb.c

Lines changed: 3 additions & 2 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 ---

0 commit comments

Comments
 (0)