![]() |
|
|
#1 |
|
May 2014
1000012 Posts |
In mprime / prime95 "commona.c"
Signed integer overflow is undefined behavior. Also, don't bother to check Y2038 if the system's time_t is 64-bits. Code:
diff -r -u a/commona.c b/commona.c
--- a/commona.c 2016-09-14 12:31:33.000000000 +0800
+++ b/commona.c 2017-02-22 16:36:51.665687758 +0800
@@ -163,13 +163,13 @@ void rangeStatusMessage (char *buf, unsigned int buflen)
"PRP");
buf += strlen (buf);
- time (&this_time);
- if (est + this_time < 2147483640) {
+ this_time = time (NULL);
+ if (sizeof(this_time) > 4 || this_time < 2147483647L - (long) est) {
this_time += (long) est;
strcpy (timebuf, ctime (&this_time));
safe_strcpy (timebuf+16, timebuf+19);
} else
- strcpy (timebuf, "after Jan 1 2038\n");
+ strcpy (timebuf, "after Jan 19 2038\n");
sprintf (buf, ", %s", timebuf);
buf += strlen (buf);
lines_output++;
|
|
|
|
|
|
#2 |
|
May 2014
3·11 Posts |
Oops. I mis-typed the <= comparison to <.
It should be Code:
this_time <= 2147483647L - (long) est |
|
|
|
|
|
#3 |
|
May 2014
3×11 Posts |
Sorry. Patch revised again. This time I found out that original formula didn't cause overflow that I expected (it was compared as "double" type), but anyway it's better to make the (double) cast explicit:
Code:
diff -r -u a/commona.c b/commona.c
--- a/commona.c 2016-09-14 12:31:33.000000000 +0800
+++ b/commona.c 2017-02-22 23:09:26.498184038 +0800
@@ -163,13 +163,13 @@
"PRP");
buf += strlen (buf);
- time (&this_time);
- if (est + this_time < 2147483640) {
+ this_time = time (NULL);
+ if ((double) this_time < 2147483648.0 - est) {
this_time += (long) est;
strcpy (timebuf, ctime (&this_time));
safe_strcpy (timebuf+16, timebuf+19);
} else
- strcpy (timebuf, "after Jan 1 2038\n");
+ strcpy (timebuf, "after Jan 19 2038\n");
sprintf (buf, ", %s", timebuf);
buf += strlen (buf);
lines_output++;
|
|
|
|
|
|
#4 |
|
"Ram Shanker"
May 2015
Delhi
2×19 Posts |
I will be forever waiting for Prime95 to be on GitHub. :)
|
|
|
|
|
|
#5 |
|
Dec 2016
73 Posts |
That would be a great thing. Exchanging diffs feels like we're back in the 1990s.
Plus, all you need to do to merge a pull request is press a button. Applying a diff that was posted in a forum is much more work. Plus, if this was a pull request on Github, tools like Travis CI would already have told us if this change breaks the build or not. |
|
|
|
|
|
#6 |
|
Serpentine Vermin Jar
Jul 2014
1100111011112 Posts |
I won't pretend to speak for George but since the source is available he might be fine with someone else getting it setup on GitHub, just to start the ball rolling.
Whether he would then stick to that and use that for checking in, merging, pull requests, etc. I have no idea but I know if it were me, I'd be happy to have someone else do that work for me. LOL I'm not a coder and I've never setup a project on GitHub so I really don't know what's involved and maybe it's simpler than I'm imagining. |
|
|
|
|
|
#7 |
|
May 2014
3×11 Posts |
Well honestly, the reason I hack the code is to modify mprime for a "totally offline" build for inclusion in the Ultimate Boot CD. And unfortunately when I study the code I discover bugs and/or problematic code.
Like many open-source projects, it is good to submit patches to be included upstream so that I can save time maintaining my mod, each time a new upstream version is released. |
|
|
|
|
|
#8 | ||
|
Dec 2016
73 Posts |
Quote:
But it is not about having the code of the releases on Github. It is about having the project on Github, i.e. the commit history, pull requests, tickets and so on. Quote:
In the most simple case, you can then use your Github repo like good old SVN with the additional bonus of having pull requests from helpful people like Explorer09. I would even try to get tests run automatically on Travis CI, but that is only useful if all commits go to the Github repo. |
||
|
|
|
|
|
#9 | ||
|
P90 years forever!
Aug 2002
Yeehaw, FL
165468 Posts |
Quote:
Quote:
|
||
|
|
|
![]() |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Patch] Fix strcpy misuse in getProxyInfo() | Explorer09 | Software | 1 | 2017-03-01 22:03 |
| (patch) No need for fmt_mask[] buffer | Explorer09 | Software | 12 | 2015-09-23 22:22 |
| v1.40 patch for massive NFS oversieving | jasonp | Msieve | 18 | 2009-04-09 03:20 |
| First check and double check llrnet servers. | opyrt | Prime Sierpinski Project | 3 | 2009-01-02 01:50 |
| Amd patch | moo | Hardware | 6 | 2005-10-10 23:29 |