fwts_summary: check for list creation failure
diff mbox series

Message ID 20190610101109.27126-1-colin.king@canonical.com
State Superseded
Headers show
Series
  • fwts_summary: check for list creation failure
Related show

Commit Message

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

Check for null pointer when creating a new list.

Addresses-Coverity: ("Dereference null return")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_summary.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Colin King June 10, 2019, 10:11 a.m. UTC | #1
On 10/06/2019 11:11, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Check for null pointer when creating a new list.
> 
> Addresses-Coverity: ("Dereference null return")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_summary.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/src/lib/src/fwts_summary.c b/src/lib/src/fwts_summary.c
> index 625dcd2d..041df5ad 100644
> --- a/src/lib/src/fwts_summary.c
> +++ b/src/lib/src/fwts_summary.c
> @@ -233,6 +233,11 @@ int fwts_summary_report(fwts_framework *fw, fwts_list *test_list)
>  		fwts_list_link *item;
>  		fwts_list *sorted = fwts_list_new();
>  
> +		if (!sorted) {
> +			fwts_log_error(fw, "Out of memory allocating test summary list\n");

NAK: \n is not required.

> +			return FWTS_ERROR;
> +		}
> +
>  		fwts_list_foreach(item, test_list)
>  			fwts_list_add_ordered(sorted, fwts_list_data(fwts_framework_test *,item), fwts_framework_compare_test_name);
>  
>

Patch
diff mbox series

diff --git a/src/lib/src/fwts_summary.c b/src/lib/src/fwts_summary.c
index 625dcd2d..041df5ad 100644
--- a/src/lib/src/fwts_summary.c
+++ b/src/lib/src/fwts_summary.c
@@ -233,6 +233,11 @@  int fwts_summary_report(fwts_framework *fw, fwts_list *test_list)
 		fwts_list_link *item;
 		fwts_list *sorted = fwts_list_new();
 
+		if (!sorted) {
+			fwts_log_error(fw, "Out of memory allocating test summary list\n");
+			return FWTS_ERROR;
+		}
+
 		fwts_list_foreach(item, test_list)
 			fwts_list_add_ordered(sorted, fwts_list_data(fwts_framework_test *,item), fwts_framework_compare_test_name);