X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fscpi%2Fscpi.c;h=9f5dba43ae493a5b4558b1970186c07ddd69b417;hb=ffa5f177f15dd8c75612d65b20459e7cdccc68b9;hp=0efde8bab7b9c11f8d2cec00ee48f1afd0ecac4f;hpb=e57057aee778e723da572a6b5e2bd01526cc7beb;p=libsigrok.git diff --git a/src/scpi/scpi.c b/src/scpi/scpi.c index 0efde8ba..9f5dba43 100644 --- a/src/scpi/scpi.c +++ b/src/scpi/scpi.c @@ -110,12 +110,16 @@ static struct sr_dev_inst *sr_scpi_scan_resource(struct drv_context *drvc, return NULL; }; - if ((sdi = probe_device(scpi))) - return sdi; + sdi = probe_device(scpi); sr_scpi_close(scpi); - sr_scpi_free(scpi); - return NULL; + + if (sdi) + sdi->status = SR_ST_INACTIVE; + else + sr_scpi_free(scpi); + + return sdi; } SR_PRIV GSList *sr_scpi_scan(struct drv_context *drvc, GSList *options, @@ -292,8 +296,10 @@ SR_PRIV int sr_scpi_send_variadic(struct sr_scpi_dev_inst *scpi, va_end(args_copy); /* Allocate buffer and write out command. */ - buf = g_malloc(len + 1); + buf = g_malloc0(len + 2); vsprintf(buf, format, args); + if (buf[len - 1] != '\n') + buf[len] = '\n'; /* Send command. */ ret = scpi->send(scpi->priv, buf); @@ -575,7 +581,7 @@ SR_PRIV int sr_scpi_get_opc(struct sr_scpi_dev_inst *scpi) unsigned int i; gboolean opc; - for (i = 0; i < SCPI_READ_RETRIES; ++i) { + for (i = 0; i < SCPI_READ_RETRIES; i++) { sr_scpi_get_bool(scpi, SCPI_CMD_OPC, &opc); if (opc) return SR_OK;