[PATCH v2] stubdom: Fix GCC 14 -Wmemset-elt-size compiler warnings in PolarSSL

Andrew Mbugua posted 1 patch 2 weeks ago
stubdom/v2-0001-PATCH-stubdom-Fix-GCC-14-Wmemset-elt-size-compile.patch | 13 +++++++++++++
1 file changed, 13 insertions(+)
create mode 100644 stubdom/v2-0001-PATCH-stubdom-Fix-GCC-14-Wmemset-elt-size-compile.patch
[PATCH v2] stubdom: Fix GCC 14 -Wmemset-elt-size compiler warnings in PolarSSL
Posted by Andrew Mbugua 2 weeks ago
A followup to the email thread with the previously suggested changes.

I have:
1. Added the patch reference to the Makefile
2. Removed the new subdirectory I created.
3. Formatted patch message to be <75 characters per line

When compiling Xen with GCC 14, I get a compiler warning originating from the /polarssl-x86_64/library about a memset element size mismatch:

ssl_tls.c: In function ‘ssl_session_reset’:
ssl_tls.c:1778:5: warning: ‘memset’ used with length equal to number of elements without multiplication by element size [-Wmemset-elt-size]
1778 |     memset( ssl->ctx_enc, 0, 128 );
|     ^~~~~~
ssl_tls.c:1779:5: warning: ‘memset’ used with length equal to number of elements without multiplication by element size [-Wmemset-elt-size]
1779 |     memset( ssl->ctx_dec, 0, 128 );
|     ^~~~~~

This patch introduces a build-time patch to PolarSSL that replaces the hardcoded
128 byte length with sizeof() allowing clean compilation without warnings.

Signed-off-by: Andrew Mbugua <andrewprecious388@gmail.com>
---
 stubdom/v2-0001-PATCH-stubdom-Fix-GCC-14-Wmemset-elt-size-compile.patch | 13 +++++++++++++
 1 file changed, 13 insertions(+)
 create mode 100644 stubdom/v2-0001-PATCH-stubdom-Fix-GCC-14-Wmemset-elt-size-compile.patch

diff --git a/stubdom/v2-0001-PATCH-stubdom-Fix-GCC-14-Wmemset-elt-size-compile.patch b/stubdom/v2-0001-PATCH-stubdom-Fix-GCC-14-Wmemset-elt-size-compile.patch
new file mode 100644
index 0000000000..3528f2817a
--- /dev/null
+++ b/stubdom/v2-0001-PATCH-stubdom-Fix-GCC-14-Wmemset-elt-size-compile.patch
@@ -0,0 +1,13 @@
+--- a/library/ssl_tls.c
++++ b/library/ssl_tls.c
+@@ -1775,8 +1775,8 @@
+ 	memset( ssl->iv_dec, 0, 16 );
+ 	memset( ssl->mac_enc, 0, 32 );
+ 	memset( ssl->mac_dec, 0, 32 );
+-    memset( ssl->ctx_enc, 0, 128 );
+-    memset( ssl->ctx_dec, 0, 128 );
++    memset( ssl->ctx_enc, 0, sizeof( ssl->ctx_enc ) );
++    memset( ssl->ctx_dec, 0, sizeof( ssl->ctx_dec ) );
+ 
+ 	md5_starts( &ssl->fin_md5  );
+ 	sha1_starts( &ssl->fin_sha1 );
-- 
2.47.3


Re: [PATCH v2] stubdom: Fix GCC 14 -Wmemset-elt-size compiler warnings in PolarSSL
Posted by Jan Beulich 2 weeks ago
On 10.09.2026 11:14, Andrew Mbugua wrote:
> A followup to the email thread with the previously suggested changes.
> 
> I have:
> 1. Added the patch reference to the Makefile
> 2. Removed the new subdirectory I created.
> 3. Formatted patch message to be <75 characters per line

For one, none of the above should be part of the commit message. Such wants
to move past the first --- separator.

Then: While I see you did 2, I don't think you really did 1 and 3. As to 3,
...

> When compiling Xen with GCC 14, I get a compiler warning originating from the /polarssl-x86_64/library about a memset element size mismatch:

... this is still in need of wrapping, whereas ...

> ssl_tls.c: In function ‘ssl_session_reset’:
> ssl_tls.c:1778:5: warning: ‘memset’ used with length equal to number of elements without multiplication by element size [-Wmemset-elt-size]
> 1778 |     memset( ssl->ctx_enc, 0, 128 );
> |     ^~~~~~
> ssl_tls.c:1779:5: warning: ‘memset’ used with length equal to number of elements without multiplication by element size [-Wmemset-elt-size]
> 1779 |     memset( ssl->ctx_dec, 0, 128 );
> |     ^~~~~~

... compiler output may be kept as is (imo).

> This patch introduces a build-time patch to PolarSSL that replaces the hardcoded
> 128 byte length with sizeof() allowing clean compilation without warnings.

This again looks to need suitable wrapping. Furthermore, isn't there a little
more to be said here? After all sizeof(ssl->ctx_enc) != 128, afaict.

> Signed-off-by: Andrew Mbugua <andrewprecious388@gmail.com>
> ---
>  stubdom/v2-0001-PATCH-stubdom-Fix-GCC-14-Wmemset-elt-size-compile.patch | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>  create mode 100644 stubdom/v2-0001-PATCH-stubdom-Fix-GCC-14-Wmemset-elt-size-compile.patch

In line with other patches we have there, maybe better name this e.g.
polarssl-gcc14.patch?

> --- /dev/null
> +++ b/stubdom/v2-0001-PATCH-stubdom-Fix-GCC-14-Wmemset-elt-size-compile.patch
> @@ -0,0 +1,13 @@
> +--- a/library/ssl_tls.c
> ++++ b/library/ssl_tls.c
> +@@ -1775,8 +1775,8 @@
> + 	memset( ssl->iv_dec, 0, 16 );
> + 	memset( ssl->mac_enc, 0, 32 );
> + 	memset( ssl->mac_dec, 0, 32 );
> +-    memset( ssl->ctx_enc, 0, 128 );
> +-    memset( ssl->ctx_dec, 0, 128 );
> ++    memset( ssl->ctx_enc, 0, sizeof( ssl->ctx_enc ) );
> ++    memset( ssl->ctx_dec, 0, sizeof( ssl->ctx_dec ) );
> + 
> + 	md5_starts( &ssl->fin_md5  );
> + 	sha1_starts( &ssl->fin_sha1 );

I haven't tried it out, but I can't help the impression that this patch is
not going to apply. The source code I'm looking at has no use of hard tabs,
yet there are hard tabs on the patch context lines above (yet interestingly
not on the lines actually altered).

Jan