使用 regex-compat 的简单正则表达式替换在 Windows 上崩溃
Simple regular expression substitution crashes on Windows using regex-compat
以下代码在 Windows 上使用 GHC 时崩溃。它在 Linux 上完美运行。
这是否有意义或是否存在错误?
module Main where
import qualified Text.Regex as Re -- from regex-compat
import Debug.Trace
main :: IO ()
main = do
putStr $ cleanWord "jan"
putStr $ cleanWord "dec"
putStr $ cleanWord "jun" -- crashes here
cleanWord :: String -> String
cleanWord word_ =
let word = trace (show word_) word_ in
let re = Re.mkRegexWithOpts "(jun|jul|aug|sep|oct|nov|dec)" True False in
Re.subRegex re word ""
一些额外的细节
- 我正在使用
stack
构建
- 它在 GHCi 和 运行 已编译的可执行文件中崩溃
- 我尝试启用分析,但似乎无法弄清楚如何让它正常工作。
改组正则表达式避免了这种情况下的错误。
现在这对我来说很好
let re = Re.mkRegexWithOpts "(jul|aug|sep|oct|jun|nov|dec)" True False in
即将 jun
移到正则表达式的末尾。不是特别令人满意,但它有效,这意味着我可以继续。
@Zeta 的评论表明这是底层库的错误
It's a bug, probably in regex-posix, due to its difference in the
inclusion of the underlying BSD regex library from 1994. In sslow, an
invalid memory address (-1(%rdx) with rdx = 0) will be accessed.
以下代码在 Windows 上使用 GHC 时崩溃。它在 Linux 上完美运行。
这是否有意义或是否存在错误?
module Main where
import qualified Text.Regex as Re -- from regex-compat
import Debug.Trace
main :: IO ()
main = do
putStr $ cleanWord "jan"
putStr $ cleanWord "dec"
putStr $ cleanWord "jun" -- crashes here
cleanWord :: String -> String
cleanWord word_ =
let word = trace (show word_) word_ in
let re = Re.mkRegexWithOpts "(jun|jul|aug|sep|oct|nov|dec)" True False in
Re.subRegex re word ""
一些额外的细节
- 我正在使用
stack
构建
- 它在 GHCi 和 运行 已编译的可执行文件中崩溃
- 我尝试启用分析,但似乎无法弄清楚如何让它正常工作。
改组正则表达式避免了这种情况下的错误。
现在这对我来说很好
let re = Re.mkRegexWithOpts "(jul|aug|sep|oct|jun|nov|dec)" True False in
即将 jun
移到正则表达式的末尾。不是特别令人满意,但它有效,这意味着我可以继续。
@Zeta 的评论表明这是底层库的错误
It's a bug, probably in regex-posix, due to its difference in the inclusion of the underlying BSD regex library from 1994. In sslow, an invalid memory address (-1(%rdx) with rdx = 0) will be accessed.