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

The scope of the unsafe block can be appropriately reduced #126

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

peamaeq
Copy link

@peamaeq peamaeq commented May 18, 2022

In this function you use the unsafe keyword for almost the entrie function body. However, I found that only 5 functions are real unsafe operations (see the list below).

We need to mark unsafe operations more precisely using unsafe keyword. Keeping unsafe blocks small can bring many benefits. For example, when mistakes happen, we can locate any errors related to memory safety within an unsafe block. This is the balance between Safe and Unsafe Rust. The separation is designed to make using Safe Rust as ergonomic as possible, but requires extra effort and care when writing Unsafe Rust.
Real unsafe operation list:

  1. the GetConsoleMode()/FillConsoleOutputCharacterA()/FillConsoleOutputAttribute()/SetConsoleCursorPosition()/
    SetConsoleCursorInfo() function(these are unsafe functions)

Hope this PR can help you.
Best regards.
References
https://doc.rust-lang.org/nomicon/safe-unsafe-meaning.html
https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html

benesch pushed a commit to benesch/console that referenced this pull request Dec 4, 2022
…onsole-rs#126)

I was working on a lost waker lint, and noticed that the "coma" task
wasn't being linted, because it never sends another stats update. This
fixes it to lint tasks when we first get them, too.
benesch pushed a commit to benesch/console that referenced this pull request Dec 4, 2022
This lint will warn when a task that isn't completed has no more wakers,
implying the task will never wake up again.

Note that this depends on console-rs#126 in most cases.

![image](https://user-images.githubusercontent.com/2796466/132753053-2a8e18be-3251-41c3-92e5-1e0d0939b369.png)
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.

1 participant