summaryrefslogtreecommitdiff
path: root/src/libnm-crypto
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-12-01 14:07:22 +0100
committerThomas Haller <thaller@redhat.com>2022-12-09 09:15:56 +0100
commit36f8de25c487fe1570a19fe917c85ec065b0339e (patch)
tree742592af2417c05ed8454f18a876a7b466443c6f /src/libnm-crypto
parent4ecd25a1391b18bd2380a9209791cb19722f7833 (diff)
downloadNetworkManager-36f8de25c487fe1570a19fe917c85ec065b0339e.tar.gz
all: fix various "-Wcast-align=strict" warnings
The warning "-Wcast-align=strict" seems useful and will be enabled next. Fix places that currently cause the warning by using the new macro NM_CAST_ALIGN(). This macro also nm_assert()s that the alignment is correct.
Diffstat (limited to 'src/libnm-crypto')
-rw-r--r--src/libnm-crypto/nm-crypto-nss.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/libnm-crypto/nm-crypto-nss.c b/src/libnm-crypto/nm-crypto-nss.c
index b31ca55ee0..6ac52b2c24 100644
--- a/src/libnm-crypto/nm-crypto-nss.c
+++ b/src/libnm-crypto/nm-crypto-nss.c
@@ -450,10 +450,17 @@ _nm_crypto_verify_pkcs12(const guint8 *data, gsize data_len, const char *passwor
#if __BYTE_ORDER == __LITTLE_ENDIAN
{
- guint16 *p, *p_end;
+ const guint16 *p_end;
+ guint16 *p;
- p_end = (guint16 *) &(((guint8 *) pw.data)[ucs2_password.len]);
- for (p = (guint16 *) pw.data; p < p_end; p++)
+ /* we cast here to guint16 pointers (which would trigger a "-Wcast-align").
+ * But this is safe, because ucs2_password.len is a multiple of 2 and
+ * because pw.data was an allocated buffer (that is presumably aligned
+ * correctly). */
+ nm_assert(ucs2_password.len % 2 == 0);
+
+ p_end = NM_CAST_ALIGN(guint16, &(((guint8 *) pw.data)[ucs2_password.len]));
+ for (p = NM_CAST_ALIGN(guint16, pw.data); p < p_end; p++)
*p = GUINT16_SWAP_LE_BE(*p);
}
#endif