Skip to content

Commit

Permalink
Makes failure more clear at UTF-8 decoding error (#1564)
Browse files Browse the repository at this point in the history
Signed-off-by: Yauheni Khnykin <[email protected]>
  • Loading branch information
Hsilgos authored Jan 2, 2024
1 parent c060a81 commit a43bfa6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Gluecodium project Release Notes

## Unreleased
## 13.7.3
### Features:
* Swift crashes with more clear error in case when UTF-8 string can't be decoded.

## 13.7.2
Release date: 2023-10-25
### Bug fixes:
Expand Down
9 changes: 7 additions & 2 deletions gluecodium/src/main/resources/swift/BuiltinConversions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ extension String {
// String

internal func copyFromCType(_ handle: _baseRef) -> String {
return String(data: Data(bytes: std_string_data_get(handle),
count: Int(std_string_size_get(handle))), encoding: .utf8)!
if let convertedString = String(data: Data(bytes: std_string_data_get(handle),
count: Int(std_string_size_get(handle))),
encoding: .utf8) {
return convertedString
}

fatalError("Failed to decode character buffer as UTF-8 string")
}

internal func moveFromCType(_ handle: _baseRef) -> String {
Expand Down

0 comments on commit a43bfa6

Please sign in to comment.