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

修复 ch3 examples/plotTrajectory.cpp vector越界访问BUG #231

Closed
wants to merge 1 commit into from
Closed

Conversation

fseasy
Copy link

@fseasy fseasy commented Mar 27, 2022

在ch3的 examples/plotTrajectory.cpp82 行:

    for (size_t i = 0; i < poses.size(); i++) {
      ...
      auto p1 = poses[i], p2 = poses[i + 1];
      ...
     }

对最后一个元素(i == poses.size() - 1U)迭代,用[i + 1]访问显然越界了,只是因为 []操作符不检查range,且恰巧内存正常,所以程序没有崩溃。
对此,稍微修改了一点点,避免越界。

PS: 斗胆说下,一般建议用 .at(idx) 来做vector的访问,其显式做out_of_range的检查,可以避免很多因为越界访问导致的core-dump. 这里未做修改,保持代码风格一致。

@fseasy fseasy changed the title f修复 ch3 examples/plotTrajectory.cpp vector越界访问BUG 修复 ch3 examples/plotTrajectory.cpp vector越界访问BUG Mar 27, 2022
@fseasy
Copy link
Author

fseasy commented Mar 27, 2022

才发现 #113 已经有此提交。 关闭了。

@fseasy fseasy closed this Mar 27, 2022
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