summaryrefslogtreecommitdiff
path: root/lib/libexecinfo
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2020-07-26 15:53:05 +0000
committerchristos <christos@NetBSD.org>2020-07-26 15:53:05 +0000
commit8d2eda18e9e84fa1195af0dec45edb0fc8b26167 (patch)
treee1c3c5e11eff1217ef3ee56d7784a2a281804124 /lib/libexecinfo
parent3920609e98e0911ca95aa2fca9199f648a787850 (diff)
If Unwind_Backtrace is broken, ctx.n will still contain ~0, and we will
return that which poor behavior for the user, so return 0 instead. We could document ~0 to be an error, but that would deviate from the Linux behavior which is not desirable. Noted by Poul-Henning Kamp
Diffstat (limited to 'lib/libexecinfo')
-rw-r--r--lib/libexecinfo/unwind.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/libexecinfo/unwind.c b/lib/libexecinfo/unwind.c
index f12c1ba67f7..ec85141bcb8 100644
--- a/lib/libexecinfo/unwind.c
+++ b/lib/libexecinfo/unwind.c
@@ -1,4 +1,4 @@
-/* $NetBSD: unwind.c,v 1.4 2020/01/22 16:07:40 mgorny Exp $ */
+/* $NetBSD: unwind.c,v 1.5 2020/07/26 15:53:05 christos Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -67,7 +67,9 @@ backtrace(void **arr, size_t len)
ctx.n = (size_t)~0;
_Unwind_Backtrace(tracer, &ctx);
- if (ctx.n != (size_t)~0 && ctx.n > 0)
+ if (ctx.n == (size_t)~0)
+ ctx.n = 0;
+ else if (ctx.n > 0)
ctx.arr[--ctx.n] = NULL; /* Skip frame below __start */
return ctx.n;