diff mbox series

lib: fwts_formatting: use simpler style for assigments

Message ID 20190611091348.27785-1-colin.king@canonical.com
State Accepted
Headers show
Series lib: fwts_formatting: use simpler style for assigments | expand

Commit Message

Colin Ian King June 11, 2019, 9:13 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Don't do double assignments and a null check in one go. Use a
simpler code style to match coding style and clean up cppcheck
warnings.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_formatting.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Alex Hung June 11, 2019, 4:31 p.m. UTC | #1
On 2019-06-11 2:13 a.m., Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Don't do double assignments and a null check in one go. Use a
> simpler code style to match coding style and clean up cppcheck
> warnings.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_formatting.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/src/lib/src/fwts_formatting.c b/src/lib/src/fwts_formatting.c
> index 4e910d51..aee19388 100644
> --- a/src/lib/src/fwts_formatting.c
> +++ b/src/lib/src/fwts_formatting.c
> @@ -40,9 +40,11 @@ static char *dup_line(const char *start, const char *end, const size_t width)
>  	if (maxlen < width)
>  		maxlen = width;
>  
> -	if ((bufptr = buffer = calloc(1, maxlen + 1)) == NULL)
> +	buffer = calloc(1, maxlen + 1);
> +	if (!buffer)
>  		return NULL;
>  
> +	bufptr = buffer;
>  	while (*start && start < end)
>  		*bufptr++ = *start++;
>  
> 


Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu June 12, 2019, 3:42 a.m. UTC | #2
On 6/11/19 5:13 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Don't do double assignments and a null check in one go. Use a
> simpler code style to match coding style and clean up cppcheck
> warnings.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_formatting.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/src/lib/src/fwts_formatting.c b/src/lib/src/fwts_formatting.c
> index 4e910d51..aee19388 100644
> --- a/src/lib/src/fwts_formatting.c
> +++ b/src/lib/src/fwts_formatting.c
> @@ -40,9 +40,11 @@ static char *dup_line(const char *start, const char *end, const size_t width)
>  	if (maxlen < width)
>  		maxlen = width;
>  
> -	if ((bufptr = buffer = calloc(1, maxlen + 1)) == NULL)
> +	buffer = calloc(1, maxlen + 1);
> +	if (!buffer)
>  		return NULL;
>  
> +	bufptr = buffer;
>  	while (*start && start < end)
>  		*bufptr++ = *start++;
>  

Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox series

Patch

diff --git a/src/lib/src/fwts_formatting.c b/src/lib/src/fwts_formatting.c
index 4e910d51..aee19388 100644
--- a/src/lib/src/fwts_formatting.c
+++ b/src/lib/src/fwts_formatting.c
@@ -40,9 +40,11 @@  static char *dup_line(const char *start, const char *end, const size_t width)
 	if (maxlen < width)
 		maxlen = width;
 
-	if ((bufptr = buffer = calloc(1, maxlen + 1)) == NULL)
+	buffer = calloc(1, maxlen + 1);
+	if (!buffer)
 		return NULL;
 
+	bufptr = buffer;
 	while (*start && start < end)
 		*bufptr++ = *start++;