[Bug libbacktrace/81983] libbacktrace calls bsearch with NULL base

vries at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Feb 11 10:37:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81983

--- Comment #4 from Tom de Vries <vries at gcc dot gnu.org> ---
Ian, how do you want this fixed?

We could add a safe_bsearch:
...
diff --git a/libbacktrace/internal.h b/libbacktrace/internal.h
index 065b9535e8b..7d9aa5e88c5 100644
--- a/libbacktrace/internal.h
+++ b/libbacktrace/internal.h
@@ -317,4 +317,13 @@ extern int backtrace_uncompress_zdebug (struct
backtrace_state *,
                                        unsigned char **uncompressed,
                                        size_t *uncompressed_size);

+static inline void *
+safe_bsearch (const void *key, const void *base, size_t nel, size_t width,
+             int (*compar)(const void *, const void *))
+{
+  return (base == NULL
+         ? NULL
+         : bsearch (key, base, nel, width, compar));
+}
+
 #endif
...
and do a:
...
$ sed -i \
    "s/bsearch (/safe_bsearch (/g" \
    libbacktrace/*
...


More information about the Gcc-bugs mailing list