Conversation
| printMsg(number, dummy, newLine); | ||
| } | ||
|
|
||
| // All MessageSet instances below (MAIN_USAGE, EXAMPLES) are initialized with |
There was a problem hiding this comment.
Write this in PR description, not in code. Keep newlines between declarations.
| TEXT msg[BUFFER_TINY]; | ||
| snprintf(msg, sizeof(msg), "ConfigStorage: mutex %s error, status = %d", string, state); | ||
| [[maybe_unused]] const int len = snprintf(msg, sizeof(msg), "ConfigStorage: mutex %s error, status = %d", string, state); | ||
| fb_assert(len >= 0 && len < (int) sizeof(msg)); |
There was a problem hiding this comment.
Don't use C-style cast. Use static_cast for that.
| TraceSession session(*getDefaultMemoryPool()); | ||
|
|
||
| fseek(cfgFile, 0, SEEK_END); | ||
| [[maybe_unused]] int fseekResult = fseek(cfgFile, 0, SEEK_END); |
There was a problem hiding this comment.
Use different name const int variables. resultEnd and resultSet, for example.
| m_info.pin_count = m_legacyCounts.getCount(); | ||
|
|
||
| for (MetaId i = 0; i < m_info.pin_count; i++) | ||
| for (FB_SIZE_T i = 0; i < m_info.pin_count; i++) |
There was a problem hiding this comment.
Explain this in PR. Why not to change type or cast m_info.pin_count instead?
|
Rename the PR to reflect changes you made. Write PR description. |
|
One of your commit messages: use FB_SIZE_T instead of MetaId for loop variable in TraceRuntimeStats (bugprone-too-small-loop-variable) Please remove checker names and file names. |
|
Still filename in commit 772987b |
|
Also, split this branch into two, please. You can just cherry-pick if your changes are independent. First two problems should go into one branch and last two in another. No need to describe first two problems that much. |
Problem
values explicitly, which could lead to silent incorrect behavior.
time(),fseek()andsnprintf()were ignored,even though their failure (or truncation, for
snprintf()) could leadto incorrect behavior going unnoticed.
MetaId(USHORT), a type not intended forholding counts, to iterate up to
m_info.pin_count(typesize_t),risking narrowing and a potential infinite loop.
MessageSetusedintfor message codes that are always within asmall fixed range, wider than necessary.
Fix
default: fb_assert(false)branches to catch unexpectedswitch values early instead of failing silently.
time(),fseek()andsnprintf()into[[maybe_unused]]variables and addedfb_assertchecks on them.FB_SIZE_Tto match the type ofm_info.pin_countit's compared against, avoiding narrowing.MessageSetfields toUSHORT.Notes
pin_count's type isn't an option sincePerformanceInfoisa public struct used outside this file — that would be an API change.
Casting
pin_countat the comparison would just hide the mismatchrather than fix it:
iis used as an array index intom_tableCounters, not as aMetaId, soMetaIdwas the wrong typehere regardless of
pin_count's type. Widening the loop variable toFB_SIZE_Tfixes the actual type mismatch and removes the risk ofoverflow/infinite loop if
pin_countever grows beyondUSHORTrange.MessageSetfields were changed toUSHORT. All current usages(
MAIN_USAGE,EXAMPLES) are initialized with message codes in range3..42, e.g.
MAIN_USAGE{{3, 21}, {41}},EXAMPLES{{22, 27}, {42}}—well within
USHORT(0..65535). If new codes are added in the future,make sure they still fit into
USHORT.