From 4967240899b6f36e3e5dfc68f1b8963824562fe9 Mon Sep 17 00:00:00 2001 From: Guido Falsi Date: Wed, 28 Jun 2023 15:42:37 +0200 Subject: [PATCH] Add VFS_SEEK_INVALID enum value. New versions of the clang compiler have strict checks for enum values. The value "-1" is returned as a last resort from to_vfs_seek_type() as a VFSSeekType. Replace usage of `-1` with the new enum name. (jlindgren: added comment, updated formatting) --- src/libaudcore/vfs.h | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/libaudcore/vfs.h b/src/libaudcore/vfs.h index 33c5a65c97..e2fe7efb73 100644 --- src/libaudcore/vfs.h +++ src/libaudcore/vfs.h @@ -53,7 +53,11 @@ enum VFSSeekType { VFS_SEEK_SET = 0, VFS_SEEK_CUR = 1, - VFS_SEEK_END = 2 + VFS_SEEK_END = 2, + /* This value exists only to translate out-of-range values from external + * libraries/APIs (e.g. POSIX). Avoid using it. For validity checks, use an + * else/default case rather than testing equality with VFS_SEEK_INVALID. */ + VFS_SEEK_INVALID = -1 }; #ifdef WANT_VFS_STDIO_COMPAT @@ -62,20 +66,18 @@ enum VFSSeekType constexpr int from_vfs_seek_type(VFSSeekType whence) { - return (whence == VFS_SEEK_SET) - ? SEEK_SET - : (whence == VFS_SEEK_CUR) - ? SEEK_CUR - : (whence == VFS_SEEK_END) ? SEEK_END : -1; + return (whence == VFS_SEEK_SET) ? SEEK_SET + : (whence == VFS_SEEK_CUR) ? SEEK_CUR + : (whence == VFS_SEEK_END) ? SEEK_END + : -1; } constexpr VFSSeekType to_vfs_seek_type(int whence) { - return (whence == SEEK_SET) - ? VFS_SEEK_SET - : (whence == SEEK_CUR) - ? VFS_SEEK_CUR - : (whence == SEEK_END) ? VFS_SEEK_END : (VFSSeekType)-1; + return (whence == SEEK_SET) ? VFS_SEEK_SET + : (whence == SEEK_CUR) ? VFS_SEEK_CUR + : (whence == SEEK_END) ? VFS_SEEK_END + : VFS_SEEK_INVALID; } #endif // WANT_VFS_STDIO_COMPAT