summaryrefslogtreecommitdiff
path: root/rts
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2019-07-26 10:32:25 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-08-02 22:20:50 -0400
commit4664bafcb8db9f7cbcc9d16b0b1d381650b682c2 (patch)
tree5a0e87b51c6a8e5d730953df94765c6e23cb803c /rts
parent0ecacb1ee6d353f85b83a63941b6e26f1ff9f4db (diff)
downloadhaskell-4664bafcb8db9f7cbcc9d16b0b1d381650b682c2.tar.gz
rts: Always truncate output files
Previously there were numerous places in the RTS where we would fopen with the "w" flag string. This is wrong as it will not truncate the file. Consequently if we write less data than the previous length of the file we will leave garbage at its end. Fixes #16993.
Diffstat (limited to 'rts')
-rw-r--r--rts/Hpc.c2
-rw-r--r--rts/ProfHeap.c2
-rw-r--r--rts/Profiling.c2
-rw-r--r--rts/RtsFlags.c4
-rw-r--r--rts/eventlog/EventLogWriter.c2
5 files changed, 6 insertions, 6 deletions
diff --git a/rts/Hpc.c b/rts/Hpc.c
index 9ba9b04b61..abf85430ac 100644
--- a/rts/Hpc.c
+++ b/rts/Hpc.c
@@ -388,7 +388,7 @@ exitHpc(void) {
// not clober the .tix file.
if (hpc_pid == getpid()) {
- FILE *f = __rts_fopen(tixFilename,"w");
+ FILE *f = __rts_fopen(tixFilename,"w+");
writeTix(f);
}
diff --git a/rts/ProfHeap.c b/rts/ProfHeap.c
index 1023f7ccbe..cc99e37fdc 100644
--- a/rts/ProfHeap.c
+++ b/rts/ProfHeap.c
@@ -385,7 +385,7 @@ initHeapProfiling(void)
sprintf(hp_filename, "%s.hp", prog);
/* open the log file */
- if ((hp_file = __rts_fopen(hp_filename, "w")) == NULL) {
+ if ((hp_file = __rts_fopen(hp_filename, "w+")) == NULL) {
debugBelch("Can't open profiling report file %s\n",
hp_filename);
RtsFlags.ProfFlags.doHeapProfile = 0;
diff --git a/rts/Profiling.c b/rts/Profiling.c
index f340a63cff..b91129ed98 100644
--- a/rts/Profiling.c
+++ b/rts/Profiling.c
@@ -263,7 +263,7 @@ initProfilingLogFile(void)
sprintf(prof_filename, "%s.prof", stem);
/* open the log file */
- if ((prof_file = __rts_fopen(prof_filename, "w")) == NULL) {
+ if ((prof_file = __rts_fopen(prof_filename, "w+")) == NULL) {
debugBelch("Can't open profiling report file %s\n", prof_filename);
RtsFlags.CcFlags.doCostCentres = 0;
// Retainer profiling (`-hr` or `-hr<cc> -h<x>`) writes to
diff --git a/rts/RtsFlags.c b/rts/RtsFlags.c
index 8d9b052bc7..5cdf08e9a5 100644
--- a/rts/RtsFlags.c
+++ b/rts/RtsFlags.c
@@ -1745,7 +1745,7 @@ openStatsFile (char *filename, // filename, or NULL
f = NULL; /* NULL means use debugBelch */
} else {
if (*filename != '\0') { /* stats file specified */
- f = __rts_fopen (filename,"w");
+ f = __rts_fopen (filename,"w+");
} else {
if (filename_fmt == NULL) {
errorBelch("Invalid stats filename format (NULL)\n");
@@ -1755,7 +1755,7 @@ openStatsFile (char *filename, // filename, or NULL
char stats_filename[STATS_FILENAME_MAXLEN];
snprintf(stats_filename, STATS_FILENAME_MAXLEN, filename_fmt,
prog_name);
- f = __rts_fopen (stats_filename,"w");
+ f = __rts_fopen (stats_filename,"w+");
}
if (f == NULL) {
errorBelch("Can't open stats file %s\n", filename);
diff --git a/rts/eventlog/EventLogWriter.c b/rts/eventlog/EventLogWriter.c
index 9f6f487d8e..4b486926a7 100644
--- a/rts/eventlog/EventLogWriter.c
+++ b/rts/eventlog/EventLogWriter.c
@@ -82,7 +82,7 @@ initEventLogFileWriter(void)
char *event_log_filename = outputFileName();
/* Open event log file for writing. */
- if ((event_log_file = __rts_fopen(event_log_filename, "wb")) == NULL) {
+ if ((event_log_file = __rts_fopen(event_log_filename, "wb+")) == NULL) {
sysErrorBelch(
"initEventLogFileWriter: can't open %s", event_log_filename);
stg_exit(EXIT_FAILURE);