Skip to content

fix: check vaild frist when relative_pos_range close #94#95

Merged
Unparalleled-Calvin merged 1 commit into
safer-rust:mainfrom
yihong0618:hy/check_vaild_first_for_relative_pos_range
Feb 17, 2025
Merged

fix: check vaild frist when relative_pos_range close #94#95
Unparalleled-Calvin merged 1 commit into
safer-rust:mainfrom
yihong0618:hy/check_vaild_first_for_relative_pos_range

Conversation

@yihong0618
Copy link
Copy Markdown
Contributor

as title, close #94

Signed-off-by: yihong0618 <zouzou0208@gmail.com>
@Unparalleled-Calvin
Copy link
Copy Markdown
Contributor

Hi, yihong. Thank you for your contribution! The keyword unsafe is used here to notice users that there might be potential issues when using this API including:

  • The two spans may come from different source files which makes the result meaningless.
  • The overflow issues.

We can write code to check both issues and ensure that the program won't crash. However, the bugs from the caller function won't be detected. Considering that the bugs are conner cases, I think adding a visible notice will make sense?

@yihong0618
Copy link
Copy Markdown
Contributor Author

yihong0618 commented Jan 17, 2025

Hi, yihong. Thank you for your contribution! The keyword unsafe is used here to notice users that there might be potential issues when using this API including:

  • The two spans may come from different source files which makes the result meaningless.
  • The overflow issues.

We can write code to check both issues and ensure that the program won't crash. However, the bugs from the caller function won't be detected. Considering that the bugs are conner cases, I think adding a visible notice will make sense?

Hi thank you for the comments

IMO for this kind of error the better way is do not panic and stop the world?
a warning message and drop the unsafe maybe better?


can you try using RAPX for greptime, the error happens every time when using -ops for greptime, maybe there is a better solution for this issue

@Unparalleled-Calvin
Copy link
Copy Markdown
Contributor

Hi yihong. I have checked the code and figured out the reason that caused this bug. In short, the sub_span passed into the function locates at a macro code block which is outside the span.

An example:

macro_rules! foo{
    ... // the sub_span locates at here
}

fn bar() { // span
    foo!(...) // unfolded while compiling
}

Then the previous code computes relative_pos_range(span, sub_span) which causes an overflow bug.

Thank you for your contribution!

@yihong0618
Copy link
Copy Markdown
Contributor Author

Hi yihong. I have checked the code and figured out the reason that caused this bug. In short, the sub_span passed into the function locates at a macro code block which is outside the span.

An example:

macro_rules! foo{
    ... // the sub_span locates at here
}

fn bar() { // span
    foo!(...) // unfolded while compiling
}

Then the previous code computes relative_pos_range(span, sub_span) which causes an overflow bug.

Thank you for your contribution!

Thank you for the info, learned that

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.

failed to check some repos error byte index 4294800896 is out of bounds

2 participants