[swift-corelibs-dev] [swift-users] DateFormatter crash on second usage (new instance) on Linux (swift 3.0.1)

Will Stanton willstanton1 at yahoo.com
Wed Jan 25 20:11:08 CST 2017


Based on the backtrace, I think the code is running into a memory issue with Swift Foundation:
https://bugs.swift.org/browse/SR-2485
https://bugs.swift.org/browse/SR-2462

I haven’t seen this in a while - are you able to try running on Swift 3.1 or 3.0.2?
Your code seems to work on the IBM Sandbox with 3.0.2 but not 3.0.1.
You could also try replacing every 'let’ with ‘var’ but that might not be the right solution :-)

Regards,
Will Stanton

> On Jan 25, 2017, at 5:04 PM, Dennis Schafroth via swift-users <swift-users at swift.org> wrote:
> 
> Hi
> 
> Trying to do some simple date parsing from syslog format (“Jan 25 20:21:22”) into Date. Seem to work once but crashes on second call
> 
> 
> func dateConv(_ dateString: String) -> Date? {
>   let dateFormatter = DateFormatter()
>   dateFormatter.dateFormat = "MMM dd HH:mm"
>   dateFormatter.locale = Locale(identifier: "da_DK_POSIX")
>   if let date = dateFormatter.date(from: dateString) {
>     print("Real date: \(date)" )
>     return date
>   }
>   return nil
> }
> 
> var date  = dateConv("Jan 25 20:10")
> var date2 = dateConv("Jan 25 20:11”)
> 
> # swift main.swift
> Real date: 2000-01-25 19:10:00 +0000
> 0  swift            0x000000000334ab78 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
> 1  swift            0x0000000003349346 llvm::sys::RunSignalHandlers() + 54
> 2  swift            0x000000000334b6aa
> 3  libpthread.so.0  0x00007fec92166890
> 4  libswiftCore.so  0x00007fec8e8f0735
> 5  libFoundation.so 0x00007fec8c0ab6ee
> 6  libFoundation.so 0x00007fec8bd7a222
> 7  libFoundation.so 0x00007fec8bd7c623
> 8  libFoundation.so 0x00007fec8bf0e873 _TFC10Foundation6NSDateg11descriptionSS + 99
> 9  libFoundation.so 0x00007fec8c182829 _TTWV10Foundation4Dates23CustomStringConvertibleS_FS1_g11descriptionSS + 57
> 10 libswiftCore.so  0x00007fec8e78c745 _TFs15_print_unlockedu0_R_s16TextOutputStreamrFTxRq__T_ + 997
> 
> using swift 3.0.1. Am I doing something wrong? I seems to work on macOS.
> 
> cheers,
> :-Dennis



More information about the swift-corelibs-dev mailing list