Fix setValue() using sizeof instead of strlen for char array arguments#417
Fix setValue() using sizeof instead of strlen for char array arguments#417
Conversation
Agent-Logs-Url: https://github.com/h2zero/NimBLE-Arduino/sessions/42ace199-2049-4c37-8f0a-30443045b8b2 Co-authored-by: h2zero <32826625+h2zero@users.noreply.github.com>
📝 WalkthroughWalkthroughModified Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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.
🧹 Nitpick comments (1)
src/NimBLEAttValue.h (1)
357-359: Minor inconsistency between the two code paths, savvy?Arr, the C++14 path at line 270 uses
sizeof(T), but this here C++17 path usessizeof(s). Both be givin' ye the same result fer a reference to an array, so this ain't causin' any scurvy bugs. But fer the sake of keepin' yer code shipshape and consistent across both paths, ye might consider usin'sizeof(T)here as well.🏴☠️ Proposed fix for consistency
} else if constexpr (std::is_array<T>::value && std::is_same<typename std::remove_extent<T>::type, char>::value) { - return setValue(reinterpret_cast<const uint8_t*>(s), strnlen(s, sizeof(s))); + return setValue(reinterpret_cast<const uint8_t*>(s), strnlen(s, sizeof(T))); } else {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/NimBLEAttValue.h` around lines 357 - 359, In NimBLEAttValue.h, the C++17 template branch that handles char arrays uses sizeof(s) when calling strnlen; change this to use sizeof(T) for consistency with the C++14 path and to correctly reflect the array type size in the branch around the reinterpret_cast and setValue call (i.e., update the branch that returns setValue(reinterpret_cast<const uint8_t*>(s), strnlen(s, sizeof(s))) to use sizeof(T) instead of sizeof(s)).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/NimBLEAttValue.h`:
- Around line 357-359: In NimBLEAttValue.h, the C++17 template branch that
handles char arrays uses sizeof(s) when calling strnlen; change this to use
sizeof(T) for consistency with the C++14 path and to correctly reflect the array
type size in the branch around the reinterpret_cast and setValue call (i.e.,
update the branch that returns setValue(reinterpret_cast<const uint8_t*>(s),
strnlen(s, sizeof(s))) to use sizeof(T) instead of sizeof(s)).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3e4d67af-eafe-461b-88f2-99039a73690c
📒 Files selected for processing (1)
src/NimBLEAttValue.h
Fixes #376
Summary by CodeRabbit