Skip to content

fix some bug of strtold#8495

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
flyingfish89:fixbug_strtof
Feb 10, 2023
Merged

fix some bug of strtold#8495
xiaoxiang781216 merged 1 commit into
apache:masterfrom
flyingfish89:fixbug_strtof

Conversation

@flyingfish89
Copy link
Copy Markdown
Contributor

@flyingfish89 flyingfish89 commented Feb 10, 2023

Summary

with the test of sim:lua ,I have fixed some bug of error output
1.input: " " and error output string is "NULL"
2.input: "1.2e+", error output string is "NULL"
3.input: "." error output string is "NULL"

Impact

Testing

  char *a = "    n";
  char *b;
  float number = strtof(a,&b);
  syslog(LOG_INFO,"string is %s\n number is %f and string is %s\n",a,number,b);

  a = " 10  nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);
  a = "2nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);
  a = " 3e0 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);
  a = "1.0e+nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);
  a = "2 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);
  a = "2nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);
  a = "-2 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"astring is %s\nnumber is %f and string is %s\n",a,number,b);
  a = " -0xa nsh";
  number = strtof(a,&b);
  syslog(LOG_INFO,"astring is %s\n number is %f and string is %s\n",a,number,b);
  a = "+0.01 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"astring is %s\nnumber is %f and string is %s\n",a,number,b);
  a = "+.01 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"astring is %s\nnumber is %f and string is %s\n",a,number,b);
  a = ".01 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"astring is %s\nnumber is %f and string is %s\n",a,number,b); 
 a = "-1. nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"astring is %s\nnumber is %f and string is %s\n",a,number,b);
  a = "+1. nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"astring is %s\nnumber is %f and string is %s\n",a,number,b);
  a = "+ 0.01 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"astring is %s\nnumber is %f and string is %s\n",a,number,b); 
 a = "+.e1 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);
  a = "1e nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "1.0e+ nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = ". nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "nan";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "-012 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "-1.2e2 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "e1 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "0xffffffffffff nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "x";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "0xffffffffffff nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "0x3. nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "0x0. nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "-0xfFfa nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "0xffffFFFF nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "0x.0p-3";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "0ffffFFFF nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "+0x2 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "-0xaA nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "-0xffFFFfff nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "0E+1 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "0E+1 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "0xe-1 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "  0x2.5 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "  -0x2.5 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "0x0.51p nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "0x.00000001 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "0xA.a nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "0xa.aP4 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "0x4P-2 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "0x1.1 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "1. nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = ".1 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "0.001e+3 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "1111111111111110 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "1111111111111111 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "+1.23E18 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = " 1.3e-2  nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = " -1.00000000000001 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "10 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  a = "20 nsh";
  number = strtof(a,&b);
 syslog(LOG_INFO,"string is %s\nnumber is %f and string is %s\n",a,number,b);  

  with the test of sim:lua ,I have fixed some bug of error output
  1.input: "  " and error output string is "NULL"
  2.input: "1.2e+", error output string is "NULL"
  3.input: "."      error output string is "NULL"
@xiaoxiang781216 xiaoxiang781216 merged commit 2334484 into apache:master Feb 10, 2023
@fjpanag
Copy link
Copy Markdown
Contributor

fjpanag commented Feb 11, 2023

@flyingfish89 Thank you for this.

Just to provide some feedback, after this patch, all tests pass, apart from specifically the following:

assert(tonumber'+ 0.01' == nil and tonumber'+.e1' == nil and
       tonumber'1e' == nil     and tonumber'1.0e+' == nil and
       tonumber'.' == nil)

I think this is the only one left.

@flyingfish89
Copy link
Copy Markdown
Contributor Author

@flyingfish89 Thank you for this.

Just to provide some feedback, after this patch, all tests pass, apart from specifically the following:

assert(tonumber'+ 0.01' == nil and tonumber'+.e1' == nil and
       tonumber'1e' == nil     and tonumber'1.0e+' == nil and
       tonumber'.' == nil)

I think this is the only one left.

yes,i have tried these,and i have found if " '1.0e+' == nil " is wrong ,because it will return 1.0 and "+"

@flyingfish89
Copy link
Copy Markdown
Contributor Author

Oh, this "e" should be returned, coule you change the strtold.c like this and try again
屏幕截图 2023-02-11 230336

@fjpanag
Copy link
Copy Markdown
Contributor

fjpanag commented Feb 11, 2023

Well... After applying this change, a get a previous test failing:

assert(0e12 == 0 and .0 == 0 and 0. == 0 and .2e2 == 20 and 2.E-1 == 0.2)

with:

math.lua:5: malformed number near '2.E-1'

@flyingfish89
Copy link
Copy Markdown
Contributor Author

ok,how about this
屏幕截图 2023-02-11 233815

@fjpanag
Copy link
Copy Markdown
Contributor

fjpanag commented Feb 11, 2023

Unfortunatelly not...

assert(string.format("%+08d", 2^31 - 1) == "+2147483647")

fails with:

strings.lua:154: malformed number near '2'

@flyingfish89
Copy link
Copy Markdown
Contributor Author

i'm sorry.i have tried this and i couldn't found any question,could you please show me about it!

@flyingfish89
Copy link
Copy Markdown
Contributor Author

also,i have trid this
屏幕截图 2023-02-12 002830

@fjpanag
Copy link
Copy Markdown
Contributor

fjpanag commented Feb 11, 2023

Maybe I did a typo? Can you please post as code, instead of a screenshot?

@flyingfish89
Copy link
Copy Markdown
Contributor Author

yes
屏幕截图 2023-02-12 003347
and this is the return
屏幕截图 2023-02-12 003452

@flyingfish89
Copy link
Copy Markdown
Contributor Author

em...,this mistake have no connection with what I just modified

@fjpanag
Copy link
Copy Markdown
Contributor

fjpanag commented Feb 21, 2023

@flyingfish89 sorry for the long delay, I was concentrating on other issues.

I applied your above change:

  if (((c | 32) == 'e' && isdigit(*f)) || ((*f == '+' || *f == '-') && (isdigit(*(f + 1)))))
    {
      num_decimal = scanexp(&f, 1) + num_decimal;
      if (num_decimal <= llong_min / 100)
        {
          ifexist(endptr, f);
          return zero;
        }
    }

And indeed I get:

strings.lua:154: malformed number near '2'

If I remove this change, this test passes. So the error is only triggered with this change.


I tried the same test with sim:lua.
The error remains identical:

image

@flyingfish89
Copy link
Copy Markdown
Contributor Author

if ((c | 32) == 'e' && (isdigit(*f) || ((*f == '+' || *f == '-') && (isdigit(*(f + 1))))))
how about this

@fjpanag
Copy link
Copy Markdown
Contributor

fjpanag commented Feb 21, 2023

@flyingfish89 Yes! That did the trick!
All tests now pass.

Can you please provide a PR for this?

@flyingfish89
Copy link
Copy Markdown
Contributor Author

ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants