[LEDE-DEV] [PATCH] libubox: Fix cppcheck warnings

Felix Fietkau nbd at nbd.name
Fri Dec 16 04:53:00 PST 2016


On 2016-12-15 05:11, Rosen Penev wrote:
> Two formats and a memory leak.
> 
> Signed-off by: Rosen Penev <rosenp at gmail.com>
> ---
>  ulog.c  | 2 +-
>  usock.c | 2 +-
>  utils.c | 4 +++-
>  3 files changed, 5 insertions(+), 3 deletions(-)
> 
> 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;
>  }
I think these changes are wrong. The variables should be made unsigned
instead, since they're not meant to ever hold contain negative values.

- Felix



More information about the Lede-dev mailing list