Skip to contentSkip to conversation

boilerplate: Replace strncpy with snprintf in ancillaries.h

PATCH In review Haiyang He 3 participants 7 messages Jul 5, 2025 – Jul 7, 2025

lore
Share & tools
lore

Haiyang He

author
#0 lore raw

PATCH 1/1 boilerplate: Replace strncpy with snprintf in ancillaries.h

When configure with --enable-registry, it fails to build regd/fs-common.c caused by strncpy. Using snprintf instead of strncpy ensures that the destination buffer is always null-terminated, preventing potential buffer overflow issues and compilation error.

$ ./configure \
--host=aarch64-linux-gnu \
--build=aarch64-linux-gnu \
--enable-smp \
--enable-pshared \
--enable-registry \
--with-core=cobalt \
CC=aarch64-linux-gnu-gcc \
LD=aarch64-linux-gnu-ld \
CFLAGS="-march=armv8-a" \
LDFLAGS="-march=armv8-a"
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.5 LTS"
$ aarch64-linux-gnu-gcc --version
aarch64-linux-gnu-gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

The output of build error:

make[3]: Entering directory '/root/xenomai-next/xenomai-next-build/lib/copperplate/regd'

  CC       regd.o
  CC       fs-common.o
  CC       fs-cobalt.o

In file included from /usr/include/string.h:535,
from /root/xenomai-next/xenomai-next/include/copperplate/heapobj.h:24,
from /root/xenomai-next/xenomai-next/lib/copperplate/regd/fs-common.c:27:
In function 'strncpy',
inlined from 'open_heaps' at /root/xenomai-next/xenomai-next/lib/copperplate/regd/fs-common.c:248:3:
/usr/include/aarch64-linux-gnu/bits/string_fortified.h:95:10: error: '__builtin_strncpy' output may be truncated copying 31 bytes from a string of length 31 [-Werror=stringop-truncation]

   95 |   return __builtin___strncpy_chk (__dest, __src, __len,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   96 |                                   __glibc_objsize (__dest));
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

---
 include/boilerplate/ancillaries.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/boilerplate/ancillaries.h +1 -2
index c8c209deb..8de353ce8 100644
@@ -36,8 +36,7 @@ void __namecpy_requires_character_array_as_destination(void);
 	({								\
 		if (!__builtin_types_compatible_p(typeof(__dst), char[])) \
 			__namecpy_requires_character_array_as_destination();	\
-		strncpy((__dst), __src, sizeof(__dst));			\
-		__dst[sizeof(__dst) - 1] = '\0';			\
+		snprintf((__dst), sizeof(__dst), "%s", (__src));	\
 		__dst;							\
 	 })
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 4 lines · Haiyang He

When configure with --enable-registry, it fails to build regd/fs-common.c caused by strncpy. Using snprintf instead of strncpy ensures that the destination buffer is always null-terminated, preventing potential buffer overflow issues and compilation error.

Thanks for reporting the compilation issue. But this is not an overflow issue, just a confusion of the gcc in Ubuntu 22.04. We are properly terminating in all cases.

Quoted 50 lines
$ ./configure \
--host=aarch64-linux-gnu \
--build=aarch64-linux-gnu \
--enable-smp \
--enable-pshared \
--enable-registry \
--with-core=cobalt \
CC=aarch64-linux-gnu-gcc \
LD=aarch64-linux-gnu-ld \
CFLAGS="-march=armv8-a" \
LDFLAGS="-march=armv8-a"
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.5 LTS"
$ aarch64-linux-gnu-gcc --version
aarch64-linux-gnu-gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

The output of build error:

make[3]: Entering directory '/root/xenomai-next/xenomai-next-build/lib/copperplate/regd'

  CC       regd.o
  CC       fs-common.o
  CC       fs-cobalt.o

In file included from /usr/include/string.h:535,
from /root/xenomai-next/xenomai-next/include/copperplate/heapobj.h:24,
from /root/xenomai-next/xenomai-next/lib/copperplate/regd/fs-common.c:27:
In function 'strncpy',
inlined from 'open_heaps' at /root/xenomai-next/xenomai-next/lib/copperplate/regd/fs-common.c:248:3:
/usr/include/aarch64-linux-gnu/bits/string_fortified.h:95:10: error: '__builtin_strncpy' output may be truncated copying 31 bytes from a string of length 31 [-Werror=stringop-truncation]

   95 |   return __builtin___strncpy_chk (__dest, __src, __len,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   96 |                                   __glibc_objsize (__dest));
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

---
 include/boilerplate/ancillaries.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/boilerplate/ancillaries.h +0 -0
index c8c209deb..8de353ce8 100644

include/boilerplate/ancillaries.h void __namecpy_requires_character_array_as_destination(void); · line 39

Quoted 4 lines
include/boilerplate/ancillaries.h +0 -1
@@ -36,8 +36,7 @@ void __namecpy_requires_character_array_as_destination(void);
 	({								\
 		if (!__builtin_types_compatible_p(typeof(__dst), char[])) \
 			__namecpy_requires_character_array_as_destination();	\
-		strncpy((__dst), __src, sizeof(__dst));			\

What if we do

strncpy((__dst), __src, sizeof(__dst) - 1)

? Is the compiler silent in that case?

BTW, we have way more places where we are using this pattern, also in userspace (lib/boilerplate/ancillaries.c, lib/cobalt/printf.c).

include/boilerplate/ancillaries.h void __namecpy_requires_character_array_as_destination(void); · line 42

Quoted 5 lines
include/boilerplate/ancillaries.h +1 -1
-		__dst[sizeof(__dst) - 1] = '\0';			\
+		snprintf((__dst), sizeof(__dst), "%s", (__src));	\
 		__dst;							\
 	 })
 

Jan

Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center
author
#2 lore raw
Quoted 67 lines · Jan Kiszka
Quoted 4 lines · Haiyang He

When configure with --enable-registry, it fails to build regd/fs-common.c caused by strncpy. Using snprintf instead of strncpy ensures that the destination buffer is always null-terminated, preventing potential buffer overflow issues and compilation error.

Thanks for reporting the compilation issue. But this is not an overflow issue, just a confusion of the gcc in Ubuntu 22.04. We are properly terminating in all cases.

Quoted 50 lines
$ ./configure \
--host=aarch64-linux-gnu \
--build=aarch64-linux-gnu \
--enable-smp \
--enable-pshared \
--enable-registry \
--with-core=cobalt \
CC=aarch64-linux-gnu-gcc \
LD=aarch64-linux-gnu-ld \
CFLAGS="-march=armv8-a" \
LDFLAGS="-march=armv8-a"
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.5 LTS"
$ aarch64-linux-gnu-gcc --version
aarch64-linux-gnu-gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

The output of build error:

make[3]: Entering directory '/root/xenomai-next/xenomai-next-build/lib/copperplate/regd'

  CC       regd.o
  CC       fs-common.o
  CC       fs-cobalt.o

In file included from /usr/include/string.h:535,
from /root/xenomai-next/xenomai-next/include/copperplate/heapobj.h:24,
from /root/xenomai-next/xenomai-next/lib/copperplate/regd/fs-common.c:27:
In function 'strncpy',
inlined from 'open_heaps' at /root/xenomai-next/xenomai-next/lib/copperplate/regd/fs-common.c:248:3:
/usr/include/aarch64-linux-gnu/bits/string_fortified.h:95:10: error: '__builtin_strncpy' output may be truncated copying 31 bytes from a string of length 31 [-Werror=stringop-truncation]

   95 |   return __builtin___strncpy_chk (__dest, __src, __len,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   96 |                                   __glibc_objsize (__dest));
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

---
 include/boilerplate/ancillaries.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/boilerplate/ancillaries.h +0 -0
index c8c209deb..8de353ce8 100644

include/boilerplate/ancillaries.h void __namecpy_requires_character_array_as_destination(void); · line 39

Quoted 4 lines
include/boilerplate/ancillaries.h +0 -1
@@ -36,8 +36,7 @@ void __namecpy_requires_character_array_as_destination(void);
 	({								\
 		if (!__builtin_types_compatible_p(typeof(__dst), char[])) \
 			__namecpy_requires_character_array_as_destination();	\
-		strncpy((__dst), __src, sizeof(__dst));			\

What if we do

Quoted 7 lines

strncpy((__dst), __src, sizeof(__dst) - 1)

? Is the compiler silent in that case?

BTW, we have way more places where we are using this pattern, also in userspace (lib/boilerplate/ancillaries.c, lib/cobalt/printf.c).

I actually tried this method when I encountered this issue. But it still reported the same error message.

Quoted 11 lines

include/boilerplate/ancillaries.h void __namecpy_requires_character_array_as_destination(void); · line 42

Quoted 5 lines
include/boilerplate/ancillaries.h +1 -1
-		__dst[sizeof(__dst) - 1] = '\0';			\
+		snprintf((__dst), sizeof(__dst), "%s", (__src));	\
 		__dst;							\
 	 })
 

Jan

Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center
#3 lore raw
Quoted 70 lines · Haiyang He
Quoted 69 lines · Jan Kiszka
Quoted 4 lines · Haiyang He

When configure with --enable-registry, it fails to build regd/fs-common.c caused by strncpy. Using snprintf instead of strncpy ensures that the destination buffer is always null-terminated, preventing potential buffer overflow issues and compilation error.

Thanks for reporting the compilation issue. But this is not an overflow issue, just a confusion of the gcc in Ubuntu 22.04. We are properly terminating in all cases.

Quoted 50 lines
$ ./configure \
--host=aarch64-linux-gnu \
--build=aarch64-linux-gnu \
--enable-smp \
--enable-pshared \
--enable-registry \
--with-core=cobalt \
CC=aarch64-linux-gnu-gcc \
LD=aarch64-linux-gnu-ld \
CFLAGS="-march=armv8-a" \
LDFLAGS="-march=armv8-a"
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.5 LTS"
$ aarch64-linux-gnu-gcc --version
aarch64-linux-gnu-gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

The output of build error:

make[3]: Entering directory '/root/xenomai-next/xenomai-next-build/lib/copperplate/regd'

  CC       regd.o
  CC       fs-common.o
  CC       fs-cobalt.o

In file included from /usr/include/string.h:535,
from /root/xenomai-next/xenomai-next/include/copperplate/heapobj.h:24,
from /root/xenomai-next/xenomai-next/lib/copperplate/regd/fs-common.c:27:
In function 'strncpy',
inlined from 'open_heaps' at /root/xenomai-next/xenomai-next/lib/copperplate/regd/fs-common.c:248:3:
/usr/include/aarch64-linux-gnu/bits/string_fortified.h:95:10: error: '__builtin_strncpy' output may be truncated copying 31 bytes from a string of length 31 [-Werror=stringop-truncation]

   95 |   return __builtin___strncpy_chk (__dest, __src, __len,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   96 |                                   __glibc_objsize (__dest));
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

---
 include/boilerplate/ancillaries.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/boilerplate/ancillaries.h +0 -0
index c8c209deb..8de353ce8 100644

include/boilerplate/ancillaries.h void __namecpy_requires_character_array_as_destination(void); · line 39

Quoted 4 lines
include/boilerplate/ancillaries.h +0 -1
@@ -36,8 +36,7 @@ void __namecpy_requires_character_array_as_destination(void);
 	({								\
 		if (!__builtin_types_compatible_p(typeof(__dst), char[])) \
 			__namecpy_requires_character_array_as_destination();	\
-		strncpy((__dst), __src, sizeof(__dst));			\

What if we do

strncpy((__dst), __src, sizeof(__dst) - 1)

Quoted 7 lines
Quoted 5 lines

? Is the compiler silent in that case?

BTW, we have way more places where we are using this pattern, also in userspace (lib/boilerplate/ancillaries.c, lib/cobalt/printf.c).

I actually tried this method when I encountered this issue. But it still reported the same error message.

But then why here, why not in the other cases?

Jan

Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center
author
#4 lore raw
Quoted 76 lines · Jan Kiszka
Quoted 75 lines · Haiyang He
Quoted 74 lines · Jan Kiszka
Quoted 4 lines · Haiyang He

When configure with --enable-registry, it fails to build regd/fs-common.c caused by strncpy. Using snprintf instead of strncpy ensures that the destination buffer is always null-terminated, preventing potential buffer overflow issues and compilation error.

Thanks for reporting the compilation issue. But this is not an overflow issue, just a confusion of the gcc in Ubuntu 22.04. We are properly terminating in all cases.

Quoted 50 lines
$ ./configure \
--host=aarch64-linux-gnu \
--build=aarch64-linux-gnu \
--enable-smp \
--enable-pshared \
--enable-registry \
--with-core=cobalt \
CC=aarch64-linux-gnu-gcc \
LD=aarch64-linux-gnu-ld \
CFLAGS="-march=armv8-a" \
LDFLAGS="-march=armv8-a"
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.5 LTS"
$ aarch64-linux-gnu-gcc --version
aarch64-linux-gnu-gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

The output of build error:

make[3]: Entering directory '/root/xenomai-next/xenomai-next-build/lib/copperplate/regd'

  CC       regd.o
  CC       fs-common.o
  CC       fs-cobalt.o

In file included from /usr/include/string.h:535,
from /root/xenomai-next/xenomai-next/include/copperplate/heapobj.h:24,
from /root/xenomai-next/xenomai-next/lib/copperplate/regd/fs-common.c:27:
In function 'strncpy',
inlined from 'open_heaps' at /root/xenomai-next/xenomai-next/lib/copperplate/regd/fs-common.c:248:3:
/usr/include/aarch64-linux-gnu/bits/string_fortified.h:95:10: error: '__builtin_strncpy' output may be truncated copying 31 bytes from a string of length 31 [-Werror=stringop-truncation]

   95 |   return __builtin___strncpy_chk (__dest, __src, __len,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   96 |                                   __glibc_objsize (__dest));
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

---
 include/boilerplate/ancillaries.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/boilerplate/ancillaries.h +0 -0
index c8c209deb..8de353ce8 100644

include/boilerplate/ancillaries.h void __namecpy_requires_character_array_as_destination(void); · line 39

Quoted 4 lines
include/boilerplate/ancillaries.h +0 -1
@@ -36,8 +36,7 @@ void __namecpy_requires_character_array_as_destination(void);
 	({								\
 		if (!__builtin_types_compatible_p(typeof(__dst), char[])) \
 			__namecpy_requires_character_array_as_destination();	\
-		strncpy((__dst), __src, sizeof(__dst));			\

What if we do

strncpy((__dst), __src, sizeof(__dst) - 1)

? Is the compiler silent in that case?

BTW, we have way more places where we are using this pattern, also in userspace (lib/boilerplate/ancillaries.c, lib/cobalt/printf.c).

Quoted 10 lines
Quoted 2 lines

I actually tried this method when I encountered this issue. But it still reported the same error message.

But then why here, why not in the other cases?

Jan

Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center

Not sure why here.

I google it and find there were similar topics such as:

https://stackoverflow.com/questions/50198319/gcc-8-wstringop-truncation-what-is-the-good-practice

Haiyang.

#5 lore raw
In reply to Haiyang He
Quoted 4 lines · Haiyang He

When configure with --enable-registry, it fails to build regd/fs-common.c caused by strncpy. Using snprintf instead of strncpy ensures that the destination buffer is always null-terminated, preventing potential buffer overflow issues and compilation error.

Hm... I have --registry enabled most of the time, so I'm wondering why I did not face the same problem yet. Some questions below:

Quoted 4 lines
$ ./configure \
--host=aarch64-linux-gnu \
--build=aarch64-linux-gnu \

So you are building on a native aarch64 machine? That might make a difference. Does something change if you just remove the two lines above? The compiler should be selected / detected automatically.

Quoted 8 lines

--enable-smp \
--enable-pshared \
--enable-registry \
--with-core=cobalt \
CC=aarch64-linux-gnu-gcc \
LD=aarch64-linux-gnu-ld \
CFLAGS="-march=armv8-a" \
LDFLAGS="-march=armv8-a"

Same problem with the 4 lines above removed?
Just wondering if we set a nasty flag somewhere that breaks the object size detection of your compiler.

Quoted 9 lines
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.5 LTS"
$ aarch64-linux-gnu-gcc --version
aarch64-linux-gnu-gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

I have no aarch64 machine for compile-testing at hand so I tried the following (cross-) combinations:

x86:
- gcc 10 (from Debian 12): already fine
- gcc 12 (from Debian 12): already fine
- gcc 15 (from Fedora 42): already fine

aarch64:
- gcc 10 (cross, from Debian 12): already fine
- gcc 12 (cross, from Debian 12): already fine

Result: Unable to reproduce...

Quoted 40 lines

The output of build error:

make[3]: Entering directory '/root/xenomai-next/xenomai-next-build/lib/copperplate/regd'

  CC       regd.o
  CC       fs-common.o
  CC       fs-cobalt.o

In file included from /usr/include/string.h:535,
from /root/xenomai-next/xenomai-next/include/copperplate/heapobj.h:24,
from /root/xenomai-next/xenomai-next/lib/copperplate/regd/fs-common.c:27:
In function 'strncpy',
inlined from 'open_heaps' at /root/xenomai-next/xenomai-next/lib/copperplate/regd/fs-common.c:248:3:
/usr/include/aarch64-linux-gnu/bits/string_fortified.h:95:10: error: '__builtin_strncpy' output may be truncated copying 31 bytes from a string of length 31 [-Werror=stringop-truncation]

   95 |   return __builtin___strncpy_chk (__dest, __src, __len,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   96 |                                   __glibc_objsize (__dest));
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

---
 include/boilerplate/ancillaries.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/boilerplate/ancillaries.h +1 -2
index c8c209deb..8de353ce8 100644
@@ -36,8 +36,7 @@ void __namecpy_requires_character_array_as_destination(void);
 	({								\
 		if (!__builtin_types_compatible_p(typeof(__dst), char[])) \
 			__namecpy_requires_character_array_as_destination();	\
-		strncpy((__dst), __src, sizeof(__dst));			\
-		__dst[sizeof(__dst) - 1] = '\0';			\
+		snprintf((__dst), sizeof(__dst), "%s", (__src));	\
 		__dst;							\
 	 })
 
Signature · 1 line
2.34.1
author
#6 lore raw
Quoted 10 lines · Florian Bezdeka
Quoted 4 lines · Haiyang He

When configure with --enable-registry, it fails to build regd/fs-common.c caused by strncpy. Using snprintf instead of strncpy ensures that the destination buffer is always null-terminated, preventing potential buffer overflow issues and compilation error.

Hm... I have --registry enabled most of the time, so I'm wondering why I did not face the same problem yet. Some questions below:

Quoted 1 line
Quoted 8 lines
Quoted 3 lines
$ ./configure \
--host=aarch64-linux-gnu \
--build=aarch64-linux-gnu \

So you are building on a native aarch64 machine? That might make a difference. Does something change if you just remove the two lines above? The compiler should be selected / detected automatically.

I remove the two lines, but it has the same problem.

Quoted 9 lines
Quoted 8 lines

--enable-smp \
--enable-pshared \
--enable-registry \
--with-core=cobalt \
CC=aarch64-linux-gnu-gcc \
LD=aarch64-linux-gnu-ld \
CFLAGS="-march=armv8-a" \
LDFLAGS="-march=armv8-a"

Quoted 4 lines

Same problem with the 4 lines above removed?
Just wondering if we set a nasty flag somewhere that breaks the object size detection of your compiler.

I remove the 4 lines, but it has the same problem.

Quoted 64 lines
Quoted 9 lines
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.5 LTS"
$ aarch64-linux-gnu-gcc --version
aarch64-linux-gnu-gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

I have no aarch64 machine for compile-testing at hand so I tried the following (cross-) combinations:

x86:
- gcc 10 (from Debian 12): already fine
- gcc 12 (from Debian 12): already fine
- gcc 15 (from Fedora 42): already fine

aarch64:
- gcc 10 (cross, from Debian 12): already fine
- gcc 12 (cross, from Debian 12): already fine

Result: Unable to reproduce...

Quoted 40 lines

The output of build error:

make[3]: Entering directory '/root/xenomai-next/xenomai-next-build/lib/copperplate/regd'

  CC       regd.o
  CC       fs-common.o
  CC       fs-cobalt.o

In file included from /usr/include/string.h:535,
from /root/xenomai-next/xenomai-next/include/copperplate/heapobj.h:24,
from /root/xenomai-next/xenomai-next/lib/copperplate/regd/fs-common.c:27:
In function 'strncpy',
inlined from 'open_heaps' at /root/xenomai-next/xenomai-next/lib/copperplate/regd/fs-common.c:248:3:
/usr/include/aarch64-linux-gnu/bits/string_fortified.h:95:10: error: '__builtin_strncpy' output may be truncated copying 31 bytes from a string of length 31 [-Werror=stringop-truncation]

   95 |   return __builtin___strncpy_chk (__dest, __src, __len,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   96 |                                   __glibc_objsize (__dest));
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

---
 include/boilerplate/ancillaries.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/boilerplate/ancillaries.h +1 -2
index c8c209deb..8de353ce8 100644
@@ -36,8 +36,7 @@ void __namecpy_requires_character_array_as_destination(void);
 	({								\
 		if (!__builtin_types_compatible_p(typeof(__dst), char[])) \
 			__namecpy_requires_character_array_as_destination();	\
-		strncpy((__dst), __src, sizeof(__dst));			\
-		__dst[sizeof(__dst) - 1] = '\0';			\
+		snprintf((__dst), sizeof(__dst), "%s", (__src));	\
 		__dst;							\
 	 })
 
Signature · 1 line
2.34.1