From cd1536fbca174a8f9715ff773c2e45370b7cda08 Mon Sep 17 00:00:00 2001 From: John Marino Date: Tue, 10 Feb 2015 10:32:02 +0100 Subject: [PATCH] libstand: Fix loop with undefined optimized behavior With gcc 4.8+, libstand fails to build with "interation 8u involved in undefined behavior [-Werror=aggressive-loop-optimizations]". I figured out that problem was the code was intentionally defining two fields in the same structure with a single loop. The "name" field is an array of size 8 while the "ext" field is an array of size 3. The loop in question iterated 11 times to initialize both, relying on contiguous memory to work. Apparently this leads to undefined behavior, so I altered the line to explicitly define the correct element on the correct field. --- lib/libstand/dosfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/libstand/dosfs.c b/lib/libstand/dosfs.c index 0c966c4ebf..aad987c36c 100644 --- a/lib/libstand/dosfs.c +++ b/lib/libstand/dosfs.c @@ -495,7 +495,9 @@ lookup(DOS_FS *fs, u_int clus, const char *name, DOS_DE **dep) if ((ok = xdn == 1)) { for (x = 0, i = 0; i < 11; i++) x = ((((x & 1) << 7) | (x >> 1)) + - dir[ent].de.name[i]) & 0xff; + ((i < 8) ? dir[ent].de.name[i] : + dir[ent].de.ext[i - 8]) + ) & 0xff; ok = chk == x && !strcasecmp(name, (const char *)lfn); } -- 2.41.0