Skip to content

Added default initialization to avoid garbage values#8973

Open
3qupo wants to merge 19 commits into
FirebirdSQL:masterfrom
3qupo:added_default_initialization_to_avoid_garbage_values
Open

Added default initialization to avoid garbage values#8973
3qupo wants to merge 19 commits into
FirebirdSQL:masterfrom
3qupo:added_default_initialization_to_avoid_garbage_values

Conversation

@3qupo

@3qupo 3qupo commented Mar 31, 2026

Copy link
Copy Markdown

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.

Comment thread src/burp/restore.epp Outdated
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.

Copy link
Copy Markdown
Member

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.

In backup.epp, max_segment is initialized with zero in the very same piece of code. If we have no reply for isc_info_blob_max_segment and blob total length is not zero, why should we imply length being USHRT_MAX as you suggest?

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.

Comment "Rdb sometimes gets the length messed up" suggests that total BLOB length can be evaluated wrongly. In this case using buffer of maximum allowed segment size is better.

I suspect that this piece of code exists only to avoid allocation of 64k memory unconditionally. It had sense in the previous century but not today.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Its all makes no sense and is a waste of time. Vars gets its values from server response. There can be exactly one reason for any item to have no response - some fatal error. This is API contract. If it become broken, many places in code will fail.

Note, the title say: "...to avoid garbage values" - this code doesn't prevent any kind of garbage values.

Also, why max_segment gets default, while num_segments - not ? Looks like "slightly-pregnant", sorry...

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.

Because num_segments is not used at all. This routine still can handle only ACLs of max size 64k. Perhaps, @AlexPeshkoff missed it when fixed #2651.

Comment thread src/burp/restore.epp Outdated
Comment thread src/burp/restore.epp Outdated
Comment thread src/burp/restore.epp
Comment thread src/burp/restore.epp
*
**************************************/
enum trig_t type;
enum trig_t type = trig_none;

@aafemt aafemt Mar 31, 2026

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.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd better use std::optional rather than introduce trig_none for nothing useful.

Comment thread src/dsql/DdlNodes.epp
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.

Comment thread src/jrd/cvt2.cpp Outdated
Comment thread src/jrd/cvt2.cpp Outdated
if (desc->isText())
{
if (from_interp == to_interp || to_interp == ttype_none || to_interp == ttype_binary)
if (from_interp == ttype_none || from_interp == to_interp || to_interp == ttype_none || to_interp == ttype_binary)

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 may be a wrong change: NONE is the most permissive charset, so conversion from NONE to something else requires validation of data which can be skipped in the other direction.

@3qupo 3qupo force-pushed the added_default_initialization_to_avoid_garbage_values branch from 974229b to d3d0952 Compare April 14, 2026 08:25
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.

4 participants