Jump to content
David Heffernan

Why does TRegistry.GetKeyInfo double the returned values of MaxSubKeyLen/MaxValueLen for far eastern locales?

Recommended Posts

I came across this code in the RTL:

function TRegistry.GetKeyInfo(var Value: TRegKeyInfo): Boolean;
begin
  FillChar(Value, SizeOf(TRegKeyInfo), 0);
  Result := CheckResult(RegQueryInfoKey(CurrentKey, nil, nil, nil, @Value.NumSubKeys,
    @Value.MaxSubKeyLen, nil, @Value.NumValues, @Value.MaxValueLen,
    @Value.MaxDataLen, nil, @Value.FileTime));
  if SysLocale.FarEast and (Win32Platform = VER_PLATFORM_WIN32_NT) then
    with Value do
    begin
      Inc(MaxSubKeyLen, MaxSubKeyLen);
      Inc(MaxValueLen, MaxValueLen);
    end;
end;

I'm wanting to call RegQueryInfoKey and wondering if I also need to mimic this far east if statement. I had a quick search on github for other code calling this function and can't see anything similar.

 

Is it possible that this code is bogus?

Share this post


Link to post

@Attila Kovacs

All Windows versions from Windows NT up to the current have Win32Platform = VER_PLATFORM_WIN32_NT. Other possible values are Win32s and Windows 95.

  • Like 1

Share this post


Link to post

Probably it' something to do with UTF16 surrogate pairs which are used in Far East languages

Edited by Fr0sT.Brutal

Share this post


Link to post
5 hours ago, David Heffernan said:

I came across this code in the RTL:

...

I'm wanting to call RegQueryInfoKey and wondering if I also need to mimic this far east if statement.

No.  It is a remnant from Delphi's pre-Unicode days (going all the way back to Delphi 5, if not earlier).  Even then, I question why it was ever added in the first place, since the API always returned the correct sizes to begin with.  So, this will cause the caller to unnecessarily waste memory (if they enumerate subkey/value names afterwards) and should be taken out.

Quote

Is it possible that this code is bogus?

Yes.  The increment is not necessary.  I have filed a bug report:

RSP-41787: TRegistry.GetKeyInfo() doubles size of MaxSubKeyLen and MaxValueLen

Edited by Remy Lebeau
  • Like 4

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×