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

Fix dangling pointer warnings in consume() for Swift 5.2+ #1

Open
tscholze opened this issue May 8, 2020 · 1 comment
Open

Fix dangling pointer warnings in consume() for Swift 5.2+ #1

tscholze opened this issue May 8, 2020 · 1 comment
Assignees

Comments

@tscholze
Copy link
Member

tscholze commented May 8, 2020

Possible fix approved by @mredlin

 /// Consume bytes from stream, return unpacked file
    ///
    /// - parameter data: data to consume
    ///
    /// - throws: TarFile.Errors
    ///
    /// - returns: tuple with filename and data on completion of a single file
    open func consume(data: [CChar]) throws -> (filename: String, data: Data)? {
        if !self.streamingMode {
            throw Errors.programmingError
        }

        return try self.buffer.withUnsafeBufferPointer { bufferPointer in
            guard let pointer = bufferPointer.baseAddress else {
                throw Errors.programmingError
            }

            if bufferPointer.count > 512 {
                let header = try self.parse(header: pointer)

                let endOffset = 512 + (header.filesize + (512 - header.filesize % 512))
                if bufferPointer.count > endOffset {
                    let data = Data(bytes: pointer.advanced(by: 512), count: header.filesize)
                    self.buffer.removeFirst(endOffset)

                    if header.isFile {
                        return (filename: header.filepath, data:data)
                    }
                }
            }
            return nil
        }
    }
@dunkelstern
Copy link
Member

I am not up to date on recent swift changes, taking myself out of assignees

@dunkelstern dunkelstern removed their assignment May 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants