Skip to content

Commit f96d97e

Browse files
committed
bin/xbps-query: actually report regex errors
1 parent 82e8acd commit f96d97e

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

bin/xbps-query/ownedby.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,13 @@ ownedby(struct xbps_handle *xhp, const char *pat, bool repo, bool regex)
188188

189189
if (regex) {
190190
ffd.rematch = true;
191-
if (regcomp(&ffd.regex, ffd.pat, REG_EXTENDED|REG_NOSUB|REG_ICASE) != 0)
191+
rv = regcomp(&ffd.regex, ffd.pat, REG_EXTENDED|REG_NOSUB|REG_ICASE);
192+
if (rv != 0) {
193+
char errbuf[256];
194+
regerror(rv, &ffd.regex, errbuf, sizeof(errbuf));
195+
fprintf(stderr, "Failed to compile pattern: %s\n", errbuf);
192196
return EINVAL;
197+
}
193198
}
194199
if (repo)
195200
rv = xbps_rpool_foreach(xhp, repo_ownedby_cb, &ffd);

bin/xbps-query/search.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,15 @@ search(struct xbps_handle *xhp, bool repo_mode, const char *pat, const char *pro
229229

230230
sd.regex = regex;
231231
if (regex) {
232-
if (regcomp(&sd.regexp, pat, REG_EXTENDED|REG_NOSUB|REG_ICASE) != 0)
233-
return errno;
232+
rv = regcomp(&sd.regexp, pat, REG_EXTENDED|REG_NOSUB|REG_ICASE);
233+
if (rv != 0) {
234+
char errbuf[256];
235+
regerror(rv, &sd.regexp, errbuf, sizeof(errbuf));
236+
fprintf(stderr, "Failed to compile pattern: %s\n", errbuf);
237+
return EINVAL;
238+
}
234239
}
240+
235241
sd.repo_mode = repo_mode;
236242
sd.pat = pat;
237243
sd.prop = prop;

0 commit comments

Comments
 (0)