Post

Replies

Boosts

Views

Activity

macOS Sonoma broke grep (assertion fails)
grep is broken on Sonoma: printf '%s' '3.2.57(1)-release' | grep -o '[0-9.]*' Assertion failed: (advance > 0), function procline, file util.c, line 732. zsh: done printf '%s' '3.2.57(1)-release' | zsh: abort grep -o '[0-9.]*' For minimal reproducers, see: # fails printf '%s' 'a' | grep -o 'b*' # works printf '%s' 'a' | grep -o 'b' # also works (note: without -o flag) printf '%s' 'a' | grep 'b*' This is the source for the assertion: https://github.com/apple-oss-distributions/text_cmds/blob/c0780aa3432383e0acde7dc7cf42972716925de6/grep/util.c#L732 For posterity: /* * rdar://problem/86536080 - if our first match * was 0-length, we wouldn't progress past that * point. Incrementing nst here ensures that if * no other pattern matches, we'll restart the * search at one past the 0-length match and * either make progress or end the search. */ if (pmatch.rm_so == pmatch.rm_eo) { if (MB_CUR_MAX > 1) { wchar_t wc; int advance; advance = mbtowc(&wc, &pc->ln.dat[nst], MB_CUR_MAX); assert(advance > 0); nst += advance; } else { nst++; } } It looks like the macOS devs tried to fix one thing but broke another. I would update rdar://problem/86536080, but it looks like that's internal to Apple.
6
1
3.4k
Oct ’23