-
Notifications
You must be signed in to change notification settings - Fork 0
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
Fix strlen usage #10
Fix strlen usage #10
Conversation
Warning Rate limit exceeded@kimkulling has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 20 minutes and 3 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
WalkthroughThe pull request introduces changes to the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/backends/sdl2_renderer.cpp (1)
Line range hint
201-203
: Consider modernizing other string length calculationsSince we're modernizing string handling, consider updating the
strlen
usage in text alignment calculation to use string_view or string length methods for consistency.Here's a suggested improvement:
- Message_rect.x = r.x1 + surfaceMessage->clip_rect.w - font->mSize * strlen(string); + const auto text_length = std::string_view(string).length(); + Message_rect.x = r.x1 + surfaceMessage->clip_rect.w - font->mSize * text_length;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/backends/sdl2_renderer.cpp
(4 hunks)
🧰 Additional context used
🪛 GitHub Check: SonarCloud
src/backends/sdl2_renderer.cpp
[warning] 77-77: std::string_view::data() should not be passed to API expecting C-style strings
Fix this function call that expects null-terminated strings but use string_view::data().See more on SonarQube Cloud
🪛 GitHub Actions: CMake
src/backends/sdl2_renderer.cpp
[error] 267-267: 'std__string' was not declared in this scope. The correct type name should be 'std::string' (with single underscore).
🔇 Additional comments (1)
src/backends/sdl2_renderer.cpp (1)
30-30
: LGTM! Good modernization of the code.The change to use
std::string_view
is a good improvement that:
- Provides a more efficient way to handle string views without copying
- Removes the need for explicit length management
- Aligns with modern C++ practices
Also applies to: 66-66
src/backends/sdl2_renderer.cpp
Outdated
@@ -267,7 +264,7 @@ | |||
return ErrorCode; | |||
} | |||
|
|||
const int driverIndex = queryDriver(ctx, "opengl", 256); | |||
const int driverIndex = queryDriver(ctx, std__string("opengl")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix typo in std::string
There's a typo in the type name: std__string
should be std::string
.
Apply this fix:
- const int driverIndex = queryDriver(ctx, std__string("opengl"));
+ const int driverIndex = queryDriver(ctx, std::string("opengl"));
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const int driverIndex = queryDriver(ctx, std__string("opengl")); | |
const int driverIndex = queryDriver(ctx, std::string("opengl")); |
🧰 Tools
🪛 GitHub Actions: CMake
[error] 267-267: 'std__string' was not declared in this scope. The correct type name should be 'std::string' (with single underscore).
src/backends/sdl2_renderer.cpp
Outdated
len = maxLen; | ||
} | ||
if (strncmp(driverType, info.name, len) == 0) { | ||
if (strncmp(driverType.data(), info.name, driverType.size()) == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix potential buffer overrun with string_view::data()
Using string_view::data()
with strncmp
is unsafe as it doesn't guarantee null-termination. This could lead to buffer overrun if the string_view points to a non-null-terminated string.
Consider these safer alternatives:
- if (strncmp(driverType.data(), info.name, driverType.size()) == 0) {
+ // Option 1: Convert to std::string to ensure null-termination
+ if (std::string(driverType) == info.name) {
+
+ // Option 2: Use string_view's compare if info.name length is known
+ if (driverType == std::string_view(info.name)) {
Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 GitHub Check: SonarCloud
[warning] 77-77: std::string_view::data() should not be passed to API expecting C-style strings
Fix this function call that expects null-terminated strings but use string_view::data().See more on SonarQube Cloud
|
Summary by CodeRabbit
std::string_view
for improved string handling