Bug? Old KVS1: some strings are treated as float


Well-Known Member
Licensed User

I think I found a bug with the old KVS. I know, I must be one of the only sticking with the first version of KVS1, but I can't upgrade it at the moment!

The bug is that if I putSimple this:
KVS.PutSimple("ColorAccent", "0e9395")
The data stored in KVS is actually this:
"ColorAccent": 0
I tried to figure out what's happening, and it could be because any string starting with "0e" is treated as float : https://www.whitehatsec.com/blog/magic-hashes/

I guess the problem with KVS1 was that the type of the column wasn't specified:
sql1.ExecNonQuery("CREATE TABLE IF NOT EXISTS main(key TEXT PRIMARY KEY, value NONE)")
so that allows the string to be treated as float.

I know it's a random case, but I figured I should post it, for learning purposes, and it took me quite a while to figure out the problem :)


Licensed User
I have a vague recollection of similar confusion in C (I think it was) where integers with leading zeros were interpreted as octal.

X = 23 'twenty-three
X = 023 'nineteen

I was surprised that your 0e9395 didn't crap out with an exponent-too-large error because single precision floats ("E") have a maximum exponent of 38, and double precision floats (which I thought were "D") have a maximum exponent of 308. But 0eANYTHING still equals 0, so... fair enough... :)