{"id":115415,"date":"2023-11-03T10:30:55","date_gmt":"2023-11-03T01:30:55","guid":{"rendered":"https:\/\/softantenna.com\/blog\/?p=115415"},"modified":"2023-11-03T10:30:55","modified_gmt":"2023-11-03T01:30:55","slug":"macos-sonoma-broke-grep","status":"publish","type":"post","link":"https:\/\/softantenna.com\/blog\/macos-sonoma-broke-grep\/","title":{"rendered":"\u3010\u60b2\u5831\u3011macOS Sonoma\u3067\u300cgrep\u300d\u304c\u58ca\u308c\u308b"},"content":{"rendered":"<p><img decoding=\"async\" style=\"display:block; margin-left:auto; margin-right:auto;\" src=\"https:\/\/softantenna.com\/blog\/wp-content\/uploads\/2023\/11\/s_20231103_101046.jpg\" alt=\"S 20231103 101046\" title=\"s_20231103_101046.jpg\" border=\"0\" width=\"860\" height=\"560\" \/><\/p>\n<p>\u6700\u65b0\u7248\u306emacOS\u3001\u300cmacOS Sonoma\u300d\u3067grep\u30b3\u30de\u30f3\u30c9\u304c\u58ca\u308c\u3066\u3044\u308b\u4e8b\u304c\u308f\u304b\u308a\u307e\u3057\u305f(<a href=\"https:\/\/news.ycombinator.com\/item?id=38104554\">Hacker News<\/a>)\u3002<\/p>\n<p>Apple\u306e<a href=\"https:\/\/developer.apple.com\/forums\/thread\/738862\">\u958b\u767a\u8005\u5411\u3051\u30d5\u30a9\u30fc\u30e9\u30e0<\/a>\u306b\u6295\u7a3f\u3055\u308c\u305f\u60c5\u5831\u306b\u3088\u308b\u3068\u3001\u4e00\u81f4\u7b87\u6240\u306e\u307f\u3092\u51fa\u529b\u3059\u308b\"-o\"\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u4ed8\u3051<code>grep -o<\/code>\u3092\u5b9f\u884c\u3057\u305f\u5834\u5408\u306b\u3001\u7279\u5b9a\u306e\u30d1\u30bf\u30fc\u30f3\u3067\u30a2\u30b5\u30fc\u30b7\u30e7\u30f3\u5931\u6557(assertion fails)\u304c\u767a\u751f\u3057\u3001abort\u3059\u308b\u6a21\u69d8\u3002<\/p>\n<pre>\nprintf '%s' '3.2.57(1)-release' | grep -o '[0-9.]*'\nAssertion failed: (advance > 0), function procline, file util.c, line 732.\nzsh: done       printf '%s' '3.2.57(1)-release' | \nzsh: abort      grep -o '[0-9.]*'\n<\/pre>\n<p>\u518d\u73fe\u53ef\u80fd\u306a\u6700\u5c0f\u30d1\u30bf\u30fc\u30f3\u3068\u3057\u3066<code>printf '%s' 'a' | grep -o 'b*'<\/code>\u304c\u63d0\u793a\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre>\n# fails\nprintf '%s' 'a' | grep -o 'b*'\n\n# works\nprintf '%s' 'a' | grep -o 'b'\n\n# also works (note: without -o flag)\nprintf '%s' 'a' | grep 'b*'\n<\/pre>\n<p>\u30a2\u30b5\u30fc\u30b7\u30e7\u30f3\u5931\u6557\u304c\u767a\u751f\u3057\u3066\u3044\u308b\u3001<a href=\"https:\/\/github.com\/apple-oss-distributions\/text_cmds\/blob\/c0780aa3432383e0acde7dc7cf42972716925de6\/grep\/util.c#L732\">\u8a72\u5f53\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/a>\u3082\u63a2\u3057\u51fa\u3055\u308c\u3066\u3044\u3066\u3001\u5225\u306e\u4e0d\u5177\u5408\u306b\u5bfe\u51e6\u3059\u308b\u305f\u3081\u306b\u65b0\u305f\u306a\u30d0\u30b0\u304c\u5165\u3063\u305f\u306e\u3067\u306f\u306a\u3044\u304b\u3068\u6307\u6458\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-c\" data-lang=\"c\"><code><blockquote>\t\t\t\t\/*\n\t\t\t\t * rdar:\/\/problem\/86536080 - if our first match\n\t\t\t\t * was 0-length, we wouldn&apos;t progress past that\n\t\t\t\t * point.  Incrementing nst here ensures that if\n\t\t\t\t * no other pattern matches, we&apos;ll restart the\n\t\t\t\t * search at one past the 0-length match and\n\t\t\t\t * either make progress or end the search.\n\t\t\t\t *\/\n\t\t\t\tif (pmatch.rm_so == pmatch.rm_eo) {\n\t\t\t\t\tif (MB_CUR_MAX &gt; 1) {\n\t\t\t\t\t\twchar_t wc;\n\t\t\t\t\t\tint advance;\n\n\t\t\t\t\t\tadvance = mbtowc(&amp;wc,\n\t\t\t\t\t\t    &amp;pc-&gt;ln.dat[nst],\n\t\t\t\t\t\t    MB_CUR_MAX);\n\n\t\t\t\t\t\tassert(advance &gt; 0);\n\t\t\t\t\t\tnst += advance;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnst++;\n\t\t\t\t\t}\n\t\t\t\t}\n<\/blockquote><\/code><\/pre>\n<\/div>\n<p><a href=\"https:\/\/news.ycombinator.com\/item?id=38104554\">Hacker News<\/a>\u3067\u306f\u3001macOS\u306eBSD\u30e6\u30fc\u30b6\u30fc\u30e9\u30f3\u30c9\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u306f\u8d85\u6642\u4ee3\u9045\u308c\u3067\u3042\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3068\u306e\u6307\u6458\u3082\u884c\u308f\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u65b0\u7248\u306emacOS\u3001\u300cmacOS Sonoma\u300d\u3067grep\u30b3\u30de\u30f3\u30c9\u304c\u58ca\u308c\u3066\u3044\u308b\u4e8b\u304c\u308f\u304b\u308a\u307e\u3057\u305f(Hacker News)\u3002 Apple\u306e\u958b\u767a\u8005\u5411\u3051\u30d5\u30a9\u30fc\u30e9\u30e0\u306b\u6295\u7a3f\u3055\u308c\u305f\u60c5\u5831\u306b\u3088\u308b\u3068\u3001\u4e00\u81f4\u7b87\u6240\u306e\u307f\u3092\u51fa\u529b\u3059\u308b\"-o\"\u30aa\u30d7\u30b7\u30e7 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":115416,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","footnotes":""},"categories":[4],"tags":[3480],"class_list":["post-115415","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mac","tag-macos"],"_links":{"self":[{"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/posts\/115415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/comments?post=115415"}],"version-history":[{"count":0,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/posts\/115415\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/media\/115416"}],"wp:attachment":[{"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/media?parent=115415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/categories?post=115415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/tags?post=115415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}