The Delphi Bug List

Entry No.
676
VCL - General - IniFiles - TIniFile
In TIniFile.ReadString, passing a default argument that ends in a space character causes an "invalid page fault in module KRNL386.EXE at 0002:00005c83".
1.02 2.01 3.0 3.01 3.02 4.0 4.01 4.02 4.03 5.0 5.01 6.0 6.01 6.02 Kylix 1.0
AbsentGotchaGotchaGotchaGotchaGotchaGotchaGotchaGotchaGotchaGotchaGotchaGotchaGotchaN/A
Description
Reported by Frank Wittl; checked by Jordan Russell
See also bug #424.

The bug can be reliably reproduced with the following code attempting to read a INI entry that does not exist:

IniString := IniFile.ReadString('Test', 'TestString', ' ');
Note that the default argument character in the third parameter is a ' ' (space). Deleting the ' ' ends the problem.

Some other notes:

  1. This bug is Windows version dependent: Windows 95 and 98 have the bug, but NT 4.0 SP6 and WIN2K does not have it.
  2. This bug has been reproduced in Delphi 5 (with SP1) and Delphi 6.
User-contributed comments
Space Case
11 Jul 2001  03:08 PM GMT
Actually, this entry's header should probably read "...ends with a space..." rather than "...contains a space...", based on the results of tests I've just run (D3.02 on Win98)!
anonymous
28 Nov 2001  09:36 PM GMT
This in the end is a bug in Microsoft Windows.

<quote MSDN>
Avoid specifying a default string with trailing blank characters. The function inserts a null character in the lpReturnedString buffer to strip any trailing blanks.

Windows 95/98/Me: Although lpDefault is declared as a constant parameter, the system strips any trailing blanks by inserting a null character into the lpDefault string before copying it to the lpReturnedString buffer.
</quote>

When
  IniFile.ReadString('Test', 'TestString', ' ');

is called then the default item ' ' resides in write-protected virtual memory. Windows BlowMeUpScotty will try to write to that - end of story.

Borland could theoretically work around this defect by creating a temporary default string in writable memory - but the generally erratic behaviour of Windows 95/98/Me cannot be fixed.
Latest update of this entry: 2002-03-18

Post a comment on this bug


Index page
Delphi Bug List home page
The Delphi Bug Lists are presently maintained by Jordan Russell, who has taken over this task from Reinier Sterkenburg since August 2000.
All feedback is appreciated. See also the feedback section of the Delphi Bug List home page.