Fix a fun bug where, every now again, ego would get its temporary files mangled
authorDavid Given <dg@cowlark.com>
Mon, 22 Aug 2016 21:53:01 +0000 (23:53 +0200)
committerDavid Given <dg@cowlark.com>
Mon, 22 Aug 2016 21:53:01 +0000 (23:53 +0200)
and generate invalid calls to the optimisers.

Previously ego would generate a temporary file template that looked like
/tmp/ego.A.BB.XXXXXX, call mktemp() on it to randomise the XXXXXX, and then
replace A and BB with data.

However, it used strrchr to find the A and B. Which would fine, except when
mktemp produced an A or a B in the randomised part...

This code was written on 4 March 1991. I was 16.

util/ego/em_ego/em_ego.c

index 5475618..60a99ea 100644 (file)
@@ -418,8 +418,9 @@ int main(int argc, char* argv[])
        (void)strcat(pdump, "/ego.pd.XXXXXX");
        (void)mktemp(pdump);
 
-       (void)strcat(tmpbufs[0], "/ego.A.BB.XXXXXX");
+       (void)strcat(tmpbufs[0], "/ego.XXXXXX");
        (void)mktemp(tmpbufs[0]);
+       (void)strcat(tmpbufs[0], ".A.BB");
        for (i = 2 * NTEMPS - 1; i >= 1; i--)
        {
                (void)strcpy(tmpbufs[i], tmpbufs[0]);