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

Improve unsafe code in GTK clipboard code #1820

Merged
merged 4 commits into from
Jun 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ You can find its changes [documented below](#070---2021-01-01).
- `Notification`s will not be delivered to the widget that sends them ([#1640] by [@cmyr])
- `TextBox` can handle standard keyboard shortcuts without needing menus ([#1660] by [@cmyr])
- GTK Shell: Prevent mangling of newline characters in clipboard ([#1695] by [@ForLoveOfCats])
- GTK: Replaced call to `std::str::from_utf8_unchecked` with `from_utf8` ([#1820] by [@psychon])
- Use correct fill rule when rendering SVG paths ([#1606] by [@SecondFlight])
- Correctly capture and use stroke properties when rendering SVG paths ([#1647] by [@SecondFlight])
- focus-chain now only includes non hidden (`should_propagate_to_hidden()` on `Event` and `Lifecylce`) widgets ([#1724] by [@xarvic])
Expand Down Expand Up @@ -726,6 +727,7 @@ Last release without a changelog :(
[#1772]: https://github.com/linebender/druid/pull/1772
[#1787]: https://github.com/linebender/druid/pull/1787
[#1802]: https://github.com/linebender/druid/pull/1802
[#1820]: https://github.com/linebender/druid/pull/1820

[Unreleased]: https://github.com/linebender/druid/compare/v0.7.0...master
[0.7.0]: https://github.com/linebender/druid/compare/v0.6.0...v0.7.0
Expand Down
9 changes: 6 additions & 3 deletions druid-shell/src/platform/gtk/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ impl Clipboard {
let idx = idx as usize;
if idx < formats.len() {
let item = &formats[idx];
if item.identifier == ClipboardFormat::TEXT {
sel.set_text(unsafe { std::str::from_utf8_unchecked(&item.data) });
if let (ClipboardFormat::TEXT, Ok(data)) =
(item.identifier, std::str::from_utf8(&item.data))
{
sel.set_text(data);
} else {
let atom = Atom::intern(item.identifier);
let stride = 8;
Expand Down Expand Up @@ -130,7 +132,8 @@ impl Clipboard {
let targets = clipboard.wait_for_targets().unwrap_or_default();
targets
.iter()
.map(|atom| unsafe { format!("{} ({})", atom.name(), atom.value()) })
// SAFETY: Atom::value() is 'self.0 as usize'. No idea why that is unsafe.
.map(|atom| format!("{} ({})", atom.name(), unsafe { atom.value() }))
.collect()
}
}
Expand Down