From: Aurelien Jacobs Date: Sun, 14 Aug 2016 23:28:55 +0000 (+0200) Subject: drivers: don't try to access the sr_driver_list section with no driver compiled. X-Git-Tag: libsigrok-0.5.0~280 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=bf85ea2110f5fc798841b7d912ad6d961c28d6b3;p=libsigrok.git drivers: don't try to access the sr_driver_list section with no driver compiled. This closes bug #820. --- diff --git a/configure.ac b/configure.ac index c5089f1d..94e54572 100644 --- a/configure.ac +++ b/configure.ac @@ -211,7 +211,7 @@ m4_define([_SR_DRIVER], [ sr_driver_summary_append "$2" "$sr_hw_info" AM_CONDITIONAL([$3], [test "x[$]$3" = xyes]) - AM_COND_IF([$3], [AC_DEFINE([HAVE_$3], [1], [Whether to support $1 device.])]) + AM_COND_IF([$3], [AC_DEFINE([HAVE_$3], [1], [Whether to support $1 device.]) AC_DEFINE([HAVE_DRIVERS], [1], [Whether at least one driver is enabled.])]) ]) ## SR_DRIVER(Device name, driver-name, [dependencies...]) diff --git a/src/drivers.c b/src/drivers.c index a5c21a08..d2763414 100644 --- a/src/drivers.c +++ b/src/drivers.c @@ -18,6 +18,7 @@ * along with this program. If not, see . */ +#include #include #include #include "libsigrok-internal.h" @@ -44,13 +45,14 @@ extern struct sr_dev_driver *__stop_sr_driver_list; */ SR_API void sr_drivers_init(struct sr_context *ctx) { - struct sr_dev_driver **drivers; GArray *array; array = g_array_new(TRUE, FALSE, sizeof(struct sr_dev_driver *)); - for (drivers = &__start_sr_driver_list; drivers < &__stop_sr_driver_list; - drivers++) +#ifdef HAVE_DRIVERS + for (struct sr_dev_driver **drivers = &__start_sr_driver_list; + drivers < &__stop_sr_driver_list; drivers++) g_array_append_val(array, *drivers); +#endif ctx->driver_list = (struct sr_dev_driver **)array->data; g_array_free(array, FALSE); }