Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: use of assert prevents code from being executed when optimization is turned on #55

Closed
foobarzap opened this issue May 6, 2018 · 1 comment
Labels
bug Something isn't working
Projects

Comments

@foobarzap
Copy link

In utilities.swift:

  internal mutating func skip(_ n: Int) {
        guard n < count else {
            self = Data()
            return
        }
        for _ in 0..<n {
            // -> popFirst() doesn't get executed if optimization is turned on!
            assert(popFirst() != nil)
        }
    }

Possible fix:

  internal mutating func skip(_ n: Int) {
        guard n < count else {
            self = Data()
            return
        }
        for _ in 0..<n {           
            let check = popFirst()
            assert(check != nil)
        }
    }

Another place where assert prevents a possibly intended side effect to occur:

In PostgreSQLData+Point:

   case .point:
            switch data.format {
            case .text:
                let string = try value.makeString()
                let parts = string.split(separator: ",")
                var x = parts[0]
                var y = parts[1]
                // -> popFirst() and popLast() will only be executed when optimization is turned off
                assert(x.popFirst()! == "(")
                assert(y.popLast()! == ")")
                return .init(x: Double(x)!, y: Double(y)!)
@tanner0101 tanner0101 added the bug Something isn't working label May 7, 2018
@tanner0101
Copy link
Member

Ah yeah, that is no good. Thanks for catching. I will make sure all instances of that get fixed before official release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Vapor 3
  
Awaiting triage
Development

No branches or pull requests

2 participants