diff options
author | Pete Batard <pete@akeo.ie> | 2014-05-16 23:01:57 +0100 |
---|---|---|
committer | Pete Batard <pete@akeo.ie> | 2014-05-16 23:01:57 +0100 |
commit | bcc4e517d5ce41e541484ade9b2800ba06a9b903 (patch) | |
tree | dc8e64e893606d2371d076d0f712273712e07db6 /examples | |
parent | 26dab3d6808a00c28a0d222c8f6625d4e719a5b2 (diff) | |
download | libusb-bcc4e517d5ce41e541484ade9b2800ba06a9b903.tar.gz |
core: fix/silence issues reported by Coverity
* libusb has been added to Coverity at https://scan.coverity.com/projects/2180
* Use "// coverity[keyword]" to silence the issues we don't care about
* All other issues from the Windows build have been fixed, apart from the closing of the DLLs.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/ezusb.c | 14 | ||||
-rw-r--r-- | examples/xusb.c | 1 |
2 files changed, 10 insertions, 5 deletions
diff --git a/examples/ezusb.c b/examples/ezusb.c index 5111f98..f369e50 100644 --- a/examples/ezusb.c +++ b/examples/ezusb.c @@ -442,9 +442,11 @@ static int parse_iic(FILE *image, void *context, if (initial_pos < 0) return -1; - fseek(image, 0L, SEEK_END); + if (fseek(image, 0L, SEEK_END) != 0) + return -1; file_size = ftell(image); - fseek(image, initial_pos, SEEK_SET); + if (fseek(image, initial_pos, SEEK_SET) != 0) + return -1; for (;;) { /* Ignore the trailing reset IIC data (5 bytes) */ if (ftell(image) >= (file_size - 5)) @@ -633,7 +635,8 @@ static int fx3_load_ram(libusb_device_handle *device, const char *path) if (dLength == 0) break; // done - dImageBuf = calloc(dLength, sizeof(uint32_t)); + // coverity[tainted_data] + dImageBuf = (uint32_t*)calloc(dLength, sizeof(uint32_t)); if (dImageBuf == NULL) { logerror("could not allocate buffer for image chunk\n"); ret = -4; @@ -813,9 +816,10 @@ int ezusb_load_ram(libusb_device_handle *device, const char *path, int fx_type, } } - if (verbose) + if (verbose && (ctx.count != 0)) { logerror("... WROTE: %d bytes, %d segments, avg %d\n", - (int)ctx.total, (int)ctx.count, (int)(ctx.total/ctx.count)); + (int)ctx.total, (int)ctx.count, (int)(ctx.total/ctx.count)); + } /* if required, reset the CPU so it runs what we just uploaded */ if (cpucs_addr && !ezusb_cpucs(device, cpucs_addr, true)) diff --git a/examples/xusb.c b/examples/xusb.c index 77c8c46..540c90e 100644 --- a/examples/xusb.c +++ b/examples/xusb.c @@ -512,6 +512,7 @@ static int test_mass_storage(libusb_device_handle *handle, uint8_t endpoint_in, get_sense(handle, endpoint_in, endpoint_out); } + // coverity[tainted_data] data = (unsigned char*) calloc(1, block_size); if (data == NULL) { perr(" unable to allocate data buffer\n"); |