bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* [PATCH] memset_explicit: port to older MS-Windows
@ 2022-12-18  7:47 Paul Eggert
  2022-12-26 16:50 ` Bruno Haible
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Eggert @ 2022-12-18  7:47 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Paul Eggert

* lib/memset_explicit.c (memset_explicit):
Remove special case for C==0 and MS-Windows.  The code isn’t
needed for correctness and it’s more trouble than it’s worth as it
prevents this module from being used with GNU Emacs, which wants
to port to MS-Windows versions so old that they lack
SecureZeroMemory.
---
 ChangeLog             | 10 ++++++++++
 lib/memset_explicit.c |  9 ---------
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 997faec27e..d7f0a62ed9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2022-12-17  Paul Eggert  <eggert@cs.ucla.edu>
+
+	memset_explicit: port to older MS-Windows
+	* lib/memset_explicit.c (memset_explicit):
+	Remove special case for C==0 and MS-Windows.  The code isn’t
+	needed for correctness and it’s more trouble than it’s worth as it
+	prevents this module from being used with GNU Emacs, which wants
+	to port to MS-Windows versions so old that they lack
+	SecureZeroMemory.
+
 2022-12-09  Bruno Haible  <bruno@clisp.org>
 
 	Update users.txt.
diff --git a/lib/memset_explicit.c b/lib/memset_explicit.c
index 867391b80f..eabeb3ec2b 100644
--- a/lib/memset_explicit.c
+++ b/lib/memset_explicit.c
@@ -23,20 +23,11 @@
 
 #include <string.h>
 
-#if defined _WIN32 && !defined __CYGWIN__
-# define WIN32_LEAN_AND_MEAN
-# include <windows.h>
-#endif
-
 /* Set S's bytes to C, where S has LEN bytes.  The compiler will not
    optimize effects away, even if S is dead after the call.  */
 void *
 memset_explicit (void *s, int c, size_t len)
 {
-#if defined _WIN32 && !defined __CYGWIN__
-  if (!c)
-    return SecureZeroMemory (s, len);
-#endif
 #if HAVE_EXPLICIT_MEMSET
   return explicit_memset (s, c, len);
 #elif HAVE_MEMSET_S
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] memset_explicit: port to older MS-Windows
  2022-12-18  7:47 [PATCH] memset_explicit: port to older MS-Windows Paul Eggert
@ 2022-12-26 16:50 ` Bruno Haible
  2022-12-26 16:58   ` Paul Eggert
  0 siblings, 1 reply; 3+ messages in thread
From: Bruno Haible @ 2022-12-26 16:50 UTC (permalink / raw)
  To: bug-gnulib, Paul Eggert

Paul Eggert wrote:
> * lib/memset_explicit.c (memset_explicit):
> Remove special case for C==0 and MS-Windows.  The code isn’t
> needed for correctness
> ...
>  /* Set S's bytes to C, where S has LEN bytes.  The compiler will not
>     optimize effects away, even if S is dead after the call.  */
>  void *
>  memset_explicit (void *s, int c, size_t len)
>  {
> -#if defined _WIN32 && !defined __CYGWIN__
> -  if (!c)
> -    return SecureZeroMemory (s, len);
> -#endif
>  #if HAVE_EXPLICIT_MEMSET
>    return explicit_memset (s, c, len);
>  #elif HAVE_MEMSET_S

For compilers other than GCC and clang, we are betting on a trick with
'volatile'. I'm not sure it won't break in the future. But at least for
now, with MSVC, the unit tests still pass.

Bruno





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] memset_explicit: port to older MS-Windows
  2022-12-26 16:50 ` Bruno Haible
@ 2022-12-26 16:58   ` Paul Eggert
  0 siblings, 0 replies; 3+ messages in thread
From: Paul Eggert @ 2022-12-26 16:58 UTC (permalink / raw)
  To: Bruno Haible, bug-gnulib

On 12/26/22 08:50, Bruno Haible wrote:
> For compilers other than GCC and clang, we are betting on a trick with
> 'volatile'. I'm not sure it won't break in the future. But at least for
> now, with MSVC, the unit tests still pass.

Thanks for doing the unit tests. Yes, the hope is that this good is good 
enough for today's compilers, and that tomorrow's compilers will 
implement C23 memset_explicit anyway so this code will be irrelevant.

Given the underlying hardware issues, memset_explicit is best-effort 
anyway. (Plus, you should see how Emacs misuses it! Oh my. I suggested 
an improvement for that but there were objections and I haven't had the 
time or patience to wade through it.)



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-26 16:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-18  7:47 [PATCH] memset_explicit: port to older MS-Windows Paul Eggert
2022-12-26 16:50 ` Bruno Haible
2022-12-26 16:58   ` Paul Eggert

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).