public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin/main] Cygwin: introduce constexpr errmap_size and errmap[] consistency checks
@ 2024-02-26 15:47 Corinna Vinschen
0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2024-02-26 15:47 UTC (permalink / raw)
To: cygwin-cvs
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=b55eed943b85a72b76a0a2f5738dfb9aad1982ea
commit b55eed943b85a72b76a0a2f5738dfb9aad1982ea
Author: Christian Franke <christian.franke@t-online.de>
AuthorDate: Mon Feb 26 13:37:33 2024 +0100
Commit: Corinna Vinschen <corinna@vinschen.de>
CommitDate: Mon Feb 26 15:56:10 2024 +0100
Cygwin: introduce constexpr errmap_size and errmap[] consistency checks
Use constexpr instead of const for errmap[] to allow static_assert
checks on its values.
Signed-off-by: Christian Franke <christian.franke@t-online.de>
Diff:
---
winsup/cygwin/errno.cc | 2 +-
winsup/cygwin/local_includes/errmap.h | 11 ++++++++++-
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/winsup/cygwin/errno.cc b/winsup/cygwin/errno.cc
index 1c85e9a04367..7d58e62ec142 100644
--- a/winsup/cygwin/errno.cc
+++ b/winsup/cygwin/errno.cc
@@ -185,7 +185,7 @@ geterrno_from_win_error (DWORD code, int deferrno)
{
/* A 0-value in errmap means, we don't handle this windows error
explicitely. Fall back to deferrno in these cases. */
- if (code < sizeof errmap / sizeof errmap[0] && errmap[code])
+ if (code < errmap_size && errmap[code])
{
syscall_printf ("windows error %u == errno %d", code, errmap[code]);
return errmap[code];
diff --git a/winsup/cygwin/local_includes/errmap.h b/winsup/cygwin/local_includes/errmap.h
index a0b3ff400644..737c01c8b869 100644
--- a/winsup/cygwin/local_includes/errmap.h
+++ b/winsup/cygwin/local_includes/errmap.h
@@ -3,7 +3,7 @@
to this new array manually on demand. */
/* FIXME: Some of these choices are arbitrary! */
-static const int errmap[] =
+constexpr int errmap[] =
{
0, /* ERROR_SUCCESS */
EBADRQC, /* ERROR_INVALID_FUNCTION */
@@ -9006,3 +9006,12 @@ static const int errmap[] =
0, /* 8998 */
0, /* 8999 */
};
+
+constexpr unsigned errmap_size = sizeof (errmap) / sizeof (errmap[0]);
+
+/* Some consistency checks. */
+static_assert (errmap_size == 8999 + 1);
+static_assert (EINTR == errmap[/* 104 */ ERROR_INVALID_AT_INTERRUPT_TIME]);
+static_assert (ENXIO == errmap[/* 1006 */ ERROR_FILE_INVALID]);
+static_assert (EAGAIN == errmap[/* 2404 */ ERROR_DEVICE_IN_USE]);
+static_assert (EIO == errmap[/* 8341 */ ERROR_DS_GENERIC_ERROR]);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-02-26 15:47 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-26 15:47 [newlib-cygwin/main] Cygwin: introduce constexpr errmap_size and errmap[] consistency checks Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).