[Feature] A string Result value of a function should be initialized automatically
Original Reporter info from Mantis: JuhaManninen @JuhaManninen
-
Reporter name: Juha Manninen
Original Reporter info from Mantis: JuhaManninen @JuhaManninen
- Reporter name: Juha Manninen
Description:
In r34092 I fixed a bug in Lazarus Codetools by initializing the string Result value of a function.
This was the first time with FPC I clearly saw with a debugger that an uninitialized string Result can contain anything.
I have seen the same problem in Delphi years ago. It means the current behavior is Delphi compatible but is also a source of nasty bugs and it goes against what people expect.
If I understand right, other local string variables are initialized as empty ('') but the Result is not.
In my example case the function was called inside a loop from another function.
Values were accumulated, apparently because the same space was used for the variable.
With different OS / CPU / compiler / heap /stack ... whatever combinations the behavior may be different.
I propose now that the string Result value is initialized automatically.
Delphi's behavior should not be followed here because it can be considered a bug in Delphi.
If for some reason the value cannot be initialized, at least the compiler should warn about such uninitialized variable.
Additional information:
My compiler version is really 2.6.0 RC1 but it was not in the list.
Mantis conversion info:
- Mantis ID: 20907
- OS: Linux
- OS Build: OpenSuse 11.4
- Platform: x86
- Version: 2.7.1
- Fixed in version: 2.6.1
- Fixed in revision: 20427 (#75aac428)
- Monitored by: » luizamerico (Luiz Americo), » @JuhaManninen (Juha Manninen), » Vincent (Vincent Snijders)