Actually, my "fix" from earlier isn't quite right -- the line (from whatever input file) could have null chars in it, and grep ought to handle that gracefully instead of exploding (GNU grep handles this just fine). But we see:
% printf '\0' | LANG="en_US.UTF-8" grep -o 'b*'
Assertion failed: (advance > 0), function procline, file util.c, line 732.
[1] 24086 done printf '\0' |
24087 abort LANG="en_US.UTF-8" ./grep-debug -o 'b*'
Same sort of result, but now the '\0' char is coming from the input, rather than the line buffer's terminal '\0'.
So maybe something like so:
diff --git a/grep/util.c b/grep/util.c
index f362f97..1689061 100644
--- a/grep/util.c
+++ b/grep/util.c
@@ -691,7 +691,7 @@ procline(struct parsec *pc)
#ifdef __APPLE__
/* rdar://problem/86536080 */
if (pmatch.rm_so == pmatch.rm_eo) {
- if (MB_CUR_MAX > 1) {
+ if (MB_CUR_MAX > 1 && nst < pc->ln.len && pc->ln.dat[nst] != '\0') {
wchar_t wc;
int advance;
@@ -721,7 +721,7 @@ procline(struct parsec *pc)
* either make progress or end the search.
*/
if (pmatch.rm_so == pmatch.rm_eo) {
- if (MB_CUR_MAX > 1) {
+ if (MB_CUR_MAX > 1 && nst < pc->ln.len && pc->ln.dat[nst] != '\0') {
wchar_t wc;
int advance;
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags: