diff mbox

[LEDE-DEV] libubox: Fix cppcheck warnings

Message ID 20161214054754.4052-1-rosenp@gmail.com
State Changes Requested
Headers show

Commit Message

Rosen Penev Dec. 14, 2016, 5:47 a.m. UTC
Two formats and a memory leak.

Signed-off by: Rosen Penev <rosenp@gmail.com>
---
 ulog.c  | 2 +-
 usock.c | 2 +-
 utils.c | 3 +++
 3 files changed, 5 insertions(+), 2 deletions(-)

Comments

Rafał Miłecki Dec. 14, 2016, 9:54 a.m. UTC | #1
On 14 December 2016 at 06:47, Rosen Penev <rosenp@gmail.com> wrote:
> @@ -44,7 +44,10 @@ void *__calloc_a(size_t len, ...)
>
>         ptr = calloc(1, alloc_len);
>         if (!ptr)
> +       {
> +               va_end(ap);
>                 return NULL;
> +       }

Please following coding style used across the whole project and put
opening bracket in one line with "if"
diff mbox

Patch

diff --git a/ulog.c b/ulog.c
index 985d366..e7fb081 100644
--- a/ulog.c
+++ b/ulog.c
@@ -91,7 +91,7 @@  static void ulog_kmsg(int priority, const char *fmt, va_list ap)
 	FILE *kmsg;
 
 	if ((kmsg = fopen("/dev/kmsg", "r+")) != NULL) {
-		fprintf(kmsg, "<%u>", priority);
+		fprintf(kmsg, "<%d>", priority);
 
 		if (_ulog_ident)
 			fprintf(kmsg, "%s: ", _ulog_ident);
diff --git a/usock.c b/usock.c
index 0ce5390..0983806 100644
--- a/usock.c
+++ b/usock.c
@@ -247,7 +247,7 @@  const char *usock_port(int port)
 	if (port < 0 || port > 65535)
 		return NULL;
 
-	snprintf(buffer, sizeof(buffer), "%u", port);
+	snprintf(buffer, sizeof(buffer), "%d", port);
 
 	return buffer;
 }
diff --git a/utils.c b/utils.c
index 91dd71e..a8bc5c5 100644
--- a/utils.c
+++ b/utils.c
@@ -44,7 +44,10 @@  void *__calloc_a(size_t len, ...)
 
 	ptr = calloc(1, alloc_len);
 	if (!ptr)
+	{
+		va_end(ap);
 		return NULL;
+	}
 	alloc_len = 0;
 	foreach_arg(ap, cur_addr, cur_len, &ret, len) {
 		*cur_addr = &ptr[alloc_len];