Sat Oct 31 22:05:56 2020 UTC ()
make(1): document possible undefined behavior in trace.c with .CURDIR


(rillig)
diff -r1.20 -r1.21 src/usr.bin/make/trace.c

cvs diff -r1.20 -r1.21 src/usr.bin/make/trace.c (expand / switch to unified diff)

--- src/usr.bin/make/trace.c 2020/10/30 20:30:44 1.20
+++ src/usr.bin/make/trace.c 2020/10/31 22:05:56 1.21
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: trace.c,v 1.20 2020/10/30 20:30:44 rillig Exp $ */ 1/* $NetBSD: trace.c,v 1.21 2020/10/31 22:05:56 rillig Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc. 4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Bill Sommerfeld 8 * by Bill Sommerfeld
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -38,47 +38,49 @@ @@ -38,47 +38,49 @@
38 * the lifetime of the process) 38 * the lifetime of the process)
39 * 39 *
40 * Trace_End Finalize tracing (called before make exits) 40 * Trace_End Finalize tracing (called before make exits)
41 * 41 *
42 * Trace_Log Log an event about a particular make job. 42 * Trace_Log Log an event about a particular make job.
43 */ 43 */
44 44
45#include <sys/time.h> 45#include <sys/time.h>
46 46
47#include "make.h" 47#include "make.h"
48#include "job.h" 48#include "job.h"
49#include "trace.h" 49#include "trace.h"
50 50
51MAKE_RCSID("$NetBSD: trace.c,v 1.20 2020/10/30 20:30:44 rillig Exp $"); 51MAKE_RCSID("$NetBSD: trace.c,v 1.21 2020/10/31 22:05:56 rillig Exp $");
52 52
53static FILE *trfile; 53static FILE *trfile;
54static pid_t trpid; 54static pid_t trpid;
55const char *trwd; 55const char *trwd;
56 56
57static const char *evname[] = { 57static const char *evname[] = {
58 "BEG", 58 "BEG",
59 "END", 59 "END",
60 "ERR", 60 "ERR",
61 "JOB", 61 "JOB",
62 "DON", 62 "DON",
63 "INT", 63 "INT",
64}; 64};
65 65
66void 66void
67Trace_Init(const char *pathname) 67Trace_Init(const char *pathname)
68{ 68{
69 if (pathname != NULL) { 69 if (pathname != NULL) {
70 void *dontFreeIt; 70 void *dontFreeIt;
71 trpid = getpid(); 71 trpid = getpid();
 72 /* XXX: This variable may get overwritten later, which
 73 * would make trwd point to undefined behavior. */
72 trwd = Var_Value(".CURDIR", VAR_GLOBAL, &dontFreeIt); 74 trwd = Var_Value(".CURDIR", VAR_GLOBAL, &dontFreeIt);
73 75
74 trfile = fopen(pathname, "a"); 76 trfile = fopen(pathname, "a");
75 } 77 }
76} 78}
77 79
78void 80void
79Trace_Log(TrEvent event, Job *job) 81Trace_Log(TrEvent event, Job *job)
80{ 82{
81 struct timeval rightnow; 83 struct timeval rightnow;
82 84
83 if (trfile == NULL) 85 if (trfile == NULL)
84 return; 86 return;