Skip to content

Added default initialization to avoid garbage values#8973

Open
3qupo wants to merge 11 commits intoFirebirdSQL:masterfrom
3qupo:added_default_initialization_to_avoid_garbage_values
Open

Added default initialization to avoid garbage values#8973
3qupo wants to merge 11 commits intoFirebirdSQL:masterfrom
3qupo:added_default_initialization_to_avoid_garbage_values

Conversation

@3qupo
Copy link
Copy Markdown

@3qupo 3qupo commented Mar 31, 2026

This PR adds default initialization for variables that were previously used without being explicitly initialized, potentially leading to undefined behavior due to garbage values.

The changes include:

  • Initializing local variables at declaration
  • Using nullptr for pointer initializations

This PR is part of the closed parent PR #8938, which was split into smaller, focused pull requests.

ULONG length = 0;
UCHAR item;
USHORT max_segment;
USHORT max_segment = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wrong initialization. In this case USHRT_MAX is a safe assumption.

SLONG slice_length = 0;
SLONG *range;
const SLONG* end_ranges;
const SLONG* end_ranges = nullptr;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fld_ranges is the right default here.

if (return_length != slice_length)
{
int upper, lower;
int upper = 0, lower = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is remains of old C code. Move this declaration to usage instead.

scan_attr_t scan_next_attr;
TEXT usr[GDS_NAME_LEN];
SSHORT uType;
SSHORT uType = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pointless because of initialization of typeSet below. But if your AI insist - initialize usr as well for symmetry.

*
**************************************/
enum trig_t type;
enum trig_t type = trig_none;
Copy link
Copy Markdown
Contributor

@aafemt aafemt Mar 31, 2026

Choose a reason for hiding this comment

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

For completeness you should also add a check that a meaningful value was assigned below and throw an error if type is still trig_none.

AutoCacheRequest request(tdbb, drq_l_rel_info, DYN_REQUESTS);
QualifiedName masterRelName;
rel_t masterType, childType;
rel_t masterType = rel_persistent;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This function is basically wrong and will fail in the case if the table has several foreign keys. It must be fixed, not polished.

UCHAR* from_buf;
USHORT from_len;
TTypeId from_interp;
USHORT from_interp = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

First, replacing a specific type with a generic one is a bad idea.
Second, right initial value would be ttype_none, but I would suggest to refactor this routine instead.

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