r1.66 (May 2014) introduced a two #if 0/#else/#endif chunks to avoid "over
authorkrw <krw@openbsd.org>
Mon, 18 Oct 2021 16:12:02 +0000 (16:12 +0000)
committerkrw <krw@openbsd.org>
Mon, 18 Oct 2021 16:12:02 +0000 (16:12 +0000)
optimistic alignment expectations" when extracting a uint32_t field from a
packed struct.

r1.70 (March 2015) removed one of the two #if 0 chunks, realizing there was no
real gain to be had even if various compilers were ever able to intuit the
expected alignment.

Belatedly nuke the other #if 0 chunk and always memcpy() the uint32_t values out
of the struct.

sbin/fdisk/part.c

index cd0ecaa..d65255b 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: part.c,v 1.108 2021/10/10 15:34:21 krw Exp $  */
+/*     $OpenBSD: part.c,v 1.109 2021/10/18 16:12:02 krw Exp $  */
 
 /*
  * Copyright (c) 1997 Tobias Weingartner
@@ -289,19 +289,12 @@ PRT_parse(const struct dos_partition *dp, const uint64_t lba_self,
        else
                off = lba_self;
 
-#if 0 /* XXX */
-       prt->prt_bs = letoh32(dp->dp_start) + off;
-       prt->prt_ns = letoh32(dp->dp_size);
-       if (prt->prt_id == DOSPTYP_EFI && partn == UINT32_MAX)
-               prt->prt_ns = DL_GETDSIZE(&dl) - prt->prt_bs;
-#else
        memcpy(&t, &dp->dp_start, sizeof(uint32_t));
        prt->prt_bs = letoh32(t) + off;
        memcpy(&t, &dp->dp_size, sizeof(uint32_t));
        prt->prt_ns = letoh32(t);
        if (prt->prt_id == DOSPTYP_EFI && prt->prt_ns == UINT32_MAX)
                prt->prt_ns = DL_GETDSIZE(&dl) - prt->prt_bs;
-#endif
 
        PRT_fix_CHS(prt);
 }