Bug 17157 – ctRegex.matchAll doesn't set last item in Captures

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-02-08T09:41:45Z
Last change time
2018-01-05T13:27:41Z
Keywords
pull
Assigned to
No Owner
Creator
Alexey Kulentsov

Comments

Comment #0 by crimaniak — 2017-02-08T09:41:45Z
Reproduce code: int main() { import std.stdio; import std.regex; // auto r = ctRegex!"(a)|(b)|(c)|(d)"; /* // <- uncomment to switch to ctRegex auto r = regex("(a)|(b)|(c)|(d)"); //*/ auto s = "--a--b--c--d--"; foreach(match; s.matchAll(r)) { foreach(i; 0..match.length) write(i,":",match[i]," "); writeln(); } return 0; } if line 6 commented and regex() is used then output is correct: 0:a 1:a 2: 3: 4: 0:b 1: 2:b 3: 4: 0:c 1: 2: 3:c 4: 0:d 1: 2: 3: 4:d if comment at line 6 beginning is removed and ctRegex is used then we have exception: core.exception.AssertError@/usr/include/dmd/phobos/std/regex/package.d(565): wrong match: 1..0 ---------------- ??:? _d_assert_msg [0x4edba6] ??:? std.regex.Captures!(immutable(char)[], ulong).Captures.opIndex!().opIndexinout(pure nothrow @trusted inout(immutable(char)[]) function(ulong)) [0x4e4f01] ??:? _Dmain [0x4bb73e] ??:? _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv [0x4ef333] ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x4ef25b] ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() [0x4ef2d8] ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x4ef25b] ??:? _d_run_main [0x4ef1c7] ??:? main [0x4eae0f] ??:? __libc_start_main [0xc012282f] More experiments have shown: last element of match is not set and attempt to access it leads to exception. Compiler: DMD64 D Compiler v2.073.0 OS: Ubuntu 16.04 LTS
Comment #1 by dmitry.olsh — 2017-03-08T13:48:03Z
(In reply to Alexey Kulentsov from comment #0) > if comment at line 6 beginning is removed and ctRegex is used then we have > exception: > > core.exception.AssertError@/usr/include/dmd/phobos/std/regex/package.d(565): > wrong match: 1..0 > ---------------- > ??:? _d_assert_msg [0x4edba6] > ??:? std.regex.Captures!(immutable(char)[], > ulong).Captures.opIndex!().opIndexinout(pure nothrow @trusted > inout(immutable(char)[]) function(ulong)) [0x4e4f01] > ??:? _Dmain [0x4bb73e] > ??:? _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv > [0x4ef333] > ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int > function(char[][])*).tryExec(scope void delegate()) [0x4ef25b] > ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int > function(char[][])*).runAll() [0x4ef2d8] > ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int > function(char[][])*).tryExec(scope void delegate()) [0x4ef25b] > ??:? _d_run_main [0x4ef1c7] > ??:? main [0x4eae0f] > ??:? __libc_start_main [0xc012282f] > > More experiments have shown: last element of match is not set and attempt to > access it leads to exception. > > Compiler: DMD64 D Compiler v2.073.0 > OS: Ubuntu 16.04 LTS Trying to reproduce with latest master (2.074~alpha) I see no exception but the output of 2 runs differs. With regex correctly: 0:a 1:a 2: 3: 4: 0:b 1: 2:b 3: 4: 0:c 1: 2: 3:c 4: 0:d 1: 2: 3: 4:d With ctRegex: 0:a 1:a 2: 3: 4: 0:b 1:a 2:b 3: 4: 0:c 1:a 2: 3:c 4: 0:d 1:a 2: 3: 4:d Investigating...
Comment #2 by dmitry.olsh — 2017-03-08T16:12:58Z
Comment #3 by github-bugzilla — 2017-03-09T21:57:49Z
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/0e76847361ef8005f080f2cd57a111f563dc97a9 Fix issue 17157 ctRegex.matchAll doesn't set last item in Captures https://github.com/dlang/phobos/commit/7200b368056f99dcea9c11ba68a50f89d05348fa Merge pull request #5250 from DmitryOlshansky/isssue-17157 Fix issue 17157 ctRegex.matchAll doesn't set last item in Captures
Comment #4 by github-bugzilla — 2017-03-22T12:05:24Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/0e76847361ef8005f080f2cd57a111f563dc97a9 Fix issue 17157 ctRegex.matchAll doesn't set last item in Captures https://github.com/dlang/phobos/commit/7200b368056f99dcea9c11ba68a50f89d05348fa Merge pull request #5250 from DmitryOlshansky/isssue-17157
Comment #5 by github-bugzilla — 2017-08-07T12:26:22Z
Commits pushed to newCTFE at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/0e76847361ef8005f080f2cd57a111f563dc97a9 Fix issue 17157 ctRegex.matchAll doesn't set last item in Captures https://github.com/dlang/phobos/commit/7200b368056f99dcea9c11ba68a50f89d05348fa Merge pull request #5250 from DmitryOlshansky/isssue-17157
Comment #6 by github-bugzilla — 2018-01-05T13:27:41Z
Commits pushed to dmd-cxx at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/0e76847361ef8005f080f2cd57a111f563dc97a9 Fix issue 17157 ctRegex.matchAll doesn't set last item in Captures https://github.com/dlang/phobos/commit/7200b368056f99dcea9c11ba68a50f89d05348fa Merge pull request #5250 from DmitryOlshansky/isssue-17157