X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsigrok.c;h=d8c65c08d39f6b3d8d25bd9794c3d2e57f506029;hb=edd9af8a874ebc9f2a7f02846807229a648917db;hp=eecb54c8c5fd8c1ad8a607358925d1510cdbe233;hpb=21a4ddcc2d66eea59224fd95746c7533b1b1a46d;p=collectd.git diff --git a/src/sigrok.c b/src/sigrok.c index eecb54c8..d8c65c08 100644 --- a/src/sigrok.c +++ b/src/sigrok.c @@ -27,7 +27,6 @@ #include #include #include -#include #include #include @@ -72,11 +71,10 @@ static int sigrok_config_device(oconfig_item_t *ci) struct config_device *cfdev; int i; - if (!(cfdev = malloc(sizeof(struct config_device)))) { - ERROR("sigrok plugin: malloc() failed."); + if (!(cfdev = calloc(1, sizeof(*cfdev)))) { + ERROR("sigrok plugin: calloc failed."); return -1; } - memset(cfdev, 0, sizeof(*cfdev)); if (cf_util_get_string(ci, &cfdev->name)) { free(cfdev); WARNING("sigrok plugin: Invalid device name."); @@ -136,9 +134,9 @@ static int sigrok_config(oconfig_item_t *ci) return 0; } -static char *sigrok_value_type(const struct sr_datafeed_analog *analog) +static const char *sigrok_value_type(const struct sr_datafeed_analog *analog) { - char *s; + const char *s; if (analog->mq == SR_MQ_VOLTAGE) s = "voltage"; @@ -236,14 +234,14 @@ static int sigrok_init_driver(struct config_device *cfdev, drvopts = NULL; if (cfdev->conn) { - if (!(src = malloc(sizeof(struct sr_config)))) + if (!(src = malloc(sizeof(*src)))) return -1; src->key = SR_CONF_CONN; src->data = g_variant_new_string(cfdev->conn); drvopts = g_slist_append(drvopts, src); } if (cfdev->serialcomm) { - if (!(src = malloc(sizeof(struct sr_config)))) + if (!(src = malloc(sizeof(*src)))) return -1; src->key = SR_CONF_SERIALCOMM; src->data = g_variant_new_string(cfdev->serialcomm); @@ -360,10 +358,13 @@ static int sigrok_init(void) return -1; } - if ((status = plugin_thread_create(&sr_thread, NULL, sigrok_read_thread, - NULL)) != 0) { + status = plugin_thread_create(&sr_thread, NULL, sigrok_read_thread, + NULL); + if (status != 0) + { + char errbuf[1024]; ERROR("sigrok plugin: Failed to create thread: %s.", - strerror(status)); + sstrerror (errno, errbuf, sizeof (errbuf))); return -1; } sr_thread_running = TRUE;