bitsmanent / snore Goto Github PK
View Code? Open in Web Editor NEWsleep with feedback
License: MIT License
sleep with feedback
License: MIT License
$ ./snore 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d-10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d
00d 00h 00m 00.000s
If you add printf("%f\n",tm);
after https://github.com/clamiax/snore/blob/caad43cde564123b541df3cb2652df55937ac45f/snore.c#L118 you can observe that the number is NaN:
$ ./snore 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d-10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d
-nan
00d 00h 00m 00.000s
This ends up being accidentally safe because all comparisons involving NaN are false, so tm < endtm
is false and the loop is never entered. However, if the loop is ever executed, this would invoke undefined behavior, as demonstrated if you run with ubsan on the branch https://github.com/jpdoyle/snore/tree/nan-unsafety:
$ ./snore 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d-10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d
-nan
snore.c:98:6: runtime error: store to null pointer of type 'char'
For example:
$ ./snore 26000d
fish: “./snore 26000d” terminated by signal SIGSEGV (Address boundary error)
I know the time is not very reasonable, but sleep
handles it fine, and SIGSEGVs are never nice.
sleep(1) supports the sleep inf
syntax, which sleeps indefinitely. This should be supported by snore for two reasons:
In my opinion, snore
without arguments should behave like snore inf
, but I don't know if you are willing to change its behavior at this point.
Apparently, software is never "complete" :)
Hello @clamiax,
If you could tag releases it would help downstream packaging.
Thanks!
snore 0
(with no suffix or any suffix) sleeps for one day, while it should exit immediately, like sleep(1) does.
There's quite a bit on unused space to the right of the counter. Maybe it could be filled with an ASCII progress bar?
(Also, is it possible to hide the days and hours etc. when they aren't used for a counter? They make it more difficult to visually grep what's going on.)
I added undefined behavior sanitization to snore
in a small patch: https://github.com/jpdoyle/snore/tree/ubsan-overflow
With that patch, I can trigger signed integer overflow by doing:
$ ./snore 4294967294.5
snore.c:100:20: runtime error: signed integer overflow: 49710 * 86400 cannot be represented in type 'int'
While compiling on OS X (Darwin Kernel Version 15.6.0, RELEASE_X86_64 x86_64), I get the following error:
snore.c:110:16: error: use of undeclared identifier 'CLOCK_REALTIME'
clock_gettime(CLOCK_REALTIME, &start);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.