strlcpy_expand_host, sudo_getdelim, sudo_realpath: add restrict qualifier

This commit is contained in:
Todd C. Miller
2023-10-17 10:47:43 -06:00
parent 29ddd26793
commit cf9fc5317e
6 changed files with 11 additions and 7 deletions

View File

@@ -342,7 +342,7 @@ sudo_dso_public int sudo_getgrouplist(const char *name, GETGROUPS_T basegid, GET
# define getgrouplist(_a, _b, _c, _d) sudo_getgrouplist((_a), (_b), (_c), (_d))
#endif /* GETGROUPLIST */
#if !defined(HAVE_GETDELIM)
sudo_dso_public ssize_t sudo_getdelim(char **bufp, size_t *bufsizep, int delim, FILE *fp);
sudo_dso_public ssize_t sudo_getdelim(char ** restrict bufp, size_t * restrict bufsizep, int delim, FILE * restrict fp);
# undef getdelim
# define getdelim(_a, _b, _c, _d) sudo_getdelim((_a), (_b), (_c), (_d))
#elif defined(HAVE_DECL_GETDELIM) && !HAVE_DECL_GETDELIM
@@ -533,7 +533,7 @@ sudo_dso_public void *sudo_reallocarray(void *ptr, size_t nmemb, size_t size);
# define reallocarray(_a, _b, _c) sudo_reallocarray((_a), (_b), (_c))
#endif /* HAVE_REALLOCARRAY */
#ifndef HAVE_REALPATH
sudo_dso_public char *sudo_realpath(const char *path, char *resolved);
sudo_dso_public char *sudo_realpath(const char * restrict path, char * restrict resolved);
# undef realpath
# define realpath(_a, _b) sudo_realpath((_a), (_b))
#endif /* HAVE_REALPATH */

View File

@@ -33,7 +33,8 @@
#include <sudo_compat.h>
ssize_t
sudo_getdelim(char **buf, size_t *bufsize, int delim, FILE *fp)
sudo_getdelim(char ** restrict buf, size_t * restrict bufsize, int delim,
FILE * restrict fp)
{
char *cp, *ep;
int ch;

View File

@@ -53,7 +53,7 @@
* in which case the path which caused trouble is left in (resolved).
*/
char *
sudo_realpath(const char *path, char *resolved)
sudo_realpath(const char * restrict path, char * restrict resolved)
{
struct stat sb;
int idx = 0, nlnk = 0;

View File

@@ -38,7 +38,8 @@
sudo_dso_public int main(int argc, char *argv[]);
ssize_t sudo_getdelim(char **bufp, size_t *bufsizep, int delim, FILE *fp);
ssize_t sudo_getdelim(char ** restrict bufp, size_t * restrict bufsizep,
int delim, FILE * restrict fp);
/*
* Test that sudo_getdelim() works as expected.

View File

@@ -5897,7 +5897,8 @@ init_lexer(void)
* Like strlcpy() but expand %h escapes.
*/
static size_t
strlcpy_expand_host(char *dst, const char *src, const char *host, size_t size)
strlcpy_expand_host(char * restrict dst, const char * restrict src,
const char * restrict host, size_t size)
{
size_t len = 0;
char ch;

View File

@@ -1118,7 +1118,8 @@ init_lexer(void)
* Like strlcpy() but expand %h escapes.
*/
static size_t
strlcpy_expand_host(char *dst, const char *src, const char *host, size_t size)
strlcpy_expand_host(char * restrict dst, const char * restrict src,
const char * restrict host, size_t size)
{
size_t len = 0;
char ch;