TRegistry_TryReadBool(Key) and TRegistryGuard methods crash for a key that...
Brought to you by:
twm
TRegistry_TryOpenKeyReadonly returns a guard whose Reg is nil (and IsValid False) if the key cannot be opened. Several callers do not check that and end in an access violation:
TRegistry_TryReadBool(Key, Entry, Value, HKEY) calls TRegistry_TryReadBool(Guard.Reg, ...) without checking Guard.IsValid, so it crashes for a key that does not exist instead of returning False. TRegistry_ReadBool(Key, ...) goes through it and crashes too. The sibling overloads of TRegistry_TryReadString and TRegistry_TryReadInteger do check it.TRegistryGuard.TryReadInteger does not check IsValid, and with it ReadIntegerDef.TRegistryGuard.WriteInteger does not check IsValid.TRegistryGuard.TryReadString, ReadStringDef, TryReadStringList, WriteString and WriteStringList do check it.
Fix: check IsValid in all of them. WriteInteger then does nothing on an invalid guard, like WriteString and WriteStringList already do; whether a write should be silently dropped there is a separate question.
Fixed in revision #2432