lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>    n = strtol(&s[2], &ss,base);
>    if (ss != &s[2])
>      return (double)n;
>    else
>      return -1;
>  }
>  // End Hex

I belive this will accept wrong numbers... 
Ex:  s="0xA0XF"
     n = strtol(&s[2], &ss, 16) whil produce:
     n  = 160 (A0) and  ss = "XF"

I belive a simple change can solve that (UNTESTED):

    if(!s[2]) 
      return -1;
    n = strtol(&s[2], &ss, base);
    if(!(*ss))
      return -1;
    else
      return (double)n;


[]s,
Carlos Augusto.