tools/kwbimage.c: fix parser error handling
PATCH 1/1 tools/kwbimage.c: fix parser error handling
From: Andreas Bie?mann <[email protected]>
The two error checks for image_boot_mode_id and image_nand_ecc_mode_id where wrong and would never fail, fix that!
This was detected by Apple's clang compiler:
---8<---
HOSTCC tools/kwbimage.otools/kwbimage.c:553:20: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
if (el->bootfrom < 0) {
~~~~~~~~~~~~ ^ ~
tools/kwbimage.c:571:23: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
if (el->nandeccmode < 0) {
~~~~~~~~~~~~~~~ ^ ~2 warnings generated.
--->8---
---
tools/kwbimage.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
tools/kwbimage.c +8 -6
@@ -548,13 +548,14 @@ static int image_create_config_parse_oneline(char *line, el->version =atoi (value); }else if (!strcmp (keyword,"BOOT_FROM" )) {char *value =strtok_r (NULL , deliminiters, &saveptr); - el->type =IMAGE_CFG_BOOT_FROM ; - el->bootfrom =image_boot_mode_id (value); -if (el->bootfrom <0 ) { +int ret =image_boot_mode_id (value); +if (ret <0 ) {fprintf (stderr,"Invalid boot media '%s'\n" , value);return -1 ; } + el->type =IMAGE_CFG_BOOT_FROM ; + el->bootfrom = ret; }else if (!strcmp (keyword,"NAND_BLKSZ" )) {char *value =strtok_r (NULL , deliminiters, &saveptr); el->type =IMAGE_CFG_NAND_BLKSZ ;
@@ -566,13 +567,14 @@ static int image_create_config_parse_oneline(char *line,strtoul (value,NULL ,16 ); }else if (!strcmp (keyword,"NAND_ECC_MODE" )) {char *value =strtok_r (NULL , deliminiters, &saveptr); - el->type =IMAGE_CFG_NAND_ECC_MODE ; - el->nandeccmode =image_nand_ecc_mode_id (value); -if (el->nandeccmode <0 ) { +int ret =image_nand_ecc_mode_id (value); +if (ret <0 ) {fprintf (stderr,"Invalid NAND ECC mode '%s'\n" , value);return -1 ; } + el->type =IMAGE_CFG_NAND_ECC_MODE ; + el->nandeccmode = ret; }else if (!strcmp (keyword,"NAND_PAGE_SIZE" )) {char *value =strtok_r (NULL , deliminiters, &saveptr); el->type =IMAGE_CFG_NAND_PAGESZ ;
Signature · 1 line
1.9.3 (Apple Git-50)
PATCH 1/1 tools/kwbimage.c: fix parser error handling
Hello Andreas,
Quoted 46 lines · andreas.devel at googlemail.com
From: Andreas Bie?mann <[email protected]>
The two error checks for
image_boot_mode_idandimage_nand_ecc_mode_idwhere wrong and would never fail, fix that!This was detected by Apple's clang compiler:
---8<---
HOSTCCtools/kwbimage.otools/kwbimage.c:553:20: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]if (el->bootfrom < 0) { ~~~~~~~~~~~~ ^ ~ tools/kwbimage.c:571:23: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare] if (el->nandeccmode < 0) { ~~~~~~~~~~~~~~~ ^ ~2 warnings generated.
--->8---Signed-off-by Andreas Bie?mann <[email protected]>---
tools/kwbimage.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)tools/kwbimage.c +4
-3@@ -548,13 +548,14 @@ static int image_create_config_parse_oneline(char *line, el->version =atoi (value); }else if (!strcmp (keyword,"BOOT_FROM" )) {char *value =strtok_r (NULL , deliminiters, &saveptr); - el->type =IMAGE_CFG_BOOT_FROM ; - el->bootfrom =image_boot_mode_id (value); -if (el->bootfrom <0 ) { +int ret =image_boot_mode_id (value); +if (ret <0 ) {fprintf (stderr,"Invalid boot media '%s'\n" , value);return -1 ; } + el->type =IMAGE_CFG_BOOT_FROM ; + el->bootfrom = ret; }else if (!strcmp (keyword,"NAND_BLKSZ" )) {char *value =strtok_r (NULL , deliminiters, &saveptr); el->type =IMAGE_CFG_NAND_BLKSZ ;
tools/kwbimage.c static int image_create_config_parse_oneline(char *line, · line 570
Quoted 7 lines
tools/kwbimage.c +1
-3@@ -566,13 +567,14 @@ static int image_create_config_parse_oneline(char *line,strtoul (value,NULL ,16 ); }else if (!strcmp (keyword,"NAND_ECC_MODE" )) {char *value =strtok_r (NULL , deliminiters, &saveptr); - el->type =IMAGE_CFG_NAND_ECC_MODE ; - el->nandeccmode =image_nand_ecc_mode_id (value); -if (el->nandeccmode <0 ) { +int ret =image_nand_ecc_mode_id (value);
Thanks for fixing this. Could you move the int ret declaration before actual code though?
Regards,
Jeroen
PATCH 1/1 tools/kwbimage.c: fix parser error handling
Hello Andreas,
Quoted 56 lines · Jeroen Hofstee
Hello Andreas,
Quoted 53 lines · andreas.devel at googlemail.com
From: Andreas Bie?mann <[email protected]>
The two error checks for
image_boot_mode_idandimage_nand_ecc_mode_idwhere
wrong and would never fail, fix that!This was detected by Apple's clang compiler:
---8<---
HOSTCCtools/kwbimage.otools/kwbimage.c:553:20: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]if (el->bootfrom < 0) { ~~~~~~~~~~~~ ^ ~ tools/kwbimage.c:571:23: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare] if (el->nandeccmode < 0) { ~~~~~~~~~~~~~~~ ^ ~2 warnings generated.
--->8---Signed-off-by Andreas Bie?mann <[email protected]>---
tools/kwbimage.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)tools/kwbimage.c +4
-3@@ -548,13 +548,14 @@ static intimage_create_config_parse_oneline (char *line, el->version = atoi(value); }else if (!strcmp (keyword,"BOOT_FROM" )) {char *value =strtok_r (NULL , deliminiters, &saveptr); - el->type =IMAGE_CFG_BOOT_FROM ; - el->bootfrom =image_boot_mode_id (value); -if (el->bootfrom <0 ) { +int ret =image_boot_mode_id (value); +if (ret <0 ) {fprintf (stderr,"Invalid boot media '%s'\n" , value);return -1 ; } + el->type =IMAGE_CFG_BOOT_FROM ; + el->bootfrom = ret; }else if (!strcmp (keyword,"NAND_BLKSZ" )) {char *value =strtok_r (NULL , deliminiters, &saveptr);el->type = IMAGE_CFG_NAND_BLKSZ;tools/kwbimage.c +0
-0@@ -566,13 +567,14 @@ static intimage_create_config_parse_oneline (char *line, strtoul(value, NULL, 16); }else if (!strcmp (keyword,"NAND_ECC_MODE" )) {
Quoted 8 lines
tools/kwbimage.c static int image_create_config_parse_oneline(char *line, · line 570
Quoted 5 lines
tools/kwbimage.c +1
-3char *value =strtok_r (NULL , deliminiters, &saveptr); - el->type =IMAGE_CFG_NAND_ECC_MODE ; - el->nandeccmode =image_nand_ecc_mode_id (value); -if (el->nandeccmode <0 ) { +int ret =image_nand_ecc_mode_id (value);Thanks for fixing this. Could you move the int ret declaration before actual code though?
Ah, I see now, you were not adding the declaration in the middle of the code. There is just a newline missing after the declaration, which make the patch look like it does. This was already the case in the original code, so
Regards,
Jeroen
PATCH 1/1 tools/kwbimage.c: fix parser error handling
ping?
It is http://patchwork.ozlabs.org/patch/403237/
Quoted 77 lines · Jeroen Hofstee
Hello Andreas,
Quoted 56 lines · Jeroen Hofstee
Hello Andreas,
Quoted 53 lines · andreas.devel at googlemail.com
From: Andreas Bie?mann <[email protected]>
The two error checks for
image_boot_mode_idandimage_nand_ecc_mode_idwhere
wrong and would never fail, fix that!This was detected by Apple's clang compiler:
---8<---
HOSTCCtools/kwbimage.otools/kwbimage.c:553:20: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]if (el->bootfrom < 0) { ~~~~~~~~~~~~ ^ ~ tools/kwbimage.c:571:23: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare] if (el->nandeccmode < 0) { ~~~~~~~~~~~~~~~ ^ ~2 warnings generated.
--->8---Signed-off-by Andreas Bie?mann <[email protected]>---
tools/kwbimage.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)tools/kwbimage.c +4
-3@@ -548,13 +548,14 @@ static intimage_create_config_parse_oneline (char *line, el->version = atoi(value); }else if (!strcmp (keyword,"BOOT_FROM" )) {char *value =strtok_r (NULL , deliminiters, &saveptr); - el->type =IMAGE_CFG_BOOT_FROM ; - el->bootfrom =image_boot_mode_id (value); -if (el->bootfrom <0 ) { +int ret =image_boot_mode_id (value); +if (ret <0 ) {fprintf (stderr,"Invalid boot media '%s'\n" , value);return -1 ; } + el->type =IMAGE_CFG_BOOT_FROM ; + el->bootfrom = ret; }else if (!strcmp (keyword,"NAND_BLKSZ" )) {char *value =strtok_r (NULL , deliminiters, &saveptr);el->type = IMAGE_CFG_NAND_BLKSZ;tools/kwbimage.c +0
-0@@ -566,13 +567,14 @@ static intimage_create_config_parse_oneline (char *line, strtoul(value, NULL, 16); }else if (!strcmp (keyword,"NAND_ECC_MODE" )) {Quoted 8 lines
tools/kwbimage.c static int image_create_config_parse_oneline(char *line, · line 570
Quoted 5 lines
tools/kwbimage.c +1
-3char *value =strtok_r (NULL , deliminiters, &saveptr); - el->type =IMAGE_CFG_NAND_ECC_MODE ; - el->nandeccmode =image_nand_ecc_mode_id (value); -if (el->nandeccmode <0 ) { +int ret =image_nand_ecc_mode_id (value);Thanks for fixing this. Could you move the int ret declaration before actual code though?
Ah, I see now, you were not adding the declaration in the middle of the code. There is just a newline missing after the declaration, which make the patch look like it does. This was already the case in the original code, so
Acked-by Jeroen Hofstee <[email protected]>Regards,
Jeroen
Quoted 6 lines · Andreas Bie?mann
From: Andreas Bie?mann <[email protected]>
The two error checks for
image_boot_mode_idandimage_nand_ecc_mode_idwhere wrong and would never fail, fix that!This was detected by Apple's clang compiler:
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150111/3d865218/attachment.pgp>