]> sigrok.org Git - libsigrok.git/commitdiff
Various NULL-check consistency fixes.
authorUwe Hermann <redacted>
Mon, 23 Mar 2015 19:09:08 +0000 (20:09 +0100)
committerUwe Hermann <redacted>
Tue, 24 Mar 2015 18:30:16 +0000 (19:30 +0100)
16 files changed:
src/ezusb.c
src/hardware/baylibre-acme/api.c
src/hardware/beaglelogic/api.c
src/hardware/fx2lafw/api.c
src/hardware/fx2lafw/dslogic.c
src/hardware/hantek-dso/dso.c
src/hardware/ikalogic-scanalogic2/api.c
src/hardware/link-mso19/api.c
src/hardware/link-mso19/protocol.c
src/hardware/openbench-logic-sniffer/api.c
src/hardware/saleae-logic16/api.c
src/hardware/saleae-logic16/protocol.c
src/scpi/scpi_serial.c
src/scpi/scpi_vxi.c
src/soft-trigger.c
src/strutil.c

index 034c6c9ebf9679e1ea2dd9ba230b251ae1c97c3f..9f40d3b72179e5fd1b2a81afb1c077babc3b986f 100644 (file)
@@ -57,7 +57,7 @@ SR_PRIV int ezusb_install_firmware(libusb_device_handle *hdl,
        unsigned char buf[4096];
 
        sr_info("Uploading firmware at %s", filename);
-       if ((fw = g_fopen(filename, "rb")) == NULL) {
+       if (!(fw = g_fopen(filename, "rb"))) {
                sr_err("Unable to open firmware file %s for reading: %s",
                       filename, strerror(errno));
                return SR_ERR;
index 4bcf772dd3c110b9ad9d7dacf60616d128eb0a07..def373d1e2a34d4c682d14e6c4d286eba615aa26 100644 (file)
@@ -115,7 +115,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
         * Let's assume there's no ACME device present if no probe
         * has been registered.
         */
-       if (sdi->channel_groups == NULL)
+       if (!sdi->channel_groups)
                goto err_out;
 
        devices = g_slist_append(devices, sdi);
index 4fae9b803b507507305d5eaff27f52be704d6d35..5f1d35fc1716f88172024d0795d1d464461c232b 100644 (file)
@@ -365,7 +365,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
                if (devc->limit_samples > 0)
                        pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100;
                devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples);
-               if (devc->stl == NULL)
+               if (!devc->stl)
                        return SR_ERR_MALLOC;
                devc->trigger_fired = FALSE;
        } else
index baa1476d0bbd022ada03d6ed382e31354f5c30cf..04284e507ecfc1833d12492d273450f607bf3569 100644 (file)
@@ -426,7 +426,7 @@ static int dev_close(struct sr_dev_inst *sdi)
        struct sr_usb_dev_inst *usb;
 
        usb = sdi->conn;
-       if (usb->devhdl == NULL)
+       if (!usb->devhdl)
                return SR_ERR;
 
        sr_info("fx2lafw: Closing device on %d.%d (logical) / %s (physical) interface %d.",
@@ -629,7 +629,7 @@ static int start_transfers(const struct sr_dev_inst *sdi)
                if (devc->limit_samples > 0)
                        pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100;
                devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples);
-               if (devc->stl == NULL)
+               if (!devc->stl)
                        return SR_ERR_MALLOC;
                devc->trigger_fired = FALSE;
        } else
index f0b49c341a6a0957ede76e8806f8874a68866b19..715ca8a571bcb69cc2963fbe6a3e5497901004cb 100644 (file)
@@ -57,7 +57,7 @@ int dslogic_fpga_firmware_upload(const struct sr_dev_inst *sdi,
        }
        buf = g_malloc(FW_BUFSIZE);
 
-       if ((fw = g_fopen(filename, "rb")) == NULL) {
+       if (!(fw = g_fopen(filename, "rb"))) {
                sr_err("Unable to open %s for reading: %s.", filename, strerror(errno));
                return SR_ERR;
        }
index 814db59839785139211b9347dc5d155a94aec00e..766157484c4aa1c96b04bb4c936d06597973ec64 100644 (file)
@@ -185,7 +185,7 @@ SR_PRIV void dso_close(struct sr_dev_inst *sdi)
 
        usb = sdi->conn;
 
-       if (usb->devhdl == NULL)
+       if (!usb->devhdl)
                return;
 
        sr_info("Closing device on %d.%d (logical) / %s (physical) interface %d.",
index 31e1fb1fc2517752ed6e7a2881bb1b349f643bbb..a18557cf5f0cd94986a4843b1e0f50a256d69077 100644 (file)
@@ -77,7 +77,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
 
        usb_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, USB_VID_PID);
 
-       if (usb_devices == NULL)
+       if (!usb_devices)
                return NULL;
 
        for (l = usb_devices; l; l = l->next) {
index 89718894e7fab93be6de47d585d735c03be649ad..dbc66fddf5d209a8310f221e7b0cf5a50a50664f 100644 (file)
@@ -116,7 +116,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        }
        if (!conn)
                conn = SERIALCONN;
-       if (serialcomm == NULL)
+       if (!serialcomm)
                serialcomm = SERIALCOMM;
 
        udev = udev_new();
index 11fa8a616f79960795983833e953122537128d93..148f0ba18933fd80ec26bd2ee171be379e582097 100644 (file)
@@ -336,7 +336,7 @@ SR_PRIV int mso_check_trigger(struct sr_serial_dev_inst *serial, uint8_t *info)
 
        sr_dbg("Requesting trigger state.");
        ret = mso_send_control_message(serial, ARRAY_AND_SIZE(ops));
-       if (info == NULL || ret != SR_OK)
+       if (!info || ret != SR_OK)
                return ret;
 
        uint8_t buf = 0;
index c8ddc4be4ef357f0efc1ac421cc7cc3ea5c1ccc8..144378391eaedbe1e656ed06248193138f647c29 100644 (file)
@@ -123,7 +123,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        if (!conn)
                return NULL;
 
-       if (serialcomm == NULL)
+       if (!serialcomm)
                serialcomm = SERIALCOMM;
 
        serial = sr_serial_dev_inst_new(conn, serialcomm);
index c82bac80783c4a795f35b310256baf8df154ec8d..55e3d75237231446ec8f9f44919b2b9fdf81f05e 100644 (file)
@@ -398,7 +398,7 @@ static int dev_close(struct sr_dev_inst *sdi)
        struct sr_usb_dev_inst *usb;
 
        usb = sdi->conn;
-       if (usb->devhdl == NULL)
+       if (!usb->devhdl)
                return SR_ERR;
 
        sr_info("Closing device on %d.%d (logical) / %s (physical) interface %d.",
@@ -738,7 +738,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
                if (devc->limit_samples > 0)
                        pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100;
                devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples);
-               if (devc->stl == NULL)
+               if (!devc->stl)
                        return SR_ERR_MALLOC;
                devc->trigger_fired = FALSE;
        } else
index 9e5806e0ae4c89c620121e158b345753d38022dd..3bc7c7566c6abfb3d3fec30e52f1c7ac9f1d48e6 100644 (file)
@@ -107,7 +107,7 @@ static int do_ep1_command(const struct sr_dev_inst *sdi,
        usb = sdi->conn;
 
        if (cmd_len < 1 || cmd_len > 64 || reply_len > 64 ||
-           command == NULL || (reply_len > 0 && reply == NULL))
+           !command || (reply_len > 0 && !reply))
                return SR_ERR_ARG;
 
        encrypt(buf, command, cmd_len);
@@ -165,7 +165,7 @@ static int upload_led_table(const struct sr_dev_inst *sdi,
        uint8_t chunk, command[64];
        int ret;
 
-       if (cnt < 1 || cnt + offset > 64 || table == NULL)
+       if (cnt < 1 || cnt + offset > 64 || !table)
                return SR_ERR_ARG;
 
        while (cnt > 0) {
@@ -351,7 +351,7 @@ static int upload_fpga_bitstream(const struct sr_dev_inst *sdi,
                }
 
                sr_info("Uploading FPGA bitstream at %s.", filename);
-               if ((fw = g_fopen(filename, "rb")) == NULL) {
+               if (!(fw = g_fopen(filename, "rb"))) {
                        sr_err("Unable to open bitstream file %s for reading: %s.",
                               filename, strerror(errno));
                        return SR_ERR;
index 7f039bf0df87f5a77086281e9968e44d4a9995cb..de307989ad17a0bb5f3e837111f42908257ad8e7 100644 (file)
@@ -54,8 +54,8 @@ static GSList *scpi_serial_scan(struct drv_context *drvc)
        (void)drvc;
 
        for (i = 0; i < ARRAY_SIZE(scpi_serial_usb_ids); i++) {
-               if ((l = sr_serial_find_usb(scpi_serial_usb_ids[i].vendor_id,
-                                           scpi_serial_usb_ids[i].product_id)) == NULL)
+               if (!(l = sr_serial_find_usb(scpi_serial_usb_ids[i].vendor_id,
+                                       scpi_serial_usb_ids[i].product_id)))
                        continue;
                for (r = l; r; r = r->next) {
                        if (scpi_serial_usb_ids[i].serialcomm)
index e4efbf1d1d55cab2f55eb4cf91b638a66cc6ed4a..e7a4b2b5087eec89c7ca3111848f3ec49d78e9fe 100644 (file)
@@ -66,7 +66,7 @@ static int scpi_vxi_open(void *priv)
        Create_LinkResp *link_resp;
 
        vxi->client = clnt_create(vxi->address, DEVICE_CORE, DEVICE_CORE_VERSION, "tcp");
-       if (vxi->client == NULL) {
+       if (!vxi->client) {
                sr_err("Client creation failed for %s", vxi->address);
                return SR_ERR;
        }
index 27c71b611b4a82546c7c0cf35eda99a30fe40dab..9c3963d3acf651baa3f19f9076c23bb5fb070841 100644 (file)
@@ -40,7 +40,7 @@ SR_PRIV struct soft_trigger_logic *soft_trigger_logic_new(
        stl->pre_trigger_buffer = g_malloc(stl->pre_trigger_size);
        stl->pre_trigger_head = stl->pre_trigger_buffer;
 
-       if (stl->pre_trigger_size > 0 && stl->pre_trigger_buffer == NULL) {
+       if (stl->pre_trigger_size > 0 && !stl->pre_trigger_buffer) {
                soft_trigger_logic_free(stl);
                return NULL;
        }
index 050f37bf7090532cc67282e07c10ce2867a985b6..131126b0b2e0c6a922c8b045964302bf80d09dd3 100644 (file)
@@ -246,7 +246,7 @@ SR_API char *sr_si_string_u64(uint64_t x, const char *unit)
        const char *p, prefix[] = "\0kMGTPE";
        char fmt[16], fract[20] = "", *f;
 
-       if (unit == NULL)
+       if (!unit)
                unit = "";
 
        for (i = 0; (quot = x / divisor[i]) >= 1000; i++);