View Issue Details

IDProjectCategoryView StatusLast Update
0037376FPCRTLpublic2020-08-22 09:03
Reportercreaothceann Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Platformx86_64OSWindows 
Product Version3.2.0 
Fixed in Version3.3.1 
Summary0037376: InitCriticalSection should have an "out" parameter
DescriptionInitCriticalSection 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 "<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 Reproduceunit 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 InformationUsing FPC 3.2.0 via Lazarus 2.0.10 (date: 2020-07-07).
TagsNo tags attached.
Fixed in Revision46533
FPCOldBugId
FPCTarget3.2.2
Attached Files

Activities

ravi dion

2020-08-19 22:06

reporter   ~0125001

Seems legit

Serge Anvarov

2020-08-20 15:40

reporter   ~0125025

I can also suggest more candidates for changing the parameter type:
BlockRead
BlockWrite
BeginThread
GetThreadManager
GetWideStringManager
GetUnicodeStringManager
GetVariantManager
GetDynLibsManager
SetWideStringManager
SetUnicodeStringManager
SetDynLibsManager
TryEnterCriticalSection

Michael Van Canneyt

2020-08-21 12:46

administrator   ~0125060

Changed most, but not:
BlockRead/Blockwrite : for TP compatibility.
TryEnterCriticalSection : I don't think out would be correct.

Serge Anvarov

2020-08-22 08:22

reporter   ~0125068

I agree, I made a mistake with TryEnterCriticalSection.

Michael, can I prepare a series of patches (in new issues) for the Windows API, where it is also possible to replace var with out to eliminate unnecessary warning cases? Only for parameter types that are not managed and do not include them. Of course, only if it is consistent with the WinAPI documentation.
It's just a lot of work, but if it's definitely rejected, I don't want to waste time.

Michael Van Canneyt

2020-08-22 09:03

administrator   ~0125071

@Serge: Sure.
But be careful, from what I know a lot of parameters are indeed VAR instead of simply OUT.
But I suppose the MSDN documentation can tell you when it's OUT.

Issue History

Date Modified Username Field Change
2020-07-16 21:32 creaothceann New Issue
2020-08-19 22:06 ravi dion Note Added: 0125001
2020-08-20 15:40 Serge Anvarov Note Added: 0125025
2020-08-21 12:44 Michael Van Canneyt Note View State: 0125025: private
2020-08-21 12:44 Michael Van Canneyt Note View State: 0125025: public
2020-08-21 12:46 Michael Van Canneyt Assigned To => Michael Van Canneyt
2020-08-21 12:46 Michael Van Canneyt Status new => resolved
2020-08-21 12:46 Michael Van Canneyt Resolution open => fixed
2020-08-21 12:46 Michael Van Canneyt Fixed in Version => 3.3.1
2020-08-21 12:46 Michael Van Canneyt Fixed in Revision => 46533
2020-08-21 12:46 Michael Van Canneyt FPCTarget => 3.2.2
2020-08-21 12:46 Michael Van Canneyt Note Added: 0125060
2020-08-22 08:22 Serge Anvarov Note Added: 0125068
2020-08-22 09:03 Michael Van Canneyt Note Added: 0125071