Winquery additional characters in strings

Not sure if matlab also does it, but in windows, with octave 7.0.91:

a = winqueryreg (“HKEY_LOCAL_MACHINE”, ‘SOFTWARE\Microsoft\Windows\CurrentVersion’, “ProgramFilesDir”)

gives me "C:\Program Files "

(Note the extra space which is reality is a 0 character)

The previous version of octave doesnt add it - what does matlab do ?

In Matlab R2021a:

>> a = winqueryreg ('HKEY_LOCAL_MACHINE', 'SOFTWARE\Microsoft\Windows\CurrentVersion', 'ProgramFilesDir')

a =

    'C:\Program Files'

running Windows 10, Version 20H2

Octave 6.4.0 CLI:

octave:1> a = winqueryreg ('HKEY_LOCAL_MACHINE', 'SOFTWARE\Microsoft\Windows\CurrentVersion', 'ProgramFilesDir')
a = C:\Program Files
octave:2> a(end)
ans = s

Octave 7.0.1 (hg id: d00ae0ad8f89) CLI:

octave:2> a = winqueryreg ('HKEY_LOCAL_MACHINE', 'SOFTWARE\Microsoft\Windows\CurrentVersion', 'ProgramFilesDir')
a = C:\Program Files
octave:3> a(end)
ans =

Octave 7.0.90 (hg id: 347dbc9049d5)

octave:2> a = winqueryreg ('HKEY_LOCAL_MACHINE', 'SOFTWARE\Microsoft\Windows\CurrentVersion', 'ProgramFilesDir')
a = C:\Program Files
octave:3> a(end)
ans =

Matlab 2021b:

>> a = winqueryreg ('HKEY_LOCAL_MACHINE', 'SOFTWARE\Microsoft\Windows\CurrentVersion', 'ProgramFilesDir')
a =
    'C:\Program Files'
>> a(end)
ans =
    's'

opening regedit to look at the key directly, there doesn’t appear to be a space following Files, the ‘s’ is indeed the last character, so it’s being appended somewhere.

Likely unrelated but I do notice there is also a ‘ProgramFilesDir (x86)’ key where the key value is “C:\Program Files (x86)”. two keys with (x86) are the only two with spaces in the key name. could it be finding and misreading that key?

also not sure why matlab 2021a and b are giving different results, I don’t have a or any previous version to try.

i’m guessing change introduced the extra character:

https://hg.octave.org/octave/rev/3c60814448ea

Perhaps need to check for trailing null bytes

Thanks. Should be fixed here:
hg.savannah.gnu.org/hgweb/octave/rev/51770116f835