Skip to content

Fix/warnings 2 - #48

Closed
Foxpunk wants to merge 11 commits into
masterfrom
fix/warnings
Closed

Foxpunk wants to merge 11 commits into
masterfrom
fix/warnings

Conversation

@Foxpunk

@Foxpunk Foxpunk commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Problem

  • Several switch statements over enum-like fields didn't handle unexpected
    values explicitly, which could lead to silent incorrect behavior.
  • Return values of time(), fseek() and snprintf() were ignored,
    even though their failure (or truncation, for snprintf()) could lead
    to incorrect behavior going unnoticed.
  • A loop variable used MetaId (USHORT), a type not intended for
    holding counts, to iterate up to m_info.pin_count (type size_t),
    risking narrowing and a potential infinite loop.
  • MessageSet used int for message codes that are always within a
    small fixed range, wider than necessary.

Fix

  • Added explicit default: fb_assert(false) branches to catch unexpected
    switch values early instead of failing silently.
  • Saved the return values of time(), fseek() and snprintf() into
    [[maybe_unused]] variables and added fb_assert checks on them.
  • Changed the loop variable type to FB_SIZE_T to match the type of
    m_info.pin_count it's compared against, avoiding narrowing.
  • Changed MessageSet fields to USHORT.

Notes

  • Changing pin_count's type isn't an option since PerformanceInfo is
    a public struct used outside this file — that would be an API change.
    Casting pin_count at the comparison would just hide the mismatch
    rather than fix it: i is used as an array index into
    m_tableCounters, not as a MetaId, so MetaId was the wrong type
    here regardless of pin_count's type. Widening the loop variable to
    FB_SIZE_T fixes the actual type mismatch and removes the risk of
    overflow/infinite loop if pin_count ever grows beyond USHORT range.
  • MessageSet fields were changed to USHORT. All current usages
    (MAIN_USAGE, EXAMPLES) are initialized with message codes in range
    3..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.

Comment thread src/jrd/trace/TraceCmdLine.cpp Outdated
printMsg(number, dummy, newLine);
}

// All MessageSet instances below (MAIN_USAGE, EXAMPLES) are initialized with

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write this in PR description, not in code. Keep newlines between declarations.

Comment thread src/jrd/trace/TraceConfigStorage.cpp Outdated
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));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use C-style cast. Use static_cast for that.

Comment thread src/jrd/trace/TraceConfigStorage.cpp Outdated
TraceSession session(*getDefaultMemoryPool());

fseek(cfgFile, 0, SEEK_END);
[[maybe_unused]] int fseekResult = fseek(cfgFile, 0, SEEK_END);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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++)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain this in PR. Why not to change type or cast m_info.pin_count instead?

@craftmaster1231

Copy link
Copy Markdown
Owner

Rename the PR to reflect changes you made. Write PR description.
Don't write about warnings in PR name. Better don't write about them at all. Write about problems and fixes.

@craftmaster1231

craftmaster1231 commented Jul 24, 2026

Copy link
Copy Markdown
Owner

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.

@Foxpunk Foxpunk changed the title Fix/warnings Fix/warnings 2 Jul 27, 2026
@craftmaster1231

Copy link
Copy Markdown
Owner

Still filename in commit 772987b

@craftmaster1231

craftmaster1231 commented Jul 30, 2026

Copy link
Copy Markdown
Owner

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.
Please, don''t name branches like that. No "fix_warnings" or "warnings12345". You can do master_add_asserts and master_fix_types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants