diff mbox

[7/7] dmi: dmicheck: fix a couple of cppcheck style warnings

Message ID 20161019132639.16524-8-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King Oct. 19, 2016, 1:26 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

reduce the scope of some local variables. Do not initialize
struct_type = 0 as it gets set a little while later.  Change the
while (1) loop to the fwts for (;;) idoim.

Cleans up cppcheck style warnings:
src/dmi/dmicheck/dmicheck.c:452]: (style) The scope of the variable
  'dmi_entry_length' can be reduced.
src/dmi/dmicheck/dmicheck.c:599]: (style) The scope of the variable
  'struct_length' can be reduced.
src/dmi/dmicheck/dmicheck.c:600]: (style) The scope of the variable
  'struct_type' can be reduced.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/dmi/dmicheck/dmicheck.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Comments

Alex Hung Oct. 19, 2016, 5:28 p.m. UTC | #1
On 2016-10-19 06:26 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> reduce the scope of some local variables. Do not initialize
> struct_type = 0 as it gets set a little while later.  Change the
> while (1) loop to the fwts for (;;) idoim.
>
> Cleans up cppcheck style warnings:
> src/dmi/dmicheck/dmicheck.c:452]: (style) The scope of the variable
>   'dmi_entry_length' can be reduced.
> src/dmi/dmicheck/dmicheck.c:599]: (style) The scope of the variable
>   'struct_length' can be reduced.
> src/dmi/dmicheck/dmicheck.c:600]: (style) The scope of the variable
>   'struct_type' can be reduced.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/dmi/dmicheck/dmicheck.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/src/dmi/dmicheck/dmicheck.c b/src/dmi/dmicheck/dmicheck.c
> index 51ccd26..1934ebe 100644
> --- a/src/dmi/dmicheck/dmicheck.c
> +++ b/src/dmi/dmicheck/dmicheck.c
> @@ -449,7 +449,6 @@ static void dmi_dump_entry30(fwts_framework *fw, fwts_smbios30_entry *entry)
>  static int dmi_sane(fwts_framework *fw, fwts_smbios_entry *entry)
>  {
>  	uint8_t	*table, *ptr;
> -	uint8_t dmi_entry_length;
>  	uint8_t dmi_entry_type = 0;
>  	uint16_t i = 0;
>  	uint16_t table_length = entry->struct_table_length;
> @@ -460,6 +459,8 @@ static int dmi_sane(fwts_framework *fw, fwts_smbios_entry *entry)
>  		return FWTS_ERROR;
>
>  	for (i = 0; i < entry->number_smbios_structures; i++) {
> +		uint8_t dmi_entry_length;
> +
>  		if (ptr > table + table_length) {
>  			fwts_failed(fw, LOG_LEVEL_MEDIUM,
>  				"SMBIOSTableLengthTooSmall",
> @@ -596,8 +597,6 @@ static int smbios_entry_check(fwts_framework *fw)
>  static int dmi_smbios30_sane(fwts_framework *fw, fwts_smbios30_entry *entry)
>  {
>  	uint8_t	*table, *ptr;
> -	uint8_t struct_length;
> -	uint8_t struct_type = 0;
>  	uint16_t i = 0;
>  	uint32_t table_length = entry->struct_table_max_size;
>  	int ret = FWTS_OK;
> @@ -606,8 +605,10 @@ static int dmi_smbios30_sane(fwts_framework *fw, fwts_smbios30_entry *entry)
>  	if (table == NULL)
>  		return FWTS_ERROR;
>
> -	while (1)
> -	{
> +	for (;;) {
> +		uint8_t struct_length;
> +		uint8_t struct_type;
> +
>  		if (ptr > table + table_length) {
>  			fwts_failed(fw, LOG_LEVEL_MEDIUM,
>  				"SMBIOS30TableLengthTooSmall",
>

Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu Oct. 24, 2016, 8:04 a.m. UTC | #2
On 2016年10月19日 21:26, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> reduce the scope of some local variables. Do not initialize
> struct_type = 0 as it gets set a little while later.  Change the
> while (1) loop to the fwts for (;;) idoim.
>
> Cleans up cppcheck style warnings:
> src/dmi/dmicheck/dmicheck.c:452]: (style) The scope of the variable
>   'dmi_entry_length' can be reduced.
> src/dmi/dmicheck/dmicheck.c:599]: (style) The scope of the variable
>   'struct_length' can be reduced.
> src/dmi/dmicheck/dmicheck.c:600]: (style) The scope of the variable
>   'struct_type' can be reduced.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/dmi/dmicheck/dmicheck.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/src/dmi/dmicheck/dmicheck.c b/src/dmi/dmicheck/dmicheck.c
> index 51ccd26..1934ebe 100644
> --- a/src/dmi/dmicheck/dmicheck.c
> +++ b/src/dmi/dmicheck/dmicheck.c
> @@ -449,7 +449,6 @@ static void dmi_dump_entry30(fwts_framework *fw, fwts_smbios30_entry *entry)
>  static int dmi_sane(fwts_framework *fw, fwts_smbios_entry *entry)
>  {
>  	uint8_t	*table, *ptr;
> -	uint8_t dmi_entry_length;
>  	uint8_t dmi_entry_type = 0;
>  	uint16_t i = 0;
>  	uint16_t table_length = entry->struct_table_length;
> @@ -460,6 +459,8 @@ static int dmi_sane(fwts_framework *fw, fwts_smbios_entry *entry)
>  		return FWTS_ERROR;
>
>  	for (i = 0; i < entry->number_smbios_structures; i++) {
> +		uint8_t dmi_entry_length;
> +
>  		if (ptr > table + table_length) {
>  			fwts_failed(fw, LOG_LEVEL_MEDIUM,
>  				"SMBIOSTableLengthTooSmall",
> @@ -596,8 +597,6 @@ static int smbios_entry_check(fwts_framework *fw)
>  static int dmi_smbios30_sane(fwts_framework *fw, fwts_smbios30_entry *entry)
>  {
>  	uint8_t	*table, *ptr;
> -	uint8_t struct_length;
> -	uint8_t struct_type = 0;
>  	uint16_t i = 0;
>  	uint32_t table_length = entry->struct_table_max_size;
>  	int ret = FWTS_OK;
> @@ -606,8 +605,10 @@ static int dmi_smbios30_sane(fwts_framework *fw, fwts_smbios30_entry *entry)
>  	if (table == NULL)
>  		return FWTS_ERROR;
>
> -	while (1)
> -	{
> +	for (;;) {
> +		uint8_t struct_length;
> +		uint8_t struct_type;
> +
>  		if (ptr > table + table_length) {
>  			fwts_failed(fw, LOG_LEVEL_MEDIUM,
>  				"SMBIOS30TableLengthTooSmall",
>

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

Patch

diff --git a/src/dmi/dmicheck/dmicheck.c b/src/dmi/dmicheck/dmicheck.c
index 51ccd26..1934ebe 100644
--- a/src/dmi/dmicheck/dmicheck.c
+++ b/src/dmi/dmicheck/dmicheck.c
@@ -449,7 +449,6 @@  static void dmi_dump_entry30(fwts_framework *fw, fwts_smbios30_entry *entry)
 static int dmi_sane(fwts_framework *fw, fwts_smbios_entry *entry)
 {
 	uint8_t	*table, *ptr;
-	uint8_t dmi_entry_length;
 	uint8_t dmi_entry_type = 0;
 	uint16_t i = 0;
 	uint16_t table_length = entry->struct_table_length;
@@ -460,6 +459,8 @@  static int dmi_sane(fwts_framework *fw, fwts_smbios_entry *entry)
 		return FWTS_ERROR;
 
 	for (i = 0; i < entry->number_smbios_structures; i++) {
+		uint8_t dmi_entry_length;
+
 		if (ptr > table + table_length) {
 			fwts_failed(fw, LOG_LEVEL_MEDIUM,
 				"SMBIOSTableLengthTooSmall",
@@ -596,8 +597,6 @@  static int smbios_entry_check(fwts_framework *fw)
 static int dmi_smbios30_sane(fwts_framework *fw, fwts_smbios30_entry *entry)
 {
 	uint8_t	*table, *ptr;
-	uint8_t struct_length;
-	uint8_t struct_type = 0;
 	uint16_t i = 0;
 	uint32_t table_length = entry->struct_table_max_size;
 	int ret = FWTS_OK;
@@ -606,8 +605,10 @@  static int dmi_smbios30_sane(fwts_framework *fw, fwts_smbios30_entry *entry)
 	if (table == NULL)
 		return FWTS_ERROR;
 
-	while (1)
-	{
+	for (;;) {
+		uint8_t struct_length;
+		uint8_t struct_type;
+
 		if (ptr > table + table_length) {
 			fwts_failed(fw, LOG_LEVEL_MEDIUM,
 				"SMBIOS30TableLengthTooSmall",