Skip to content

Add misc safe rules - #264

Merged
nunoplopes merged 8 commits into
Cpp2Rust:masterfrom
lucic71:misc-safe-rules
Jul 18, 2026
Merged

Add misc safe rules#264
nunoplopes merged 8 commits into
Cpp2Rust:masterfrom
lucic71:misc-safe-rules

Conversation

@lucic71

@lucic71 lucic71 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread rules/pwd/tgt_refcount.rs Outdated
fn f1(a0: u32) -> Ptr<Passwd> {
match nix::unistd::User::from_uid(nix::unistd::Uid::from_raw(a0)) {
Ok(Some(__u)) => Ptr::alloc(Passwd::from_user(&__u)),
_ => Ptr::null(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

needs to set errno

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

use libcc2rs::*;

fn f1(a0: i32, a1: Ptr<u8>) -> Ptr<u8> {
Ptr::from_string_literal(b"C")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is not correct for sure :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Rust does not seem to have support for localization

The man page of setlocale says:

       A successful call to setlocale() returns an opaque string that
       corresponds to the locale set.  This string may be allocated in
       static storage.  The string returned is such that a subsequent
       call with that string and its associated category will restore
       that part of the process's locale.  The return value is NULL if
       the request cannot be honored.

So the real options here are to return C (The locale "C" or "POSIX" is a portable locale; it exists on all conforming systems.) or NULL. NULL looks more like a failure, so I chose "C" instead.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We probably need to track the locale ourselves and change the behavior of relevant string functions then

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added a TODO about that

@lucic71
lucic71 requested a review from nunoplopes July 18, 2026 12:53
@nunoplopes
nunoplopes merged commit 5ed6982 into Cpp2Rust:master Jul 18, 2026
9 checks passed
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.

2 participants