diff options
author | Travis Geiselbrecht <geist@foobox.com> | 2015-11-24 15:08:38 -0800 |
---|---|---|
committer | Travis Geiselbrecht <geist@foobox.com> | 2015-11-24 15:08:38 -0800 |
commit | 4ab14424bdcdb1ab51fdc84d506338a46e689609 (patch) | |
tree | 91f3a0204cd21d6bf483e058293af071221ebe97 | |
parent | 6cdc5cd1daaf22f56422301d3dac67c3573ef290 (diff) | |
download | common-4ab14424bdcdb1ab51fdc84d506338a46e689609.tar.gz |
[cppcheck] clean up a few suggestions from cppcheck
-rw-r--r-- | app/tests/benchmarks.c | 2 | ||||
-rw-r--r-- | arch/arm/arm/faults.c | 2 | ||||
-rw-r--r-- | dev/usb/usb.c | 5 | ||||
-rw-r--r-- | kernel/thread.c | 5 | ||||
-rw-r--r-- | lib/fs/shell.c | 5 | ||||
-rw-r--r-- | lib/minip/udp.c | 1 |
6 files changed, 12 insertions, 8 deletions
diff --git a/app/tests/benchmarks.c b/app/tests/benchmarks.c index fed46137..49a1aa92 100644 --- a/app/tests/benchmarks.c +++ b/app/tests/benchmarks.c @@ -119,7 +119,7 @@ __NO_INLINE static void bench_cset_wide(void) __NO_INLINE static void bench_memcpy(void) { - uint8_t *buf = malloc(BUFSIZE); + uint8_t *buf = calloc(1, BUFSIZE); uint count = arch_cycle_count(); for (uint i = 0; i < ITER; i++) { diff --git a/arch/arm/arm/faults.c b/arch/arm/arm/faults.c index 9a76cc53..0908b55c 100644 --- a/arch/arm/arm/faults.c +++ b/arch/arm/arm/faults.c @@ -216,7 +216,6 @@ void arm_data_abort_handler(struct arm_fault_frame *frame) case 0b01000: // synchronous external abort dprintf(CRITICAL, "synchronous external abort on %s\n", write ? "write" : "read"); break; - break; case 0b10110: // asynchronous external abort dprintf(CRITICAL, "asynchronous external abort on %s\n", write ? "write" : "read"); break; @@ -275,7 +274,6 @@ void arm_prefetch_abort_handler(struct arm_fault_frame *frame) case 0b01000: // synchronous external abort dprintf(CRITICAL, "synchronous external abort\n"); break; - break; case 0b10110: // asynchronous external abort dprintf(CRITICAL, "asynchronous external abort\n"); break; diff --git a/dev/usb/usb.c b/dev/usb/usb.c index 418dea09..5c8948ad 100644 --- a/dev/usb/usb.c +++ b/dev/usb/usb.c @@ -141,7 +141,10 @@ status_t usb_add_string(const char *string, uint8_t id) { uint i; size_t len = strlen(string); + uint16_t *strbuf = malloc(len * 2 + 2); + if (!strbuf) + return ERR_NO_MEMORY; /* build the usb string descriptor */ strbuf[0] = 0x300 | (len * 2 + 2); @@ -159,6 +162,8 @@ status_t usb_add_string(const char *string, uint8_t id) } } + /* couldn't find a spot */ + free(strbuf); return ERR_NO_MEMORY; } diff --git a/kernel/thread.c b/kernel/thread.c index 8f4546ea..14aa5832 100644 --- a/kernel/thread.c +++ b/kernel/thread.c @@ -429,11 +429,10 @@ static thread_t *get_top_thread(int cpu) { thread_t *newthread; uint32_t local_run_queue_bitmap = run_queue_bitmap; - uint next_queue; while (local_run_queue_bitmap) { /* find the first (remaining) queue with a thread in it */ - next_queue = HIGHEST_PRIORITY - __builtin_clz(local_run_queue_bitmap) + uint next_queue = HIGHEST_PRIORITY - __builtin_clz(local_run_queue_bitmap) - (sizeof(run_queue_bitmap) * 8 - NUM_PRIORITIES); list_for_every_entry(&run_queue[next_queue], newthread, thread_t, queue_node) { @@ -878,7 +877,7 @@ void thread_secondary_cpu_init_early(void) thread_t *t = &idle_threads[cpu]; char name[16]; - snprintf(name, sizeof(name), "idle %d", cpu); + snprintf(name, sizeof(name), "idle %u", cpu); init_thread_struct(t, name); t->pinned_cpu = cpu; diff --git a/lib/fs/shell.c b/lib/fs/shell.c index af1ad9c1..1dbd6de8 100644 --- a/lib/fs/shell.c +++ b/lib/fs/shell.c @@ -46,8 +46,9 @@ static void set_cwd(const char *path) } size_t len = strlen(path) + 1; - cwd = realloc(cwd, len); - if (cwd) { + char *new_cwd = realloc(cwd, len); + if (new_cwd) { + cwd = new_cwd; memcpy(cwd, path, len); } } diff --git a/lib/minip/udp.c b/lib/minip/udp.c index e168321d..08e10b3c 100644 --- a/lib/minip/udp.c +++ b/lib/minip/udp.c @@ -103,6 +103,7 @@ status_t udp_open(uint32_t host, uint16_t sport, uint16_t dport, udp_socket_t ** dst_mac = arp_get_dest_mac(host); if (dst_mac == NULL) { + free(socket); return -EHOSTUNREACH; } |