From: sf Date: Fri, 16 Jun 2023 08:42:08 +0000 (+0000) Subject: msdosfs: fixes for Undefined Behavior X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=962873417674167d31ba9ef08dd8e7bf20468941;p=openbsd msdosfs: fixes for Undefined Behavior From FreeBSD commits commit c0db7289c3de290d821311942d5533f2284af77f Author: pfg Date: Wed Aug 8 15:08:22 2018 +0000 commit 852150953b828e4e8c32789637061001158a8cf4 Author: kib Date: Fri Oct 11 18:37:02 2019 +0000 ok bluhm@ --- diff --git a/sys/msdosfs/msdosfs_fat.c b/sys/msdosfs/msdosfs_fat.c index d31abf7d11d..0b28222da0a 100644 --- a/sys/msdosfs/msdosfs_fat.c +++ b/sys/msdosfs/msdosfs_fat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: msdosfs_fat.c,v 1.35 2023/04/30 17:16:36 sf Exp $ */ +/* $OpenBSD: msdosfs_fat.c,v 1.36 2023/06/16 08:42:08 sf Exp $ */ /* $NetBSD: msdosfs_fat.c,v 1.26 1997/10/17 11:24:02 ws Exp $ */ /*- @@ -411,7 +411,7 @@ usemap_alloc(struct msdosfsmount *pmp, uint32_t cn) { KASSERT(cn <= pmp->pm_maxcluster); - pmp->pm_inusemap[cn / N_INUSEBITS] |= 1 << (cn % N_INUSEBITS); + pmp->pm_inusemap[cn / N_INUSEBITS] |= 1U << (cn % N_INUSEBITS); pmp->pm_freeclustercount--; } @@ -421,7 +421,7 @@ usemap_free(struct msdosfsmount *pmp, uint32_t cn) KASSERT(cn <= pmp->pm_maxcluster); pmp->pm_freeclustercount++; - pmp->pm_inusemap[cn / N_INUSEBITS] &= ~(1 << (cn % N_INUSEBITS)); + pmp->pm_inusemap[cn / N_INUSEBITS] &= ~(1U << (cn % N_INUSEBITS)); } int @@ -652,7 +652,7 @@ chainlength(struct msdosfsmount *pmp, uint32_t start, uint32_t count) idx = start / N_INUSEBITS; start %= N_INUSEBITS; map = pmp->pm_inusemap[idx]; - map &= ~((1 << start) - 1); + map &= ~((1U << start) - 1); if (map) { len = ffs(map) - 1 - start; len = MIN(len, count); @@ -759,7 +759,7 @@ clusteralloc(struct msdosfsmount *pmp, uint32_t start, uint32_t count, for (cn = newst; cn <= pmp->pm_maxcluster;) { idx = cn / N_INUSEBITS; map = pmp->pm_inusemap[idx]; - map |= (1 << (cn % N_INUSEBITS)) - 1; + map |= (1U << (cn % N_INUSEBITS)) - 1; if (map != (u_int)-1) { cn = idx * N_INUSEBITS + ffs(map^(u_int)-1) - 1; if ((l = chainlength(pmp, cn, count)) >= count) @@ -776,7 +776,7 @@ clusteralloc(struct msdosfsmount *pmp, uint32_t start, uint32_t count, for (cn = 0; cn < newst;) { idx = cn / N_INUSEBITS; map = pmp->pm_inusemap[idx]; - map |= (1 << (cn % N_INUSEBITS)) - 1; + map |= (1U << (cn % N_INUSEBITS)) - 1; if (map != (u_int)-1) { cn = idx * N_INUSEBITS + ffs(map^(u_int)-1) - 1; if ((l = chainlength(pmp, cn, count)) >= count)