Skip to content

Conversation

@alejandro-colomar
Copy link
Collaborator

@alejandro-colomar alejandro-colomar commented Nov 27, 2024

The first commit is just readability stuff, but the second one is an important safety improvement.

Cc: @uecker


Revisions:

v1b
  • Rebase
$ git range-diff master..gh/arrayparam shadow/master..arrayparam 
1:  208d2461 = 1:  21a2e3d7 lib/alloc/: Compact parameter names
2:  6652239e = 2:  74c8c193 lib/string/: Use array notation with forward declarations
v1c
  • Rebase
$ git range-diff master..gh/arrayparam shadow/master..arrayparam 
1:  21a2e3d7 = 1:  c6b33e71 lib/alloc/: Compact parameter names
2:  74c8c193 = 2:  108e00b2 lib/string/: Use array notation with forward declarations
v1d
  • Rebase
$ git range-diff master..gh/arrayparam shadow/master..arrayparam 
1:  c6b33e71 = 1:  ec3e7478 lib/alloc/: Compact parameter names
2:  108e00b2 = 2:  839aa80e lib/string/: Use array notation with forward declarations
v1e
  • Rebase
$ git range-diff master..gh/arrayparam shadow/master..arrayparam 
1:  ec3e7478 = 1:  ed3d9a60 lib/alloc/: Compact parameter names
2:  839aa80e = 2:  fea5bcf1 lib/string/: Use array notation with forward declarations
v1f
  • Rebase
$ git range-diff master..gh/arrayparam shadow/master..arrayparam 
1:  ed3d9a60 = 1:  639a287d lib/alloc/: Compact parameter names
2:  fea5bcf1 = 2:  40bd9363 lib/string/: Use array notation with forward declarations
v1g
  • Rebase
$ git range-diff alx/master..gh/arrayparam master..arrayparam 
1:  639a287d = 1:  b20779a4 lib/alloc/: Compact parameter names
2:  40bd9363 = 2:  91af1e44 lib/string/: Use array notation with forward declarations
v1h
  • Rebase
$ git range-diff alx/master..gh/arrayparam master..arrayparam 
1:  b20779a4 = 1:  3c3052ad lib/alloc/: Compact parameter names
2:  91af1e44 = 2:  133e9cca lib/string/: Use array notation with forward declarations
v1i
  • Rebase
$ git range-diff master..gh/arrayparam shadow/master..arrayparam 
1:  3c3052ad = 1:  a03c31a6 lib/alloc/: Compact parameter names
2:  133e9cca = 2:  b0589f79 lib/string/: Use array notation with forward declarations
v1j
  • Rebase
$ git range-diff master..gh/arrayparam shadow/master..arrayparam 
1:  a03c31a6 = 1:  e6ba045f lib/alloc/: Compact parameter names
2:  b0589f79 = 2:  087d85ed lib/string/: Use array notation with forward declarations
v2
  • Do the same for lib/fs/
$ git range-diff master gh/arrayparam arrayparam 
1:  e6ba045f = 1:  e6ba045f lib/alloc/: Compact parameter names
2:  087d85ed = 2:  087d85ed lib/string/: Use array notation with forward declarations
-:  -------- > 3:  ee6ce25e lib/fs/: Use array notation with forward declarations
v2b
  • Rebase
$ git range-diff master..gh/arrayparam shadow/master..arrayparam 
1:  e6ba045f = 1:  9d17ed47 lib/alloc/: Compact parameter names
2:  087d85ed = 2:  4f70f9f4 lib/string/: Use array notation with forward declarations
3:  ee6ce25e = 3:  b9be41f3 lib/fs/: Use array notation with forward declarations
v2c
  • Rebase
$ git range-diff master..gh/arrayparam shadow/master..arrayparam 
1:  9d17ed47 = 1:  49c27768 lib/alloc/: Compact parameter names
2:  4f70f9f4 = 2:  c0ac4db5 lib/string/: Use array notation with forward declarations
3:  b9be41f3 = 3:  94a72033 lib/fs/: Use array notation with forward declarations
v2d
  • Rebase
$ git range-diff master..gh/arrayparam shadow/master..arrayparam 
1:  49c27768 = 1:  06655043 lib/alloc/: Compact parameter names
2:  c0ac4db5 = 2:  69290f14 lib/string/: Use array notation with forward declarations
3:  94a72033 = 3:  34c2c098 lib/fs/: Use array notation with forward declarations
v2e
  • Rebase
$ git range-diff --creation-factor=99 master..gh/arrayparam shadow/master..arrayparam 
1:  06655043 = 1:  fa543f1f lib/alloc/: Compact parameter names
2:  69290f14 = 2:  8eb8ff29 lib/string/: Use array notation with forward declarations
3:  34c2c098 ! 3:  dc7167fd lib/fs/: Use array notation with forward declarations
    @@ lib/fs/readlink/readlinknul.c
      
      
     -extern inline ssize_t readlinknul(const char *restrict link, char *restrict buf,
    --    size_t size);
    +-    ssize_t size);
     +extern inline ssize_t readlinknul(size_t size;
    -+    const char *restrict link, char buf[restrict size], size_t size);
    ++    const char *restrict link, char buf[restrict size], ssize_t size);
     
      ## lib/fs/readlink/readlinknul.h ##
     @@
    @@ lib/fs/readlink/readlinknul.h
      
      ATTR_STRING(1)
     -inline ssize_t readlinknul(const char *restrict link, char *restrict buf,
    --    size_t size);
    +-    ssize_t size);
     +inline ssize_t readlinknul(size_t size;
    -+    const char *restrict link, char buf[restrict size], size_t size);
    ++    const char *restrict link, char buf[restrict size], ssize_t size);
      
      
      // Similar to readlink(2), but terminate the string.
      inline ssize_t
    --readlinknul(const char *restrict link, char *restrict buf, size_t size)
    +-readlinknul(const char *restrict link, char *restrict buf, ssize_t size)
     +readlinknul(size_t size;
    -+    const char *restrict link, char buf[restrict size], size_t size)
    ++    const char *restrict link, char buf[restrict size], ssize_t size)
      {
    -   size_t   ulen;
    -   ssize_t  slen;
    +   ssize_t  len;
    + 
v2f
  • Rebase
$ git rd
1:  fa543f1f = 1:  41ad41c9 lib/alloc/: Compact parameter names
2:  8eb8ff29 = 2:  838dfa21 lib/string/: Use array notation with forward declarations
3:  dc7167fd = 3:  0926e791 lib/fs/: Use array notation with forward declarations
v2g
  • Rebase
$ git rd 
1:  41ad41c9 = 1:  8486d3ec lib/alloc/: Compact parameter names
2:  838dfa21 = 2:  10f33fe8 lib/string/: Use array notation with forward declarations
3:  0926e791 = 3:  31afd7d2 lib/fs/: Use array notation with forward declarations
v2h
  • Rebase
$ git rd
1:  8486d3ec = 1:  0ebe7f5d lib/alloc/: Compact parameter names
2:  10f33fe8 = 2:  5a3fbce8 lib/string/: Use array notation with forward declarations
3:  31afd7d2 = 3:  ad533df9 lib/fs/: Use array notation with forward declarations
v2i
  • Rebase
$ git rd
1:  0ebe7f5d = 1:  d1cafe3e lib/alloc/: Compact parameter names
2:  5a3fbce8 = 2:  f1c50dbc lib/string/: Use array notation with forward declarations
3:  ad533df9 = 3:  c6238539 lib/fs/: Use array notation with forward declarations
v2j
  • Rebase
$ git rd
1:  d1cafe3e = 1:  9d30db42 lib/alloc/: Compact parameter names
2:  f1c50dbc = 2:  ee4d94bd lib/string/: Use array notation with forward declarations
3:  c6238539 = 3:  10dad35a lib/fs/: Use array notation with forward declarations
v2k
  • Rebase
$ git rd 
1:  9d30db42 = 1:  7c1162ed lib/alloc/: Compact parameter names
2:  ee4d94bd = 2:  d30cea9e lib/string/: Use array notation with forward declarations
3:  10dad35a = 3:  88778fd6 lib/fs/: Use array notation with forward declarations
v2l
  • Rebase
$ git rd 
1:  7c1162ed = 1:  1467c1e0 lib/alloc/: Compact parameter names
2:  d30cea9e = 2:  24f6dc33 lib/string/: Use array notation with forward declarations
3:  88778fd6 = 3:  d2a0110a lib/fs/: Use array notation with forward declarations
v2m
  • Rebase
$ git rd
1:  1467c1e0 = 1:  3fe155d3 lib/alloc/: Compact parameter names
2:  24f6dc33 = 2:  fcca9ef8 lib/string/: Use array notation with forward declarations
3:  d2a0110a = 3:  6ec4643d lib/fs/: Use array notation with forward declarations
v2n
  • Rebase
$ git rd 
1:  3fe155d3 = 1:  02149ac1 lib/alloc/: Compact parameter names
2:  fcca9ef8 = 2:  25cd50d6 lib/string/: Use array notation with forward declarations
3:  6ec4643d = 3:  04a53ba1 lib/fs/: Use array notation with forward declarations
v3
  • Update type of forward-declared parameter after some changes in master.
$ git rd 
1:  810601e5 ! 1:  32f13c9c lib/, src/: Use str[n]cmp(3) instead of explicit byte comparisons
    @@ Metadata
     Author: Alejandro Colomar <[email protected]>
     
      ## Commit message ##
    -    lib/, src/: Use str[n]cmp(3) instead of explicit byte comparisons
    +    lib/, src/: Use strncmp(3) instead of explicit byte comparisons
     
         This is simpler to read, IMO.
     
    @@ lib/utmp.c: active_sessions_count(const char *name, unsigned long limit)
                        continue;
                }
     -          if ('\0' == ut->ut_user[0]) {
    -+          if (strncmp(ut->ut_user, "", NITEMS(ut->ut_user)) == 0)
    ++          if (strncmp(ut->ut_user, "", countof(ut->ut_user)) == 0)
                        continue;
     -          }
     -          if (strncmp (name, ut->ut_user, sizeof (ut->ut_user)) != 0) {
     +
    -+          if (strncmp(ut->ut_user, name, NITEMS(ut->ut_user)) != 0)
    ++          if (strncmp(ut->ut_user, name, countof(ut->ut_user)) != 0)
                        continue;
     -          }
     +
    @@ src/logoutd.c: main(int argc, char **argv)
                                continue;
                        }
     -                  if (ut->ut_user[0] == '\0') {
    -+                  if (strncmp(ut->ut_user, "", NITEMS(ut->ut_user)) == 0)
    ++                  if (strncmp(ut->ut_user, "", countof(ut->ut_user)) == 0)
                                continue;
     -                  }
     +
2:  044bfd89 = 2:  4a514b51 contrib/, lib/, src/: Use consistent style using strchr(3) in conditionals
v3b
  • Rebase
$ git rd 
1:  02149ac1 = 1:  31a131bf lib/alloc/: Compact parameter names
2:  25cd50d6 = 2:  46a7afa8 lib/string/: Use array notation with forward declarations
3:  254206e3 = 3:  69d4db2c lib/fs/: Use array notation with forward declarations
v3c
  • Rebase
$ git rd 
1:  31a131bf = 1:  b74695b7 lib/alloc/: Compact parameter names
2:  46a7afa8 = 2:  a7d939fc lib/string/: Use array notation with forward declarations
3:  69d4db2c = 3:  1b6eedcb lib/fs/: Use array notation with forward declarations
v3d
  • Rebase
$ git rd 
1:  b74695b7 = 1:  1f06623e lib/alloc/: Compact parameter names
2:  a7d939fc = 2:  6da03ac1 lib/string/: Use array notation with forward declarations
3:  1b6eedcb = 3:  26dd4aeb lib/fs/: Use array notation with forward declarations
v4
  • Use array notation in stpecpy() and [v]stpeprintf().
$ git range-diff master gh/arrayparam arrayparam 
1:  1f06623e = 1:  1f06623e lib/alloc/: Compact parameter names
2:  6da03ac1 = 2:  6da03ac1 lib/string/: Use array notation with forward declarations
3:  26dd4aeb = 3:  26dd4aeb lib/fs/: Use array notation with forward declarations
-:  -------- > 4:  ba4ee389 lib/string/: Use array notation with forward declarations
v4b
  • wfix
$ git range-diff master gh/arrayparam arrayparam 
1:  1f06623e = 1:  1f06623e lib/alloc/: Compact parameter names
2:  6da03ac1 = 2:  6da03ac1 lib/string/: Use array notation with forward declarations
3:  26dd4aeb = 3:  26dd4aeb lib/fs/: Use array notation with forward declarations
4:  ba4ee389 ! 4:  76a7a61d lib/string/: Use array notation with forward declarations
    @@ Metadata
     Author: Alejandro Colomar <[email protected]>
     
      ## Commit message ##
    -    lib/string/: Use array notation with forward declarations
    +    lib/string/: stpe*(): Use array notation with forward declarations
     
         Signed-off-by: Alejandro Colomar <[email protected]>
     
v4c
  • Rebase
$ git rd 
1:  1f06623e = 1:  ec0639ac lib/alloc/: Compact parameter names
2:  6da03ac1 = 2:  de49e9ba lib/string/: Use array notation with forward declarations
3:  26dd4aeb = 3:  64e70dd9 lib/fs/: Use array notation with forward declarations
4:  76a7a61d = 4:  37e3e7b3 lib/string/: stpe*(): Use array notation with forward declarations
v5
  • Be careful with NULL.
$ git rd 
1:  ec0639ac = 1:  ec0639ac lib/alloc/: Compact parameter names
2:  de49e9ba = 2:  de49e9ba lib/string/: Use array notation with forward declarations
3:  64e70dd9 = 3:  64e70dd9 lib/fs/: Use array notation with forward declarations
4:  37e3e7b3 ! 4:  e23d3d18 lib/string/: stpe*(): Use array notation with forward declarations
    @@ lib/string/sprintf/stpeprintf.c
     -extern inline char *vstpeprintf(char *dst, char *end, const char *restrict fmt,
     -    va_list ap);
     +extern inline char *stpeprintf(char *dst, char *end;
    -+    char dst[end - dst], char end[0], const char *restrict fmt, ...);
    ++    char dst[dst ? end - dst : 0], char end[0], const char *restrict fmt, ...);
     +extern inline char *vstpeprintf(char *dst, char *end;
    -+    char dst[end - dst], char end[0], const char *restrict fmt, va_list ap);
    ++    char dst[dst ? end - dst : 0], char end[0], const char *restrict fmt, va_list ap);
      #endif
     
      ## lib/string/sprintf/stpeprintf.h ##
    @@ lib/string/sprintf/stpeprintf.h
      format_attr(printf, 3, 4)
     -inline char *stpeprintf(char *dst, char *end, const char *restrict fmt, ...);
     +inline char *stpeprintf(char *dst, char *end;
    -+    char dst[end - dst], char end[0], const char *restrict fmt, ...);
    ++    char dst[dst ? end - dst : 0], char end[0], const char *restrict fmt, ...);
      format_attr(printf, 3, 0)
     -inline char *vstpeprintf(char *dst, char *end, const char *restrict fmt,
     -    va_list ap);
     +inline char *vstpeprintf(char *dst, char *end;
    -+    char dst[end - dst], char end[0], const char *restrict fmt, va_list ap);
    ++    char dst[dst ? end - dst : 0], char end[0], const char *restrict fmt, va_list ap);
      #endif
      
      
    @@ lib/string/sprintf/stpeprintf.h: inline char *vstpeprintf(char *dst, char *end,
      inline char *
     -stpeprintf(char *dst, char *end, const char *restrict fmt, ...)
     +stpeprintf(char *dst, char *end;
    -+    char dst[end - dst], char end[0], const char *restrict fmt, ...)
    ++    char dst[dst ? end - dst : 0], char end[0], const char *restrict fmt, ...)
      {
        char     *p;
        va_list  ap;
    @@ lib/string/sprintf/stpeprintf.h: stpeprintf(char *dst, char *end, const char *re
      inline char *
     -vstpeprintf(char *dst, char *end, const char *restrict fmt, va_list ap)
     +vstpeprintf(char *dst, char *end;
    -+    char dst[end - dst], char end[0], const char *restrict fmt, va_list ap)
    ++    char dst[dst ? end - dst : 0], char end[0], const char *restrict fmt, va_list ap)
      {
        int        len;
        ptrdiff_t  size;
    @@ lib/string/strcpy/stpecpy.c
      #if !defined(HAVE_STPECPY)
     -extern inline char *stpecpy(char *dst, char *end, const char *restrict src);
     +extern inline char *stpecpy(char *dst, char *end;
    -+    char dst[end - dst], char end[0], const char *restrict src);
    ++    char dst[dst ? end - dst : 0], char end[0], const char *restrict src);
      #endif
     
      ## lib/string/strcpy/stpecpy.h ##
    @@ lib/string/strcpy/stpecpy.h
      ATTR_STRING(3)
     -inline char *stpecpy(char *dst, char *end, const char *restrict src);
     +inline char *stpecpy(char *dst, char *end;
    -+    char dst[end - dst], char end[0], const char *restrict src);
    ++    char dst[dst ? end - dst : 0], char end[0], const char *restrict src);
      #endif
      
      
    @@ lib/string/strcpy/stpecpy.h: inline char *stpecpy(char *dst, char *end, const ch
      inline char *
     -stpecpy(char *dst, char *end, const char *restrict src)
     +stpecpy(char *dst, char *end;
    -+    char dst[end - dst], char end[0], const char *restrict src)
    ++    char dst[dst ? end - dst : 0], char end[0], const char *restrict src)
      {
        bool    trunc;
        size_t  dsize, dlen, slen;
v6
  • Use array notation consistently.
$ git rd 
1:  ec0639ac = 1:  ec0639ac lib/alloc/: Compact parameter names
2:  de49e9ba = 2:  de49e9ba lib/string/: Use array notation with forward declarations
3:  64e70dd9 = 3:  64e70dd9 lib/fs/: Use array notation with forward declarations
4:  e23d3d18 ! 4:  7f953953 lib/string/: stpe*(): Use array notation with forward declarations
    @@ lib/string/sprintf/stpeprintf.c
     -    ...);
     -extern inline char *vstpeprintf(char *dst, char *end, const char *restrict fmt,
     -    va_list ap);
    -+extern inline char *stpeprintf(char *dst, char *end;
    ++extern inline char *stpeprintf(char dst[], char end[];
     +    char dst[dst ? end - dst : 0], char end[0], const char *restrict fmt, ...);
    -+extern inline char *vstpeprintf(char *dst, char *end;
    ++extern inline char *vstpeprintf(char dst[], char end[];
     +    char dst[dst ? end - dst : 0], char end[0], const char *restrict fmt, va_list ap);
      #endif
     
    @@ lib/string/sprintf/stpeprintf.h
      #if !defined(HAVE_STPEPRINTF)
      format_attr(printf, 3, 4)
     -inline char *stpeprintf(char *dst, char *end, const char *restrict fmt, ...);
    -+inline char *stpeprintf(char *dst, char *end;
    ++inline char *stpeprintf(char dst[], char end[];
     +    char dst[dst ? end - dst : 0], char end[0], const char *restrict fmt, ...);
      format_attr(printf, 3, 0)
     -inline char *vstpeprintf(char *dst, char *end, const char *restrict fmt,
     -    va_list ap);
    -+inline char *vstpeprintf(char *dst, char *end;
    ++inline char *vstpeprintf(char dst[], char end[];
     +    char dst[dst ? end - dst : 0], char end[0], const char *restrict fmt, va_list ap);
      #endif
      
    @@ lib/string/sprintf/stpeprintf.h: inline char *vstpeprintf(char *dst, char *end,
      #if !defined(HAVE_STPEPRINTF)
      inline char *
     -stpeprintf(char *dst, char *end, const char *restrict fmt, ...)
    -+stpeprintf(char *dst, char *end;
    ++stpeprintf(char dst[], char end[];
     +    char dst[dst ? end - dst : 0], char end[0], const char *restrict fmt, ...)
      {
        char     *p;
    @@ lib/string/sprintf/stpeprintf.h: stpeprintf(char *dst, char *end, const char *re
      #if !defined(HAVE_STPEPRINTF)
      inline char *
     -vstpeprintf(char *dst, char *end, const char *restrict fmt, va_list ap)
    -+vstpeprintf(char *dst, char *end;
    ++vstpeprintf(char dst[], char end[];
     +    char dst[dst ? end - dst : 0], char end[0], const char *restrict fmt, va_list ap)
      {
        int        len;
    @@ lib/string/strcpy/stpecpy.c
      
      #if !defined(HAVE_STPECPY)
     -extern inline char *stpecpy(char *dst, char *end, const char *restrict src);
    -+extern inline char *stpecpy(char *dst, char *end;
    ++extern inline char *stpecpy(char dst[], char end[];
     +    char dst[dst ? end - dst : 0], char end[0], const char *restrict src);
      #endif
     
    @@ lib/string/strcpy/stpecpy.h
      #if !defined(HAVE_STPECPY)
      ATTR_STRING(3)
     -inline char *stpecpy(char *dst, char *end, const char *restrict src);
    -+inline char *stpecpy(char *dst, char *end;
    ++inline char *stpecpy(char dst[], char end[];
     +    char dst[dst ? end - dst : 0], char end[0], const char *restrict src);
      #endif
      
    @@ lib/string/strcpy/stpecpy.h: inline char *stpecpy(char *dst, char *end, const ch
      #if !defined(HAVE_STPECPY)
      inline char *
     -stpecpy(char *dst, char *end, const char *restrict src)
    -+stpecpy(char *dst, char *end;
    ++stpecpy(char dst[], char end[];
     +    char dst[dst ? end - dst : 0], char end[0], const char *restrict src)
      {
        bool    trunc;
v6b
  • Rebase
$ git rd 
1:  ec0639ac = 1:  a58b4d82 lib/alloc/: Compact parameter names
2:  de49e9ba = 2:  55c315cd lib/string/: Use array notation with forward declarations
3:  64e70dd9 = 3:  8f7cc9c8 lib/fs/: Use array notation with forward declarations
4:  7f953953 = 4:  9c468a5f lib/string/: stpe*(): Use array notation with forward declarations
v6c
  • Rebase
$ git rd 
1:  a58b4d82 = 1:  acab2961 lib/alloc/: Compact parameter names
2:  55c315cd = 2:  fb5ce090 lib/string/: Use array notation with forward declarations
3:  8f7cc9c8 = 3:  dd5e7720 lib/fs/: Use array notation with forward declarations
4:  9c468a5f = 4:  daf25218 lib/string/: stpe*(): Use array notation with forward declarations
v6d
  • Rebase
$ git rd 
1:  acab2961 = 1:  dc6bde34 lib/alloc/: Compact parameter names
2:  fb5ce090 = 2:  c728f52b lib/string/: Use array notation with forward declarations
3:  dd5e7720 = 3:  29665517 lib/fs/: Use array notation with forward declarations
4:  daf25218 = 4:  79d59a11 lib/string/: stpe*(): Use array notation with forward declarations
v6e
  • Rebase
$ git rd 
1:  dc6bde34 = 1:  a4a0e87a lib/alloc/: Compact parameter names
2:  c728f52b = 2:  89f63c96 lib/string/: Use array notation with forward declarations
3:  29665517 = 3:  11e40ee2 lib/fs/: Use array notation with forward declarations
4:  79d59a11 = 4:  bc4d8154 lib/string/: stpe*(): Use array notation with forward declarations
v6f
  • Rebase
$ git rd 
1:  a4a0e87a ! 1:  030f205f lib/alloc/: Compact parameter names
    @@ lib/alloc/reallocf.h
      
        if (q == NULL)
                free(p);
    -
    - ## lib/alloc/x/xcalloc.c ##
    -@@
    - 
    - 
    - void *
    --xcalloc(size_t nmemb, size_t size)
    -+xcalloc(size_t n, size_t size)
    - {
    -   void  *p;
    - 
    --  p = calloc(nmemb, size);
    -+  p = calloc(n, size);
    -   if (p == NULL)
    -           goto x;
    - 
    -
    - ## lib/alloc/x/xcalloc.h ##
    -@@
    - 
    - ATTR_ALLOC_SIZE(1, 2)
    - ATTR_MALLOC(free)
    --void *xcalloc(size_t nmemb, size_t size);
    -+void *xcalloc(size_t n, size_t size);
    - 
    - 
    - #endif  // include guard
    -
    - ## lib/alloc/x/xmalloc.c ##
    -@@
    - #include <stddef.h>
    - 
    - 
    --extern inline void *xmallocarray(size_t nmemb, size_t size);
    -+extern inline void *xmallocarray(size_t n, size_t size);
    -
    - ## lib/alloc/x/xmalloc.h ##
    -@@
    - 
    - ATTR_ALLOC_SIZE(1, 2)
    - ATTR_MALLOC(free)
    --inline void *xmallocarray(size_t nmemb, size_t size);
    -+inline void *xmallocarray(size_t n, size_t size);
    - 
    - 
    - inline void *
    --xmallocarray(size_t nmemb, size_t size)
    -+xmallocarray(size_t n, size_t size)
    - {
    --  return xreallocarray(NULL, nmemb, size);
    -+  return xreallocarray(NULL, n, size);
    - }
    - 
    - 
    -
    - ## lib/alloc/x/xrealloc.c ##
    -@@
    - 
    - 
    - void *
    --xreallocarray(void *p, size_t nmemb, size_t size)
    -+xreallocarray(void *p, size_t n, size_t size)
    - {
    --  p = reallocarrayf(p, nmemb, size);
    -+  p = reallocarrayf(p, n, size);
    -   if (p == NULL)
    -           goto x;
    - 
    -
    - ## lib/alloc/x/xrealloc.h ##
    -@@
    - 
    - ATTR_ALLOC_SIZE(2, 3)
    - ATTR_MALLOC(free)
    --void *xreallocarray(void *p, size_t nmemb, size_t size);
    -+void *xreallocarray(void *p, size_t n, size_t size);
    - 
    - 
    - #endif  // include guard
2:  89f63c96 = 2:  24cec0c0 lib/string/: Use array notation with forward declarations
3:  11e40ee2 = 3:  1134b8be lib/fs/: Use array notation with forward declarations
4:  bc4d8154 = 4:  747d09c8 lib/string/: stpe*(): Use array notation with forward declarations

@alejandro-colomar alejandro-colomar marked this pull request as ready for review November 27, 2024 12:43
@alejandro-colomar alejandro-colomar force-pushed the arrayparam branch 4 times, most recently from 839aa80 to fea5bcf Compare December 6, 2024 12:08
@alejandro-colomar
Copy link
Collaborator Author

Queued after the release of 4.17.0.

@alejandro-colomar alejandro-colomar marked this pull request as draft December 6, 2024 12:16
@alejandro-colomar alejandro-colomar marked this pull request as ready for review December 22, 2024 12:03
@alejandro-colomar alejandro-colomar added the Simpler A good issue for a new beginner label Dec 22, 2024
@alejandro-colomar alejandro-colomar force-pushed the arrayparam branch 2 times, most recently from 133e9cc to b0589f7 Compare January 24, 2025 15:22
@alejandro-colomar alejandro-colomar force-pushed the arrayparam branch 3 times, most recently from 94a7203 to 34c2c09 Compare February 16, 2025 22:50
@alejandro-colomar alejandro-colomar force-pushed the arrayparam branch 4 times, most recently from 10dad35 to 88778fd Compare June 2, 2025 09:14
@alejandro-colomar alejandro-colomar force-pushed the arrayparam branch 2 times, most recently from d2a0110 to 6ec4643 Compare June 3, 2025 20:03
@alejandro-colomar alejandro-colomar force-pushed the arrayparam branch 3 times, most recently from 254206e to 69d4db2 Compare June 7, 2025 14:56
@alejandro-colomar alejandro-colomar force-pushed the arrayparam branch 2 times, most recently from ba4ee38 to 76a7a61 Compare July 20, 2025 11:53
@alejandro-colomar alejandro-colomar force-pushed the arrayparam branch 2 times, most recently from 37e3e7b to e23d3d1 Compare July 20, 2025 22:05
inline char *
stpeprintf(char *dst, char *end, const char *restrict fmt, ...)
stpeprintf(char *dst, char *end;
char dst[dst ? end - dst : 0], char end[0], const char *restrict fmt, ...)

Check notice

Code scanning / CodeQL

Short global name Note

Poor global variable name 'dst'. Prefer longer, descriptive names for globals (eg. kMyGlobalConstant, not foo).
inline char *
stpecpy(char *dst, char *end, const char *restrict src)
stpecpy(char *dst, char *end;
char dst[dst ? end - dst : 0], char end[0], const char *restrict src)

Check notice

Code scanning / CodeQL

Short global name Note

Poor global variable name 'dst'. Prefer longer, descriptive names for globals (eg. kMyGlobalConstant, not foo).
'n' is just as meaningful as 'nmemb', and is in more common use in C
projects (including this one).

Signed-off-by: Alejandro Colomar <[email protected]>
GNU C has an extension which allows to forward-declare parameters, so
that array notation can be used with sizes that are defined after the
array itself.

This improves the safety of such arrays, by telling the compiler the
bounds of the array.

This feature has been proposed for standardization in C2y as n3394.

Link: n3394 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3394.pdf>
Cc: Martin Uecker <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Simpler A good issue for a new beginner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant