From e5798096a2bc91139e5cce8059d9ee9a8a2be8f8 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Fri, 10 Feb 2017 14:35:05 -0700 Subject: [PATCH] gpt_spec: add casts to avoid undefined shifts Make sure the SPDK_GPT_GUID() macro parameters are treated as unsigned integers of the right sizes to avoid shifting into the sign bit or beyond the size of an int. Change-Id: I1638022692b09b179ffc770f845b053a96a8260f Signed-off-by: Daniel Verkamp --- include/spdk/gpt_spec.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/include/spdk/gpt_spec.h b/include/spdk/gpt_spec.h index 4c5db9c71..32906cbfe 100644 --- a/include/spdk/gpt_spec.h +++ b/include/spdk/gpt_spec.h @@ -92,12 +92,13 @@ SPDK_STATIC_ASSERT(sizeof(struct spdk_gpt_guid) == 16, "size incorrect"); #define SPDK_GPT_GUID(a, b, c, d, e) \ (struct spdk_gpt_guid){{ \ - (uint8_t)(a), (uint8_t)((a) >> 8), (uint8_t)((a) >> 16), (uint8_t)((a >> 24)), \ - (uint8_t)(b), (uint8_t)((b) >> 8), \ - (uint8_t)(c), (uint8_t)((c) >> 8), \ - (uint8_t)((d) >> 8), (uint8_t)(d), \ - (uint8_t)((e) >> 40), (uint8_t)((e) >> 32), (uint8_t)((e) >> 24), \ - (uint8_t)((e) >> 16), (uint8_t)((e) >> 8), (uint8_t)(e) \ + (uint8_t)(a), (uint8_t)(((uint32_t)a) >> 8), \ + (uint8_t)(((uint32_t)a) >> 16), (uint8_t)(((uint32_t)a >> 24)), \ + (uint8_t)(b), (uint8_t)(((uint16_t)b) >> 8), \ + (uint8_t)(c), (uint8_t)(((uint16_t)c) >> 8), \ + (uint8_t)(((uint16_t)d) >> 8), (uint8_t)(d), \ + (uint8_t)(((uint64_t)e) >> 40), (uint8_t)(((uint64_t)e) >> 32), (uint8_t)(((uint64_t)e) >> 24), \ + (uint8_t)(((uint64_t)e) >> 16), (uint8_t)(((uint64_t)e) >> 8), (uint8_t)(e) \ }} #define SPDK_GPT_PART_TYPE_UNUSED SPDK_GPT_GUID(0x00000000, 0x0000, 0x0000, 0x0000, 0x000000000000)