Bug? Old KVS1: some strings are treated as float

Discussion in 'B4J Bugs & Wishlist' started by jmon, Aug 22, 2019.

  1. jmon

    jmon 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:
    The data stored in KVS is actually this:
    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 :)
  2. Erel

    Erel Administrator Staff Member Licensed User

    It is a limitation of the old KVS implementation where the type information of "simple" values are lost.
    jmon likes this.
  3. emexes

    emexes Well-Known Member 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... :)
    jmon likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice