Skip to content

Commit e9e0096

Browse files
LumioseSilmillert
authored andcommitted
Restrict-qualify glob and its functions
glob is restrict-qualified in the standard
1 parent 82eac2b commit e9e0096

2 files changed

Lines changed: 35 additions & 34 deletions

File tree

include/compat/glob.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ typedef struct {
6969
#define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK not set. */
7070
#define GLOB_NOSYS (-4) /* Function not supported. */
7171

72-
sudo_dso_public int sudo_glob(const char *, int, int (*)(const char *, int), glob_t *);
72+
sudo_dso_public int sudo_glob(const char * restrict, int, int (*)(const char *, int), glob_t * restrict);
7373
sudo_dso_public void sudo_globfree(glob_t *);
7474

7575
#define glob(_a, _b, _c, _d) sudo_glob((_a), (_b), (_c), (_d))

lib/util/glob.c

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -138,33 +138,33 @@ struct glob_lim {
138138
};
139139

140140
static int compare(const void *, const void *);
141-
static int g_Ctoc(const Char *, char *, size_t);
142-
static int g_lstat(Char *, struct stat *, glob_t *);
141+
static int g_Ctoc(const Char * restrict, char * restrict, size_t);
142+
static int g_lstat(Char * restrict, struct stat * restrict, glob_t *restrict);
143143
static DIR *g_opendir(Char *, glob_t *);
144144
static Char *g_strchr(const Char *, int);
145145
static int g_strncmp(const Char *, const char *, size_t);
146-
static int g_stat(Char *, struct stat *, glob_t *);
147-
static int glob0(const Char *, glob_t *, struct glob_lim *);
148-
static int glob1(Char *, Char *, glob_t *, struct glob_lim *);
146+
static int g_stat(Char * restrict, struct stat * restrict, glob_t * restrict);
147+
static int glob0(const Char * restrict, glob_t * restrict, struct glob_lim * restrict);
148+
static int glob1(Char *, Char *, glob_t * restrict, struct glob_lim * restrict);
149149
static int glob2(Char *, Char *, Char *, Char *, Char *, Char *,
150-
glob_t *, struct glob_lim *);
150+
glob_t * restrict, struct glob_lim * restrict);
151151
static int glob3(Char *, Char *, Char *, Char *, Char *,
152-
Char *, Char *, glob_t *, struct glob_lim *);
153-
static int globextend(const Char *, glob_t *, struct glob_lim *,
154-
struct stat *);
152+
Char *, Char *, glob_t * restrict, struct glob_lim * restrict);
153+
static int globextend(const Char * restrict, glob_t * restrict, struct glob_lim * restrict,
154+
struct stat * restrict);
155155
static const Char *
156-
globtilde(const Char *, Char *, size_t, glob_t *);
157-
static int globexp1(const Char *, glob_t *, struct glob_lim *);
158-
static int globexp2(const Char *, const Char *, glob_t *,
159-
struct glob_lim *);
156+
globtilde(const Char * restrict, Char * restrict, size_t, glob_t * restrict);
157+
static int globexp1(const Char * restrict, glob_t * restrict, struct glob_lim * restrict);
158+
static int globexp2(const Char *, const Char *, glob_t * restrict,
159+
struct glob_lim * restrict);
160160
static int match(Char *, Char *, Char *);
161161
#ifdef DEBUG
162-
static void qprintf(const char *, Char *);
162+
static void qprintf(const char * restrict, Char * restrict);
163163
#endif
164164

165165
int
166-
sudo_glob(const char *pattern, int flags, int (*errfunc)(const char *, int),
167-
glob_t *pglob)
166+
sudo_glob(const char * restrict pattern, int flags, int (*errfunc)(const char *, int),
167+
glob_t * restrict pglob)
168168
{
169169
const unsigned char *patnext;
170170
int c;
@@ -220,7 +220,7 @@ sudo_glob(const char *pattern, int flags, int (*errfunc)(const char *, int),
220220
* characters
221221
*/
222222
static int
223-
globexp1(const Char *pattern, glob_t *pglob, struct glob_lim *limitp)
223+
globexp1(const Char * restrict pattern, glob_t * restrict pglob, struct glob_lim * restrict limitp)
224224
{
225225
const Char* ptr = pattern;
226226

@@ -241,10 +241,11 @@ globexp1(const Char *pattern, glob_t *pglob, struct glob_lim *limitp)
241241
* If it fails then it tries to glob the rest of the pattern and returns.
242242
*/
243243
static int
244-
globexp2(const Char *ptr, const Char *pattern, glob_t *pglob,
245-
struct glob_lim *limitp)
244+
globexp2(const Char *ptr, const Char *pattern, glob_t * restrict pglob,
245+
struct glob_lim * restrict limitp)
246246
{
247-
int i, rv;
247+
size_t i;
248+
int rv;
248249
Char *lm, *ls;
249250
const Char *pe, *pm, *pl;
250251
Char patbuf[PATH_MAX];
@@ -346,7 +347,7 @@ globexp2(const Char *ptr, const Char *pattern, glob_t *pglob,
346347
* expand tilde from the passwd file.
347348
*/
348349
static const Char *
349-
globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob)
350+
globtilde(const Char * restrict pattern, Char * restrict patbuf, size_t patbuf_len, glob_t * restrict pglob)
350351
{
351352
struct passwd *pwd;
352353
char *h;
@@ -413,7 +414,7 @@ g_strncmp(const Char *s1, const char *s2, size_t n)
413414
}
414415

415416
static int
416-
g_charclass(const Char **patternp, Char **bufnextp)
417+
g_charclass(const Char ** restrict patternp, Char ** restrict bufnextp)
417418
{
418419
const Char *pattern = *patternp + 1;
419420
Char *bufnext = *bufnextp;
@@ -447,7 +448,7 @@ g_charclass(const Char **patternp, Char **bufnextp)
447448
* to find no matches.
448449
*/
449450
static int
450-
glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp)
451+
glob0(const Char * restrict pattern, glob_t * restrict pglob, struct glob_lim * restrict limitp)
451452
{
452453
const Char *qpatnext;
453454
int c, err;
@@ -551,7 +552,7 @@ compare(const void *p, const void *q)
551552
}
552553

553554
static int
554-
glob1(Char *pattern, Char *pattern_last, glob_t *pglob, struct glob_lim *limitp)
555+
glob1(Char *pattern, Char *pattern_last, glob_t * restrict pglob, struct glob_lim * restrict limitp)
555556
{
556557
Char pathbuf[PATH_MAX];
557558

@@ -570,7 +571,7 @@ glob1(Char *pattern, Char *pattern_last, glob_t *pglob, struct glob_lim *limitp)
570571
*/
571572
static int
572573
glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
573-
Char *pattern, Char *pattern_last, glob_t *pglob, struct glob_lim *limitp)
574+
Char *pattern, Char *pattern_last, glob_t * restrict pglob, struct glob_lim * restrict limitp)
574575
{
575576
struct stat sb;
576577
Char *p, *q;
@@ -638,8 +639,8 @@ glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
638639

639640
static int
640641
glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
641-
Char *pattern, Char *restpattern, Char *restpattern_last, glob_t *pglob,
642-
struct glob_lim *limitp)
642+
Char *pattern, Char *restpattern, Char *restpattern_last, glob_t * restrict pglob,
643+
struct glob_lim * restrict limitp)
643644
{
644645
struct dirent *dp;
645646
DIR *dirp;
@@ -721,8 +722,8 @@ glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
721722
* gl_pathv points to (gl_offs + gl_pathc + 1) items.
722723
*/
723724
static int
724-
globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp,
725-
struct stat *sb)
725+
globextend(const Char * restrict path, glob_t * restrict pglob, struct glob_lim * restrict limitp,
726+
struct stat * restrict sb)
726727
{
727728
char **pathv;
728729
size_t i, newn, len;
@@ -892,7 +893,7 @@ g_opendir(Char *str, glob_t *pglob)
892893
}
893894

894895
static int
895-
g_lstat(Char *fn, struct stat *sb, glob_t *pglob)
896+
g_lstat(Char * restrict fn, struct stat * restrict sb, glob_t * restrict pglob)
896897
{
897898
char buf[PATH_MAX];
898899

@@ -902,7 +903,7 @@ g_lstat(Char *fn, struct stat *sb, glob_t *pglob)
902903
}
903904

904905
static int
905-
g_stat(Char *fn, struct stat *sb, glob_t *pglob)
906+
g_stat(Char * restrict fn, struct stat * restrict sb, glob_t * restrict pglob)
906907
{
907908
char buf[PATH_MAX];
908909

@@ -922,7 +923,7 @@ g_strchr(const Char *str, int ch)
922923
}
923924

924925
static int
925-
g_Ctoc(const Char *str, char *buf, size_t len)
926+
g_Ctoc(const Char * restrict str, char * restrict buf, size_t len)
926927
{
927928

928929
while (len--) {
@@ -934,7 +935,7 @@ g_Ctoc(const Char *str, char *buf, size_t len)
934935

935936
#ifdef DEBUG
936937
static void
937-
qprintf(const char *str, Char *s)
938+
qprintf(const char * restrict str, Char * restrict s)
938939
{
939940
Char *p;
940941

0 commit comments

Comments
 (0)