InitCriticalSection should have an "out" parameter
Original Reporter info from Mantis: creaothceann
-
Reporter name:
Original Reporter info from Mantis: creaothceann
- Reporter name:
Description:
InitCriticalSection is defined as "procedure InitCriticalSection(var cs: TRTLCRITICALSECTION);",
see https://www.freepascal.org/docs-html/rtl/system/initcriticalsection.html
This procedure takes a "var" parameter and initializes it by filling it with (OS-specific) data. It does not rely on the previous contents of the passed variable.
Passing an uninitialized variable creates the compiler hint "&LtPos;variable> does not seem to be initialized", which requires either initializing the variable manually, adding an IDE directive, or other means of suppressing the compiler message. The fix would be changing the "var" parameter modifier to "out".
Steps to reproduce:
unit Test;
interface
procedure Test;
implementation
var cs : TRTLCriticalSection;
procedure Test;
begin
EnterCriticalSection(cs);
try {...} finally LeaveCriticalSection(cs); end;
end;
initialization
InitCriticalSection(cs);
finalization
DoneCriticalSection(cs);
end.
Additional information:
Using FPC 3.2.0 via Lazarus 2.0.10 (date: 2020-07-07).
Mantis conversion info:
- Mantis ID: 37376
- OS: Windows
- OS Build: 10
- Build: 63526
- Platform: x86_64
- Version: 3.2.0
- Fixed in version: 3.3.1
- Fixed in revision: 46533 (#213d2905)
- Monitored by: » creaothceann (creaothceann)
- Target version: 3.2.2