[PATCH 0/2] replace die("BUG: ...") with BUG("...")

STALE1717d

Revision v1 of 2 in this series.

8 messages, 1 author, 2021-12-07 · open the first message on its own page

[PATCH 0/2] replace die("BUG: ...") with BUG("...")

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-12-06 16:26:13

A trivial clean-up to change a couple of die() uses to BUG() where
appropriate. This is split off from an earlier RFC series I sent
in[1], as the range-diff to the relevant patches there shown there are
no changes since then.

1. https://lore.kernel.org/git/RFC-patch-07.21-3f897bf6b0e-20211115T220831Z-avarab@gmail.com/

Ævar Arnfjörð Bjarmason (2):
  pack-objects: use BUG(...) not die("BUG: ...")
  strbuf.h: use BUG(...) not die("BUG: ...")

 builtin/pack-objects.c | 2 +-
 strbuf.h               | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Range-diff:
1:  2507ea71700 = 1:  2a17ed9f135 pack-objects: use BUG(...) not die("BUG: ...")
2:  5dedcee3fb0 = 2:  ab89fec50c3 strbuf.h: use BUG(...) not die("BUG: ...")
-- 
2.34.1.898.g5a552c2e5f0

[PATCH 1/2] pack-objects: use BUG(...) not die("BUG: ...")

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-12-06 16:26:13

Change this code added in da93d12b004 (pack-objects: be incredibly
anal about stdio semantics, 2006-04-02) to use BUG() instead.

See 1a07e59c3e2 (Update messages in preparation for i18n, 2018-07-21)
for when the "BUG: " prefix was added, and [1] for background on the
Solaris behavior that prompted the exhaustive error checking in this
fgets() loop.

1. https://lore.kernel.org/git/824.1144007555@lotus.CS.Berkeley.EDU/

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 builtin/pack-objects.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 857be7826f3..b36ed828d8d 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -3397,7 +3397,7 @@ static void read_object_list_from_stdin(void)
 			if (feof(stdin))
 				break;
 			if (!ferror(stdin))
-				die("BUG: fgets returned NULL, not EOF, not error!");
+				BUG("fgets returned NULL, not EOF, not error!");
 			if (errno != EINTR)
 				die_errno("fgets");
 			clearerr(stdin);
-- 
2.34.1.898.g5a552c2e5f0

[PATCH 2/2] strbuf.h: use BUG(...) not die("BUG: ...")

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-12-06 16:26:14

In 7141efab248 (strbuf: clarify assertion in strbuf_setlen(),
2011-04-27) this 'die("BUG: "' invocation was added with the rationale
that strbuf.c had existing users doing the same, but those users were
later changed to use BUG() in 033abf97fcb (Replace all die("BUG: ...")
calls by BUG() ones, 2018-05-02). Let's do the same here.

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 strbuf.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/strbuf.h b/strbuf.h
index 96512f85b31..76965a17d44 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -160,7 +160,7 @@ void strbuf_grow(struct strbuf *sb, size_t amount);
 static inline void strbuf_setlen(struct strbuf *sb, size_t len)
 {
 	if (len > (sb->alloc ? sb->alloc - 1 : 0))
-		die("BUG: strbuf_setlen() beyond buffer");
+		BUG("strbuf_setlen() beyond buffer");
 	sb->len = len;
 	if (sb->buf != strbuf_slopbuf)
 		sb->buf[len] = '\0';
-- 
2.34.1.898.g5a552c2e5f0

[PATCH v2 0/4] replace die("BUG: ...") with BUG("...")

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-12-07 11:06:30

A re-roll of this trivial clean-up series, now with 2x more patches
for missed cases pointed-out by Junio at
https://lore.kernel.org/git/xmqqsfv5b6u6.fsf@gitster.g/

Ævar Arnfjörð Bjarmason (4):
  pack-objects: use BUG(...) not die("BUG: ...")
  strbuf.h: use BUG(...) not die("BUG: ...")
  pathspec: use BUG(...) not die("BUG:%s:%d....", <file>, <line>)
  object.h: use BUG(...) no die("BUG: ...") in lookup_object_by_type()

 builtin/pack-objects.c | 2 +-
 object.c               | 2 +-
 pathspec.h             | 3 +--
 strbuf.h               | 2 +-
 tree-diff.c            | 3 +--
 5 files changed, 5 insertions(+), 7 deletions(-)

Range-diff against v1:
1:  2a17ed9f135 = 1:  4f39177a763 pack-objects: use BUG(...) not die("BUG: ...")
2:  ab89fec50c3 = 2:  6740c5d0da8 strbuf.h: use BUG(...) not die("BUG: ...")
-:  ----------- > 3:  81e354fa3be pathspec: use BUG(...) not die("BUG:%s:%d....", <file>, <line>)
-:  ----------- > 4:  aaf952a9ede object.h: use BUG(...) no die("BUG: ...") in lookup_object_by_type()
-- 
2.34.1.898.g5a552c2e5f0

[PATCH v2 1/4] pack-objects: use BUG(...) not die("BUG: ...")

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-12-07 11:06:31

Change this code added in da93d12b004 (pack-objects: be incredibly
anal about stdio semantics, 2006-04-02) to use BUG() instead.

See 1a07e59c3e2 (Update messages in preparation for i18n, 2018-07-21)
for when the "BUG: " prefix was added, and [1] for background on the
Solaris behavior that prompted the exhaustive error checking in this
fgets() loop.

1. https://lore.kernel.org/git/824.1144007555@lotus.CS.Berkeley.EDU/

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 builtin/pack-objects.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 857be7826f3..b36ed828d8d 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -3397,7 +3397,7 @@ static void read_object_list_from_stdin(void)
 			if (feof(stdin))
 				break;
 			if (!ferror(stdin))
-				die("BUG: fgets returned NULL, not EOF, not error!");
+				BUG("fgets returned NULL, not EOF, not error!");
 			if (errno != EINTR)
 				die_errno("fgets");
 			clearerr(stdin);
-- 
2.34.1.898.g5a552c2e5f0

[PATCH v2 2/4] strbuf.h: use BUG(...) not die("BUG: ...")

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-12-07 11:06:32

In 7141efab248 (strbuf: clarify assertion in strbuf_setlen(),
2011-04-27) this 'die("BUG: "' invocation was added with the rationale
that strbuf.c had existing users doing the same, but those users were
later changed to use BUG() in 033abf97fcb (Replace all die("BUG: ...")
calls by BUG() ones, 2018-05-02). Let's do the same here.

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 strbuf.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/strbuf.h b/strbuf.h
index 96512f85b31..76965a17d44 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -160,7 +160,7 @@ void strbuf_grow(struct strbuf *sb, size_t amount);
 static inline void strbuf_setlen(struct strbuf *sb, size_t len)
 {
 	if (len > (sb->alloc ? sb->alloc - 1 : 0))
-		die("BUG: strbuf_setlen() beyond buffer");
+		BUG("strbuf_setlen() beyond buffer");
 	sb->len = len;
 	if (sb->buf != strbuf_slopbuf)
 		sb->buf[len] = '\0';
-- 
2.34.1.898.g5a552c2e5f0

[PATCH v2 3/4] pathspec: use BUG(...) not die("BUG:%s:%d....", <file>, <line>)

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-12-07 11:06:34

Change code that was added in 8f4f8f4579f (guard against new pathspec
magic in pathspec matching code, 2013-07-14) to use the BUG() macro
instead of emitting a "fatal" message with the "__FILE__"-name and
"__LINE__"-numbers.

The original code predated the existence of the BUG() function, which
was added in d8193743e08 (usage.c: add BUG() function, 2017-05-12).

Signed-off-by: Junio C Hamano <redacted>
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 pathspec.h  | 3 +--
 tree-diff.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/pathspec.h b/pathspec.h
index 2341dc99010..402ebb80808 100644
--- a/pathspec.h
+++ b/pathspec.h
@@ -58,8 +58,7 @@ struct pathspec {
 #define GUARD_PATHSPEC(ps, mask) \
 	do { \
 		if ((ps)->magic & ~(mask))	       \
-			die("BUG:%s:%d: unsupported magic %x",	\
-			    __FILE__, __LINE__, (ps)->magic & ~(mask)); \
+			BUG("unsupported magic %x", (ps)->magic & ~(mask)); \
 	} while (0)
 
 /* parse_pathspec flags */
diff --git a/tree-diff.c b/tree-diff.c
index 437c98a70e4..69031d7cbae 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -603,8 +603,7 @@ static void try_to_follow_renames(const struct object_id *old_oid,
 	 * about dry-run mode and returns wildcard info.
 	 */
 	if (opt->pathspec.has_wildcard)
-		die("BUG:%s:%d: wildcards are not supported",
-		    __FILE__, __LINE__);
+		BUG("wildcards are not supported");
 #endif
 
 	/* Remove the file creation entry from the diff queue, and remember it */
-- 
2.34.1.898.g5a552c2e5f0

[PATCH v2 4/4] object.h: use BUG(...) no die("BUG: ...") in lookup_object_by_type()

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-12-07 11:06:37

Adjust code added in 7463064b280 (object.h: add
lookup_object_by_type() function, 2021-06-22) to use the BUG()
function.

Signed-off-by: Junio C Hamano <redacted>
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 object.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/object.c b/object.c
index 23a24e678a8..4be82c1e7bc 100644
--- a/object.c
+++ b/object.c
@@ -199,7 +199,7 @@ struct object *lookup_object_by_type(struct repository *r,
 	case OBJ_BLOB:
 		return (struct object *)lookup_blob(r, oid);
 	default:
-		die("BUG: unknown object type %d", type);
+		BUG("unknown object type %d", type);
 	}
 }
 
-- 
2.34.1.898.g5a552c2e5f0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help