View Issue Details

IDProjectCategoryView StatusLast Update
0033980FPCFCLpublic2019-03-02 18:16
ReporterBart BroersmaAssigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Platformi386OSWindowsOS Version10
Product Version3.1.1Product Build39352 
Target VersionFixed in Version 
Summary0033980: TRegIniFile: failure on consecutive reads when Section parameter is empty
DescriptionWhen you do consecutive reads (like ReadString) on the same key/section/ident, and the Section paramter is an empty string, then the second (and following) reads will fail.
Steps To ReproduceBuild and run the following program:

program rtest;

{$apptype console}
{$ifdef fpc}{$mode objfpc}{$endif}

uses
  registry, sysutils, classes {$ifndef fpc}, windows{$endif};

var
  RegIni: TRegIniFile;
  WFileName: String;
  i: Integer;
begin
  RegIni := TRegIniFile.Create('SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', KEY_READ);
  try
    for i := 1 to 2 do
    begin
      WFileName := RegIni.ReadString ('', 'Desktop', 'Failure!');
      writeln(format('Try %d: WFileName = "%s"',[i,WFileName]));
    end;
  finally
    RegIni.Free;
  end;
end.

Build and run with fpc

C:\Users\Bart\LazarusProjecten\bugs\Console\regini>fpc rtest.lpr
Free Pascal Compiler version 3.1.1 [2018/06/03] for i386
...
C:\Users\Bart\LazarusProjecten\bugs\Console\regini>rtest
Try 1: WFileName = "C:\Users\Bart\Desktop"
Try 2: WFileName = "Failure!"

Now build and run with Delphi (D7)

C:\Users\Bart\LazarusProjecten\bugs\Console\regini>dcc32 rtest.lpr
Borland Delphi Version 15.0
Copyright (c) 1983,2002 Borland Software Corporation
rtest.lpr(25)
...
C:\Users\Bart\LazarusProjecten\bugs\Console\regini>rtest
Try 1: WFileName = "C:\Users\Bart\Desktop"
Try 2: WFileName = "C:\Users\Bart\Desktop"
Additional InformationOriginally reported in forum: http://forum.lazarus.freepascal.org/index.php/topic,41847.0.html by user BjPascal.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

Bart Broersma

2018-07-13 16:54

reporter   ~0109430

Last edited: 2018-07-18 13:08

View 2 revisions

Maybe Section should not be closed if it is empty string?
(Probably for both reading and writing)

Michael Van Canneyt

2018-08-21 16:21

administrator   ~0110199

I don't have windows, so it is hard to test.
The testprogram works not at all on Linux, I did test that.
So whenever I again work a little under Windows, I will look at this.
(unless someone else fixes it first)

Bart Broersma

2018-08-21 16:27

reporter   ~0110200

Where is the test program?
I don't mind fixing/testing.
It's just that I hardly ever use TRegistry and never in my life used TRegIniFile.
I can also hardly find any Delphi examples (with expectd output).

Michael Van Canneyt

2018-08-21 16:31

administrator   ~0110201

Ehm. it's in the bug description ?

Bart Broersma

2018-08-21 16:47

reporter   ~0110203

When you mentioned test program I hoped there was a testprogram somewhere in fpc's tests.
So, I misunderstood you.

There are many methods that call CloseSection, most of them I don't really know how they should behave.
Probably the same issue exists for consecutive writes.

I'll keep on testing when I have time.
That'll be on Windows.
Hope I don't screw up my registry.

I sincerely hope nobody of sound mind uses this on a non-Windows platform...

Michael Van Canneyt

2018-08-21 17:07

administrator   ~0110205

I don't even use the registry on Windows, so my experience is limited.

jamie philbrook

2018-08-22 02:59

reporter   ~0110224

In this example, not defining a section in the ReadString does nothing.

I can't even see how it works the first time?
Looking at the code below..
createSection is set to false because it isn't specified in the
ReadString.

function TRegIniFile.OpenSection(const Section: string; CreateSection : Boolean = false): boolean;
var
  k: HKEY;
  S : String;

begin
  S:=Section;
  If (S<>'') and (S[1] = '\') then
    Delete(S,1,1);
  if CreateSection then
    CreateKey('\'+FPath+S);
  if Section <> '' then
    begin
    k:=GetKey('\'+FPath+S);
    if k = 0 then
      begin
      Result:=False;
      exit;
      end;
    SetCurrentKey(k);
  end;
  Result:=True;
end;

It looks like it simply skips all of this and never actually "Getkey"

Not sure what would happen if you would use a '\' instead of an empty section in the call? It would at least call the GetKey function..

Bart Broersma

2019-03-02 18:16

reporter   ~0114580

Please see patch from 0035022, it will fix this issue.

Issue History

Date Modified Username Field Change
2018-07-13 16:51 Bart Broersma New Issue
2018-07-13 16:54 Bart Broersma Note Added: 0109430
2018-07-18 13:08 Bart Broersma Note Edited: 0109430 View Revisions
2018-08-21 16:21 Michael Van Canneyt Note Added: 0110199
2018-08-21 16:27 Bart Broersma Note Added: 0110200
2018-08-21 16:31 Michael Van Canneyt Note Added: 0110201
2018-08-21 16:47 Bart Broersma Note Added: 0110203
2018-08-21 17:07 Michael Van Canneyt Note Added: 0110205
2018-08-22 02:59 jamie philbrook Note Added: 0110224
2019-03-02 18:16 Bart Broersma Note Added: 0114580