integrated-application-development / integrated-application-development/sonar-delphi

Do not use FillChar to initialize records

Open
#150 3 comments 1 reaction 0 assignees View on GitHub
feature rule
Dominant language
Java
Stars
159
Forks
31
Avg merge
5d 4h
Merged PRs (30d)
4

Description

### Prerequisites

- [X] This rule has not already been suggested.
- [X] This should be a new rule, not an improvement to an existing rule.
- [X] This rule would be generally useful, not specific to my code or setup.

### Suggested rule title

NoFillCharOnRecords

### Rule description

Using `FillChar` or `ZeroMemory` to initialize a record can evolve badly if one adds a managed field to the record. If the Delphi version supports it, it is suggested to use `:= Default(T)` instead.

This was suggested as part of #149, but is too dependent on using a recent Delphi version. Making it a separate rule is more adequate.

### Rationale

Using `FillChar` on a managed field can skip a refcount `Release` and result in large memory leaks.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.