From 2fb79510f0452e91b72cefa704268a569b9885e9 Mon Sep 17 00:00:00 2001 From: John Paul Adrian Glaubitz Date: Fri, 18 May 2018 23:44:40 +0200 Subject: [PATCH] Reset struct alignment back to standard after each #pragma pack (n) When using #pragma pack (n) to change the alignment for a struct to n bytes, it is necessary to reset the alignment to the standard value as otherwise the changed alignment is used throughout the whole program code which causes other structs to become unaligned. --- basicmbr.h | 1 + bsd.h | 1 + gpt.h | 1 + mbrpart.h | 1 + 4 files changed, 4 insertions(+) diff --git a/basicmbr.h b/basicmbr.h index b809856..21f962e 100644 --- a/basicmbr.h +++ b/basicmbr.h @@ -34,6 +34,7 @@ struct TempMBR { struct MBRRecord partitions[4]; uint16_t MBRSignature; }; // struct TempMBR +#pragma pack () // Possible states of the MBR enum MBRValidity {invalid, gpt, hybrid, mbr}; diff --git a/bsd.h b/bsd.h index ffbe5cc..cbd3588 100644 --- a/bsd.h +++ b/bsd.h @@ -89,5 +89,6 @@ class BSDData { int GetNumParts(void); GPTPart AsGPT(int i); // Return BSD part. as GPT part. }; // struct MBRData +#pragma pack () #endif diff --git a/gpt.h b/gpt.h index 2d7a1ce..f4bf470 100644 --- a/gpt.h +++ b/gpt.h @@ -57,6 +57,7 @@ struct GPTHeader { uint32_t partitionEntriesCRC; unsigned char reserved2[GPT_RESERVED]; }; // struct GPTHeader +#pragma pack () // Data in GPT format class GPTData { diff --git a/mbrpart.h b/mbrpart.h index f5892e7..0de365f 100644 --- a/mbrpart.h +++ b/mbrpart.h @@ -50,6 +50,7 @@ struct MBRRecord { uint32_t firstLBA; // see above uint32_t lengthLBA; }; // struct MBRRecord +#pragma pack () class MBRPart { protected: