Added default initialization to avoid garbage values#8973
Added default initialization to avoid garbage values#89733qupo wants to merge 11 commits intoFirebirdSQL:masterfrom
Conversation
| ULONG length = 0; | ||
| UCHAR item; | ||
| USHORT max_segment; | ||
| USHORT max_segment = 0; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
fld_ranges is the right default here.
| if (return_length != slice_length) | ||
| { | ||
| int upper, lower; | ||
| int upper = 0, lower = 0; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
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:
nullptrfor pointer initializationsThis PR is part of the closed parent PR #8938, which was split into smaller, focused pull requests.