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

[SR-1378] String with format initializer crashes when using repeated positional arguments #43987

Closed
swift-ci opened this issue May 1, 2016 · 8 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software good first issue Good for newcomers run-time crash Bug → crash: Swift code crashed during execution SDKOverlay standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented May 1, 2016

Previous ID SR-1378
Radar rdar://26051182
Original Reporter pol (JIRA User)
Type Bug
Status Closed
Resolution Won't Do
Environment

Xcode Playground Version 7.3 (7D175)

Additional Detail from JIRA
Votes 1
Component/s Standard Library
Labels Bug, RunTimeCrash, SDKOverlay, StarterBug
Assignee @rsfinn
Priority Medium

md5: 2e6524377155b4334bb8be3466516cc5

Issue Description:

This:
print(String(format: "%2$@ %1$@ %2$@", "bar", "foo"))
crashes with EXC_BAD_INSTRUCTION

while NSString:
print(NSString(format: "%2$@ %1$@ %2$@", "bar", "foo"))
prints "foo bar foo" as expected

Also note that adding an extra argument:
print(String(format: "%2$@ %1$@ %2$@", "bar", "foo", "dummy")
does not crash and prints "foo bar foo"

@belkadan
Copy link
Contributor

belkadan commented May 2, 2016

Interesting. @gparker42, any ideas?

@rsfinn
Copy link

rsfinn commented May 3, 2016

I came here to report a very similar issue; this code:

@gparker42
Copy link
Mannequin

gparker42 mannequin commented May 4, 2016

I think this is the fault of
{{
_precondition(
_countFormatSpecifiers(format) <= arguments.count,
"Too many format specifiers (%<letter>) provided for the argument list"
)
}}

_countFormatSpecifiers() doesn't account for the possibility of positional arguments.

@belkadan
Copy link
Contributor

belkadan commented May 4, 2016

Oh, good call. I guess we should drop or fix that. @gribozavr, any objections?

@gribozavr
Copy link
Collaborator

I'd prefer we fix the counting.

@rsfinn
Copy link

rsfinn commented Jul 16, 2016

I'm submitting a pull request with a more extensive rewrite of _countFormatSpecifiers(_:) that I believe handles both positional specifiers and the usual case.

PR: #3555

@rsfinn
Copy link

rsfinn commented Jul 23, 2016

Bump: @gribozavr, I submitted a pull request last weekend that offered a more comprehensive solution that the one offered by another submitter (who has since withdrawn his). Is there any additional information I can provide?

@rsfinn
Copy link

rsfinn commented Apr 25, 2017

Superseded by pull request #3917 which removed the checking <https://github.com/apple/swift/pull/3917\>

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software good first issue Good for newcomers run-time crash Bug → crash: Swift code crashed during execution SDKOverlay standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

5 participants