From 5f1e07afd1ae33dbaf040340e2c3c34b679a8824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= Date: Wed, 5 Feb 2020 10:05:33 +0100 Subject: [PATCH] rr_decode: Refactor name compression Add an `offset` variable to store the offset instead of `len`, and fix an implicit type conversion warning --- src/rr.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/rr.c b/src/rr.c index f6676a2..fb6fffa 100644 --- a/src/rr.c +++ b/src/rr.c @@ -322,14 +322,15 @@ rr_decode(const uint8_t *ptr, size_t *n, const uint8_t *root, char **ss, uint8_t const uint8_t *p; char *buf; size_t m; + uint16_t offset; - if (*n < sizeof(len)) + if (*n < sizeof(offset)) goto err; - len &= ~0xC0; - len = (len << 8) | *ptr; + offset = ~0xC0 & len; + offset = (uint16_t)(offset << 8u) | *ptr; advance(1); - p = root + len; + p = root + offset; m = ptr - p + *n; /* Avoid recursing on the same element */ if (p == orig_ptr)