- Notifications
You must be signed in to change notification settings - Fork 15
Fixed bug in EventProvider (Some configuration file have leading whitespaces: closes #8) #9
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
Conversation
…espaces that need to be removed when parsing)
WalkthroughTrimmed input strings in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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: 1
🧹 Nitpick comments (2)
src/event_provider.cpp (2)
336-337: LGTM! Consider applying this pattern to similar code.The whitespace trimming approach correctly addresses the issue with leading/trailing whitespace in configuration files. The use of
unsigned charin the lambda avoids undefined behavior withstd::isspacefor characters with negative values.However, lines 220-221 use
::isspacedirectly without the saferunsigned charcast pattern. Consider updating them to match this implementation:key.erase(std::remove_if(key.begin(), key.end(), [](unsigned char c){return std::isspace(c);}), key.end()); value.erase(std::remove_if(value.begin(), value.end(), [](unsigned char c){return std::isspace(c);}), value.end());
344-350: Add exception handling for robustness.
std::stoullcan throwstd::out_of_rangeif the number exceedsUINT64_MAX. While unlikely with system-generated configuration files, adding exception handling would make the function more consistent with itsstd::optionalreturn type contract, which implies graceful failure handling.Consider wrapping the
std::stoullcalls in try-catch blocks:/// Strings starting with '0x' are considered hex numbers. if (copied_str.rfind("0x", 0ULL) == 0ULL) { - return std::stoull(copied_str.substr(2ULL), nullptr, 16); + try { + return std::stoull(copied_str.substr(2ULL), nullptr, 16); + } catch (const std::out_of_range&) { + return std::nullopt; + } } /// Strings containing digits are considered dec numbers. if (std::all_of(copied_str.begin(), copied_str.end(), [](const auto c) { return std::isdigit(c); })) { - return std::stoull(copied_str, nullptr, 0); + try { + return std::stoull(copied_str, nullptr, 0); + } catch (const std::out_of_range&) { + return std::nullopt; + } }
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: 0
🧹 Nitpick comments (1)
src/event_provider.cpp (1)
335-353: Whitespace trimming correctly fixes the reported bug.The approach of creating a trimmed copy and using it for all parsing operations is sound and resolves the issue with leading whitespace in configuration files.
However, for consistency and maximum safety, consider using
unsigned charin the lambda at line 348, matching line 336:Apply this diff for type consistency:
- if (std::all_of(copied_str.begin(), copied_str.end(), [](const auto c) { return std::isdigit(c); })) { + if (std::all_of(copied_str.begin(), copied_str.end(), [](unsigned char c) { return std::isdigit(c); })) {This ensures both lambdas follow the same pattern and avoids potential undefined behavior with
std::isdigiton platforms wherecharis signed.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/event_provider.cpp(4 hunks)
🔇 Additional comments (2)
src/event_provider.cpp (2)
13-13: LGTM: Include addition is correct.The
<cctype>include is necessary forstd::isspaceandstd::isdigitused in theparse_integerfunction.
489-490: LGTM: Formatting change has no semantic impact.
| Thanks for the bugfix. I will add it to the |
Summary by CodeRabbit
Bug Fixes
Chores