Skip to content

[stdlib] fixes warning: result of call to 'initialize(from:)' is unused #21527

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

Merged

Conversation

nordicio
Copy link
Contributor

@nordicio nordicio commented Dec 22, 2018

Fixes the following warnings:

+ /usr/local/bin/cmake --build <swift-source>/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64 -- -j4 all swift-test-stdlib-macosx-x86_64 swift-benchmark-macosx-x86_64
[966/1642] Generating <swift-source>/swift/macosx/x86_64/Swift.swiftmodule
<swift-source>/swift/stdlib/public/core/StringStorage.swift:81:14: warning: result of call to 'initialize(from:)' is unused
      buffer.initialize(from: UnsafeBufferPointer(start: start, count: count))
             ^         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

and

[1063/1642] Compiling <swift-source>/swift/stdlib/public/core/macosx/x86_64/Swift.o
<swift-source>/swift/stdlib/public/core/StringStorage.swift:81:14: warning: result of call to 'initialize(from:)' is unused
      buffer.initialize(from: UnsafeBufferPointer(start: start, count: count))
             ^         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The bounds check seems alright, so it's just removing the warning.

@harlanhaskins
Copy link
Contributor

@swift-ci please smoke test

cc: @milseman

UnsafeMutableBufferPointer(start: outputPtr, count: maxLength)
buffer.initialize(from: UnsafeBufferPointer(start: start, count: count))
let buffer = UnsafeMutableBufferPointer(start: outputPtr, count: maxLength)
_ = buffer.initialize(from: UnsafeBufferPointer(start: start, count: count))
Copy link
Contributor

@Azoy Azoy Dec 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc: @milseman @Catfish-Man can this be rewritten as:

guard maxLength >= count + 1 else { return 0 }
outputPtr.initialize(from: start, count: count)
outputPtr[count] = 0
return 1

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I strongly suspect it can! Good catch

@Catfish-Man
Copy link
Contributor

@swift-ci please test

@harlanhaskins
Copy link
Contributor

Thanks for this, @nordicio!

@harlanhaskins harlanhaskins merged commit b29f1ee into swiftlang:master Jan 3, 2019
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

Successfully merging this pull request may close these issues.

4 participants