tempfile: replace die("BUG") with BUG()
Compared to die(), using BUG() triggers abort(). That may give us an actual coredump, which should make it easier to get a stack trace. And since the programming error for these assertions is not in the functions themselves but in their callers, such a stack trace is needed to actually find the source of the bug. In addition, abort() raises SIGABRT, which is more likely to be caught by our test suite. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Sep 5, 2017 at 08:14 UTC
9b028aa45a2016ae0dbdfeb85ad9d43f2017db0d
1 file changed
+10
-10
tempfile.c
+10
-10
@@ -96,7 +96,7 @@ static void prepare_tempfile_object(struct tempfile *tempfile)
96
}
97
98
if (is_tempfile_active(tempfile))
99
- die("BUG: prepare_tempfile_object called for active object");
99
+ BUG("prepare_tempfile_object called for active object");
100
if (!tempfile->on_list) {
101
/* Initialize *tempfile and add it to tempfile_list: */
102
tempfile->fd = -1;
@@ -109,7 +109,7 @@ static void prepare_tempfile_object(struct tempfile *tempfile)
109
tempfile->on_list = 1;
110
} else if (tempfile->filename.len) {
111
/* This shouldn't happen, but better safe than sorry. */
112
- die("BUG: prepare_tempfile_object called for improperly-reset object");
112
+ BUG("prepare_tempfile_object called for improperly-reset object");
113
}
114
}
115
@@ -205,9 +205,9 @@ int xmks_tempfile_m(struct tempfile *tempfile, const char *template, int mode)
205
FILE *fdopen_tempfile(struct tempfile *tempfile, const char *mode)
206
{
207
if (!is_tempfile_active(tempfile))
208
- die("BUG: fdopen_tempfile() called for inactive object");
208
+ BUG("fdopen_tempfile() called for inactive object");
209
if (tempfile->fp)
210
- die("BUG: fdopen_tempfile() called for open object");
210
+ BUG("fdopen_tempfile() called for open object");
211
212
tempfile->fp = fdopen(tempfile->fd, mode);
213
return tempfile->fp;
@@ -216,21 +216,21 @@ FILE *fdopen_tempfile(struct tempfile *tempfile, const char *mode)
216
const char *get_tempfile_path(struct tempfile *tempfile)
217
{
218
if (!is_tempfile_active(tempfile))
219
- die("BUG: get_tempfile_path() called for inactive object");
219
+ BUG("get_tempfile_path() called for inactive object");
220
return tempfile->filename.buf;
221
}
222
223
int get_tempfile_fd(struct tempfile *tempfile)
224
{
225
if (!is_tempfile_active(tempfile))
226
- die("BUG: get_tempfile_fd() called for inactive object");
226
+ BUG("get_tempfile_fd() called for inactive object");
227
return tempfile->fd;
228
}
229
230
FILE *get_tempfile_fp(struct tempfile *tempfile)
231
{
232
if (!is_tempfile_active(tempfile))
233
- die("BUG: get_tempfile_fp() called for inactive object");
233
+ BUG("get_tempfile_fp() called for inactive object");
234
return tempfile->fp;
235
}
236
@@ -265,9 +265,9 @@ int close_tempfile_gently(struct tempfile *tempfile)
265
int reopen_tempfile(struct tempfile *tempfile)
266
{
267
if (!is_tempfile_active(tempfile))
268
- die("BUG: reopen_tempfile called for an inactive object");
268
+ BUG("reopen_tempfile called for an inactive object");
269
if (0 <= tempfile->fd)
270
- die("BUG: reopen_tempfile called for an open object");
270
+ BUG("reopen_tempfile called for an open object");
271
tempfile->fd = open(tempfile->filename.buf, O_WRONLY);
272
return tempfile->fd;
273
}
@@ -275,7 +275,7 @@ int reopen_tempfile(struct tempfile *tempfile)
275
int rename_tempfile(struct tempfile *tempfile, const char *path)
276
{
277
if (!is_tempfile_active(tempfile))
278
- die("BUG: rename_tempfile called for inactive object");
278
+ BUG("rename_tempfile called for inactive object");
279
280
if (close_tempfile_gently(tempfile)) {
281
delete_tempfile(tempfile);