1570af302Sopenharmony_ci// commit: 72ed3d47e567b1635a35d3c1d174c8a8b2787e30 2014-07-17
2570af302Sopenharmony_ci// regexec should not crash on non-zero nmatch with REG_NOSUB
3570af302Sopenharmony_ci#include <regex.h>
4570af302Sopenharmony_ci#include "test.h"
5570af302Sopenharmony_ci
6570af302Sopenharmony_ciint main(void)
7570af302Sopenharmony_ci{
8570af302Sopenharmony_ci	regex_t re;
9570af302Sopenharmony_ci	int r;
10570af302Sopenharmony_ci
11570af302Sopenharmony_ci	r = regcomp(&re, "abc", REG_NOSUB);
12570af302Sopenharmony_ci	if (r)
13570af302Sopenharmony_ci		t_error("regcomp failed: %d\n", r);
14570af302Sopenharmony_ci	r = regexec(&re, "zyx abc", 1, 0, 0);
15570af302Sopenharmony_ci	if (r == REG_NOMATCH)
16570af302Sopenharmony_ci		t_error("regexec failed to match\n");
17570af302Sopenharmony_ci	else if (r)
18570af302Sopenharmony_ci		t_error("regexec returned invalid code: %d\n", r);
19570af302Sopenharmony_ci	regfree(&re);
20570af302Sopenharmony_ci	return t_status;
21570af302Sopenharmony_ci}
22