oils-for-unix / oils

Oils is our upgrade path from bash to a better language and runtime. It's also for Python and JavaScript users who avoid shell!
http://www.oilshell.org/
Other
2.85k stars 159 forks source link

printf crashes with ValueError when integers are large #2107

Open ale5000-git opened 3 weeks ago

ale5000-git commented 3 weeks ago

Oils 0.23.0 installed with brew install --quiet oils-for-unix.

Currently this works: printf '%u\n' '9223372036854775807' but this: printf '%u\n' '18446744073709551615' instead give this error: libc++abi: terminating due to uncaught exception of type ValueError*

I think it is better if the code check what is really requested. For "%d" and "%i" I think it should be cast to "long long", instead for "%u", "%o" and "%x" it should be cast to "unsigned long long" so that it will allow to use the full unsigned range.

andychu commented 3 weeks ago

Thanks for the report! I reproduced this

andychu commented 3 weeks ago

I fixed Oils to check bounds

Unfortunately it doesn't distinguish between signed and unsigned now, so these are errors

We're looking into:

(details on Zulip)

Thanks for the report!

  printf %d 18446744073709551616                                                                                                           
         ^                                                           
[ -c flag ]:1: fatal: Integer too big: 18446744073709551616          

  printf %d -18446744073709551616                                                                                                          
         ^                                                           
[ -c flag ]:1: fatal: Integer too big: -18446744073709551616