Skip to content

Commit b8530c6

Browse files
committed
libselinux: constify regex interfaces
Declare the read-only arguments for comparison and writing const. Signed-off-by: Christian Göttsche <[email protected]>
1 parent 39b3cc5 commit b8530c6

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

libselinux/src/regex.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ int regex_load_mmap(struct mmap_area *mmap_area, struct regex_data **regex,
164164
return -1;
165165
}
166166

167-
int regex_writef(struct regex_data *regex, FILE *fp, int do_write_precompregex)
167+
int regex_writef(const struct regex_data *regex, FILE *fp, int do_write_precompregex)
168168
{
169169
int rc = 0;
170170
size_t len;
@@ -269,7 +269,7 @@ int regex_match(struct regex_data *regex, char const *subject, int partial)
269269
* Preferably, this function would be replaced with an algorithm that computes
270270
* the equivalence of the automatons systematically.
271271
*/
272-
int regex_cmp(struct regex_data *regex1, struct regex_data *regex2)
272+
int regex_cmp(const struct regex_data *regex1, const struct regex_data *regex2)
273273
{
274274
int rc;
275275
size_t len1, len2;
@@ -407,7 +407,7 @@ int regex_load_mmap(struct mmap_area *mmap_area, struct regex_data **regex,
407407
return -1;
408408
}
409409

410-
static inline pcre_extra *get_pcre_extra(struct regex_data *regex)
410+
static inline const pcre_extra *get_pcre_extra(const struct regex_data *regex)
411411
{
412412
if (!regex) return NULL;
413413
if (regex->owned) {
@@ -419,14 +419,14 @@ static inline pcre_extra *get_pcre_extra(struct regex_data *regex)
419419
}
420420
}
421421

422-
int regex_writef(struct regex_data *regex, FILE *fp,
422+
int regex_writef(const struct regex_data *regex, FILE *fp,
423423
int do_write_precompregex __attribute__((unused)))
424424
{
425425
int rc;
426426
size_t len;
427427
uint32_t to_write;
428428
size_t size;
429-
pcre_extra *sd = get_pcre_extra(regex);
429+
const pcre_extra *sd = get_pcre_extra(regex);
430430

431431
/* determine the size of the pcre data in bytes */
432432
rc = pcre_fullinfo(regex->regex, NULL, PCRE_INFO_SIZE, &size);
@@ -510,7 +510,7 @@ int regex_match(struct regex_data *regex, char const *subject, int partial)
510510
* Preferably, this function would be replaced with an algorithm that computes
511511
* the equivalence of the automatons systematically.
512512
*/
513-
int regex_cmp(struct regex_data *regex1, struct regex_data *regex2)
513+
int regex_cmp(const struct regex_data *regex1, const struct regex_data *regex2)
514514
{
515515
int rc;
516516
size_t len1, len2;

libselinux/src/regex.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ int regex_load_mmap(struct mmap_area *map_area,
120120
* @arg do_write_precompregex If non-zero precompiled patterns are written to
121121
* the output file (ignored by PCRE1 back-end).
122122
*/
123-
int regex_writef(struct regex_data *regex, FILE *fp,
123+
int regex_writef(const struct regex_data *regex, FILE *fp,
124124
int do_write_precompregex) ;
125125
/**
126126
* This function applies a precompiled pattern to a subject string and
@@ -149,7 +149,7 @@ int regex_match(struct regex_data *regex, char const *subject,
149149
* the same
150150
* @retval SELABEL_INCOMPARABLE otherwise
151151
*/
152-
int regex_cmp(struct regex_data *regex1, struct regex_data *regex2) ;
152+
int regex_cmp(const struct regex_data *regex1, const struct regex_data *regex2) ;
153153
/**
154154
* This function takes the error data returned by regex_prepare_data and turns
155155
* it in to a human readable error message.

0 commit comments

Comments
 (0)