Simple regular expression substitution crashes on Windows using regex-compat

匆匆过客 提交于 2021-02-08 03:44:26

问题


The following code crashes when using GHC on Windows. It works perfectly on Linux.

Does this make any sense or is there a bug?

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 ""

Some additional details

  1. I'm building with stack
  2. It crashes in both GHCi and running the compiled executable
  3. I tried to enable profiling but can't seem to figure out how to get that to work correctly.

回答1:


Shuffling the regex around avoids the bug in this case.

This works fine for me now

let re = Re.mkRegexWithOpts "(jul|aug|sep|oct|jun|nov|dec)" True False in 

I.e. moving the jun towards the end of the regex. Not particularly satisfactory but it works and it means I can continue.

@Zeta's comment suggest that this is a bug with the underlying library

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.



来源:https://stackoverflow.com/questions/39047317/simple-regular-expression-substitution-crashes-on-windows-using-regex-compat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!