Skip to content

Commit 2aebeac

Browse files
lib/string/: Use [0] for end pointers
This helps document the fact that these pointers are pointers to one-after-the-last element of an array. GCC currently has a bug by which it triggers a diagnostic in this code. However, it works just fine, and the diagnostic can be ignored. We're working on removing that false positive in GCC, so the diagnostic will eventually disappear. Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108036> Signed-off-by: Alejandro Colomar <[email protected]>
1 parent 0be754b commit 2aebeac

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

lib/string/sprintf/seprintf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111

1212
#if !defined(HAVE_SEPRINTF)
13-
extern inline char *seprintf(char *dst, const char *end,
13+
extern inline char *seprintf(char *dst, const char end[0],
1414
const char *restrict fmt, ...);
15-
extern inline char *vseprintf(char *dst, const char *end,
15+
extern inline char *vseprintf(char *dst, const char end[0],
1616
const char *restrict fmt, va_list ap);
1717
#endif

lib/string/sprintf/seprintf.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022-2024, Alejandro Colomar <[email protected]>
1+
// SPDX-FileCopyrightText: 2022-2025, Alejandro Colomar <[email protected]>
22
// SPDX-License-Identifier: BSD-3-Clause
33

44

@@ -18,18 +18,18 @@
1818
#if !defined(HAVE_SEPRINTF)
1919
// seprintf - string end-pointer print formatted
2020
format_attr(printf, 3, 4)
21-
inline char *seprintf(char *dst, const char *end, const char *restrict fmt,
21+
inline char *seprintf(char *dst, const char end[0], const char *restrict fmt,
2222
...);
2323
// vseprintf - va_list string end-pointer print formatted
2424
format_attr(printf, 3, 0)
25-
inline char *vseprintf(char *dst, const char *end, const char *restrict fmt,
25+
inline char *vseprintf(char *dst, const char end[0], const char *restrict fmt,
2626
va_list ap);
2727
#endif
2828

2929

3030
#if !defined(HAVE_SEPRINTF)
3131
inline char *
32-
seprintf(char *dst, const char *end, const char *restrict fmt, ...)
32+
seprintf(char *dst, const char end[0], const char *restrict fmt, ...)
3333
{
3434
char *p;
3535
va_list ap;
@@ -45,7 +45,7 @@ seprintf(char *dst, const char *end, const char *restrict fmt, ...)
4545

4646
#if !defined(HAVE_SEPRINTF)
4747
inline char *
48-
vseprintf(char *dst, const char *end, const char *restrict fmt, va_list ap)
48+
vseprintf(char *dst, const char end[0], const char *restrict fmt, va_list ap)
4949
{
5050
int len;
5151
ptrdiff_t size;

lib/string/strcpy/stpecpy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022-2024, Alejandro Colomar <[email protected]>
1+
// SPDX-FileCopyrightText: 2022-2025, Alejandro Colomar <[email protected]>
22
// SPDX-License-Identifier: BSD-3-Clause
33

44

@@ -8,6 +8,6 @@
88

99

1010
#if !defined(HAVE_STPECPY)
11-
extern inline char *stpecpy(char *dst, const char *end,
11+
extern inline char *stpecpy(char *dst, const char end[0],
1212
const char *restrict src);
1313
#endif

lib/string/strcpy/stpecpy.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022-2024, Alejandro Colomar <[email protected]>
1+
// SPDX-FileCopyrightText: 2022-2025, Alejandro Colomar <[email protected]>
22
// SPDX-License-Identifier: BSD-3-Clause
33

44

@@ -20,13 +20,13 @@
2020
#if !defined(HAVE_STPECPY)
2121
// stpecpy - string offset-pointer end-pointer copy
2222
ATTR_STRING(3)
23-
inline char *stpecpy(char *dst, const char *end, const char *restrict src);
23+
inline char *stpecpy(char *dst, const char end[0], const char *restrict src);
2424
#endif
2525

2626

2727
#if !defined(HAVE_STPECPY)
2828
inline char *
29-
stpecpy(char *dst, const char *end, const char *restrict src)
29+
stpecpy(char *dst, const char end[0], const char *restrict src)
3030
{
3131
ssize_t dlen;
3232

0 commit comments

Comments
 (0)