After building from source, mk.exe instantly crashes on startup

Issue #307 resolved
Former user created an issue

Original issue 307 created by inferno-os on 2014-02-15T22:04:10.000Z:

Download snapshot from vitanuova, use HG to pull newest version, run existing Nt/386/MK to rebuild everything, try running newly-built utils/mk/obj.out

Effect: crash, classic 0xc000005 AccessViolation

OS/Compiler: Win7, VisualStudio 2010

The problem sits in utils/mk/run.c which uses time() in usage() function. On "modern Windows" the time_t has been extended to 64 bits, while the code in usage() tries to pass a pointer to long (32 bit). It compiles with just a warning, but results in stack damage and crash.

I'm not accustomed with HG & Code.Google hosting, and I don't have account, so I'm pasting a simple patch here.

There are two changes in the patch, sorry, I overlooked it. The important one is the second. The first is just cosmetics.

# HG changeset patch
# User quetzalcoatl
# Date 1392500938 -3600
#      Sat Feb 15 22:48:58 2014 +0100
# Node ID b92af84d0c333433a4954bf45a37345a39644dfc
# Parent  0e50cfeb0da567b56adbd3a0897de4aeacc7a2a9
On recent new Nt system the time_t is no longer 'long/32 bit'
but actually it's 64-bit now, so passing &long was causing
instant crash due to obvious stack damage.

diff -r 0e50cfeb0da5 -r b92af84d0c33 utils/mk/run.c
--- a/utils/mk/run.c    Sun Jan 05 22:03:10 2014 +0000
+++ b/utils/mk/run.c    Sat Feb 15 22:48:58 2014 +0100
@@ -71,7 +71,7 @@
                                else if(explain)
                                        Bprint(&bout, "no touch of virtual '%s'\n", n->name);
                        }
-                       n->time = time((long *)0);
+                       n->time = time((time_t *)0);
                        MADESET(n, MADE);
                }
        } else {
@@ -278,7 +278,7 @@
 void
 usage(void)
 {
-       long t;
+       time_t t;

        time(&t);
        if(tick)

Comments (2)

  1. Charles Forsyth

    I've changed it to avoid the problem by using the return value instead of passing a pointer, since the compiler will choose the correct type from the prototype.

  2. Log in to comment