View Issue Details

IDProjectCategoryView StatusLast Update
0035102FPCFCLpublic2020-06-24 15:31
ReporterSerge Anvarov Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
OSWindows 
Product Version3.3.1 
Summary0035102: TRegistry. Patch 4. Windows. Repeated code conversion from DWORD to TRegDataType
DescriptionThe repeated code is placed into a separate function.
TagsNo tags attached.
Fixed in Revision41952
FPCOldBugId
FPCTarget
Attached Files

Activities

Serge Anvarov

2019-02-16 20:06

reporter  

registry4.diff (1,731 bytes)   
Index: packages/fcl-registry/src/winreg.inc
===================================================================
--- packages/fcl-registry/src/winreg.inc	(revision 41343)
+++ packages/fcl-registry/src/winreg.inc	(working copy)
@@ -43,6 +41,17 @@
   Result:=(S='') or (S[1]<>'\')
 end;
 
+function RegDataWordToRegDataType(RD: DWORD): TRegDataType;
+begin
+  // Test in ascending because rdString is most commonly used
+  Result := Succ(Low(RegDataWords));
+  repeat
+    if RegDataWords[Result] = RD then
+      Exit;
+    Inc(Result);
+  until Result > High(Result);
+  Result := Low(RegDataWords);
+end;
 
 function TRegistry.sysCreateKey(const Key: String): Boolean;
 Var
@@ -96,12 +105,10 @@
   if (FLastError<>ERROR_SUCCESS) Then
     Result:=-1
   else
-    begin
-    RegData:=High(TRegDataType);
-    While (RegData>rdUnknown) and (RD<>RegDataWords[RegData]) do
-      RegData:=Pred(RegData);
-    Result:=BufSize;
-    end;
+  begin
+    RegData := RegDataWordToRegDataType(RD);
+    Result := BufSize;
+  end;
 end;
 
 function TRegistry.GetDataInfo(const ValueName: String; out Value: TRegDataInfo): Boolean;
@@ -114,15 +121,10 @@
   u:=ValueName;
   With Value do
     begin
-    FLastError:=RegQueryValueExW(fCurrentKey,PWideChar(u),Nil,lpdword(@RegData),Nil,lpdword(@DataSize));
+    FLastError:=RegQueryValueExW(fCurrentKey,PWideChar(u),Nil,@RD,Nil,lpdword(@DataSize));
     Result:=FLastError=ERROR_SUCCESS;
     if Result then
-      begin
-      RD:=DWord(RegData);
-      RegData:=High(TRegDataType);
-      While (RegData>rdUnknown) and (RD<>RegDataWords[RegData]) do
-         RegData:=Pred(RegData);
-      end;
+      RegData := RegDataWordToRegDataType(RD);
     end;
   If Not Result Then
     begin
registry4.diff (1,731 bytes)   

Serge Anvarov

2019-04-10 07:12

reporter   ~0115370

Revision 60900. The patch is still actual.

Michael Van Canneyt

2019-04-10 11:25

administrator   ~0115386

I tried the patch. It fails.

From your patch:

 function TRegistry.GetDataInfo(const ValueName: String; out Value: TRegDataInfo): Boolean;
@@ -114,15 +121,10 @@
   u:=ValueName;
   With Value do
     begin

The u:=ValueName is missing in my version of the code. What patch must be applied first ?

Serge Anvarov

2019-04-10 16:55

reporter   ~0115395

Created a new diff file

Serge Anvarov

2019-04-10 16:55

reporter  

registry4.r41854.diff (1,558 bytes)   
Index: packages/fcl-registry/src/winreg.inc
===================================================================
--- packages/fcl-registry/src/winreg.inc	(revision 41854)
+++ packages/fcl-registry/src/winreg.inc	(working copy)
@@ -42,6 +42,17 @@
   Result:=(S='') or (S[1]<>'\')
 end;
 
+function RegDataWordToRegDataType(RD: DWORD): TRegDataType;
+begin
+  // Test in ascending because rdString is most commonly used
+  Result := Succ(Low(RegDataWords));
+  repeat
+    if RegDataWords[Result] = RD then
+      Exit;
+    Inc(Result);
+  until Result > High(Result);
+  Result := Low(RegDataWords);
+end;
 
 function TRegistry.sysCreateKey(Key: UnicodeString): Boolean;
 Var
@@ -95,9 +106,7 @@
     Result:=-1
   else
     begin
-    RegData:=High(TRegDataType);
-    While (RegData>rdUnknown) and (RD<>RegDataWords[RegData]) do
-      RegData:=Pred(RegData);
+    RegData:=RegDataWordToRegDataType(RD);
     Result:=BufSize;
     end;
 end;
@@ -110,15 +119,10 @@
 begin
   With Value do
     begin
-    FLastError:=RegQueryValueExW(fCurrentKey,PWideChar(ValueName),Nil,lpdword(@RegData),Nil,lpdword(@DataSize));
+    FLastError:=RegQueryValueExW(fCurrentKey,PWideChar(ValueName),Nil,@RD,Nil,lpdword(@DataSize));
     Result:=FLastError=ERROR_SUCCESS;
     if Result then
-      begin
-      RD:=DWord(RegData);
-      RegData:=High(TRegDataType);
-      While (RegData>rdUnknown) and (RD<>RegDataWords[RegData]) do
-         RegData:=Pred(RegData);
-      end;
+      RegData:=RegDataWordToRegDataType(RD);
     end;
   If Not Result Then
     begin
registry4.r41854.diff (1,558 bytes)   

Michael Van Canneyt

2019-04-28 11:27

administrator   ~0115871

Thank you for the renewed patch. checked and applied !

Serge Anvarov

2020-06-24 15:31

reporter   ~0123565

It is not included in release 3.2.0. Waiting.

Issue History

Date Modified Username Field Change
2019-02-16 20:06 Serge Anvarov New Issue
2019-02-16 20:06 Serge Anvarov File Added: registry4.diff
2019-04-10 07:12 Serge Anvarov Note Added: 0115370
2019-04-10 11:25 Michael Van Canneyt Note Added: 0115386
2019-04-10 11:25 Michael Van Canneyt Assigned To => Michael Van Canneyt
2019-04-10 11:25 Michael Van Canneyt Status new => feedback
2019-04-10 16:55 Serge Anvarov Note Added: 0115395
2019-04-10 16:55 Serge Anvarov Status feedback => assigned
2019-04-10 16:55 Serge Anvarov File Added: registry4.r41854.diff
2019-04-28 11:27 Michael Van Canneyt Status assigned => resolved
2019-04-28 11:27 Michael Van Canneyt Resolution open => fixed
2019-04-28 11:27 Michael Van Canneyt Fixed in Revision => 41952
2019-04-28 11:27 Michael Van Canneyt Note Added: 0115871
2020-06-24 15:31 Serge Anvarov Note Added: 0123565