You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Show octal value when describing numeric base fields
✨ Enhancement🕐 Less than 10 minutes
AI Description
• Extend base field description output to include octal formatting alongside hex.
• Improve clipboard-friendly diagnostics for numeric parsing/representation.
The following are alternative approaches to this PR:
1. Save/restore iostream format flags around hex/oct output
➕ Prevents future formatting side effects if more numbers are appended after this output
➕ Makes base_t::to_stream safer if reused in other contexts
➖ Slightly more code (saving flags/precision) for a currently low-risk, end-of-stream usage
2. Use explicit base prefixes (showbase) or custom formatting helpers
➕ More readable output (e.g., 0xFF, 077) and clearer diagnostics
➕ Avoids reliance on stream state
➖ Changes output format more broadly (may break expectations/tests)
➖ More implementation churn than needed for adding octal output
Recommendation: The current approach is fine given the oct manipulator is applied at the end of the output path. If this formatting function is likely to grow or be reused, consider saving/restoring stream flags to avoid subtle future regressions caused by lingering std::oct/std::hex state.
Files changed (1) +2 / -1
Enhancement (1) +2 / -1
util.cppInclude octal representation in base field description output+2/-1
Include octal representation in base field description output
• Updates base_t::to_stream() to print the value in octal in addition to hex when emitting the non-decimal representation line. This enhances describe_basefields output that is copied to the clipboard for inspection.
1. Stream flags not restored✓ Resolved🐞 Bug⚙ Maintainability
Description
base_t::to_stream() leaves the caller-provided stream in std::oct mode after writing the octal
value, so any later integer output to the same std::stringstream will be octal unless reset (a
subtle formatting/correctness hazard). This is especially risky because other branches print labels
like "as dec" without explicitly forcing std::dec, relying on prior stream state.
ⓘ Recommendations generated based on similar findings in past PRs
Evidence
The updated hex branch sets std::hex and then std::oct on the shared std::stringstream and
never resets it. The same std::stringstream is reused across multiple conversions in
describe_basefields(), so any later numeric insertions to that stream would inherit the octal
formatting state.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
### Issue description
`base_t::to_stream()` writes using `std::hex` and now `std::oct`, but does not restore the original stream formatting flags. Because iostream manipulators are sticky, this can unexpectedly change formatting of later numeric writes to the same `std::stringstream`.
### Issue Context
`describe_basefields()` reuses one `std::stringstream` across multiple `to_stream()` calls; while the current call order happens to invoke the hex/oct path last, future edits (or additional stream writes after the call) can silently start emitting octal numbers.
### Fix Focus Areas
- src/stc/util.cpp[43-56]
- src/stc/util.cpp[88-119]
### Suggested fix
Inside `base_t::to_stream()`, save and restore the stream’s formatting state:
- Save: `auto old_flags = str.flags();`
- Optionally also save `old_fill` / `old_precision` if changed.
- Ensure decimal branch uses `std::dec` when printing "as dec".
- Restore at end of function: `str.flags(old_flags);`
Alternative: explicitly apply `std::dec` after the hex/oct write to avoid leaking octal mode.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.