mersenneforum.org  

Go Back   mersenneforum.org > Great Internet Mersenne Prime Search > Software

Reply
 
Thread Tools
Old 2017-02-22, 08:47   #1
Explorer09
 
May 2014

3·11 Posts
Default [Patch] Fix rangeStatusMessage() Y2038 check code

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++;
Explorer09 is offline   Reply With Quote
Old 2017-02-22, 11:17   #2
Explorer09
 
May 2014

3×11 Posts
Default

Oops. I mis-typed the <= comparison to <.

It should be
Code:
this_time <= 2147483647L - (long) est
instead. This will allow the compiler to optimize it into an OF (overflow flag) check.
Explorer09 is offline   Reply With Quote
Old 2017-02-22, 15:14   #3
Explorer09
 
May 2014

3·11 Posts
Default [Patch v2] Fix rangeStatusMessage() Y2038 check code

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++;
Explorer09 is offline   Reply With Quote
Old 2017-02-23, 15:21   #4
ramshanker
 
ramshanker's Avatar
 
"Ram Shanker"
May 2015
Delhi

3810 Posts
Default

I will be forever waiting for Prime95 to be on GitHub. :)
ramshanker is offline   Reply With Quote
Old 2017-02-23, 19:51   #5
nordi
 
Dec 2016

71 Posts
Default

Quote:
Originally Posted by ramshanker View Post
I will be forever waiting for Prime95 to be on GitHub. :)
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.
nordi is online now   Reply With Quote
Old 2017-02-24, 04:04   #6
Madpoo
Serpentine Vermin Jar
 
Madpoo's Avatar
 
Jul 2014

329310 Posts
Default

Quote:
Originally Posted by ramshanker View Post
I will be forever waiting for Prime95 to be on GitHub. :)
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.
Madpoo is offline   Reply With Quote
Old 2017-02-24, 07:52   #7
Explorer09
 
May 2014

1000012 Posts
Default

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.
Explorer09 is offline   Reply With Quote
Old 2017-02-24, 23:58   #8
nordi
 
Dec 2016

1078 Posts
Default

Quote:
Originally Posted by Madpoo View Post
Whether he would then stick to that and use that for checking in, merging, pull requests, etc. I have no idea
Someone has already copied it to Github: https://github.com/rudimeier/mprime Although I think it is not quite 100% complete.

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:
Originally Posted by Madpoo View Post
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.
Merely setting it up is zero effort. You register, upload your code and you're done.

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.
nordi is online now   Reply With Quote
Old 2017-03-01, 02:41   #9
Prime95
P90 years forever!
 
Prime95's Avatar
 
Aug 2002
Yeehaw, FL

7·1,069 Posts
Default

Quote:
Originally Posted by Explorer09 View Post
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:
Fixed.

Quote:
Originally Posted by nordi View Post
That would be a great thing. Exchanging diffs feels like we're back in the 1990s.
I'm an old fart apparently incapable of learning fancy new things like Github.
Prime95 is offline   Reply With Quote
Reply

Thread Tools


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

All times are UTC. The time now is 22:26.

Wed May 5 22:26:00 UTC 2021 up 27 days, 17:06, 0 users, load averages: 3.25, 2.78, 2.74

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.