diff mbox series

[OpenWrt-Devel,uci,18/18] lua: fix error handling

Message ID 20191105003657.16540-19-ynezz@true.cz
State Accepted
Delegated to: Petr Štetiar
Headers show
Series fixes and improvements | expand

Commit Message

Petr Štetiar Nov. 5, 2019, 12:36 a.m. UTC
scan-build from clang version 9 has reported following issues:

 uci.c:389:3: warning: Value stored to 'err' is never read
                err = UCI_ERR_INVAL;
                ^     ~~~~~~~~~~~~~
 uci.c:393:3: warning: Value stored to 'err' is never read
                err = UCI_ERR_NOTFOUND;
                ^     ~~~~~~~~~~~~~~~~
 uci.c:417:4: warning: Value stored to 'err' is never read
                        err = UCI_ERR_INVAL;
                        ^     ~~~~~~~~~~~~~
 uci.c:524:3: warning: Value stored to 'err' is never read
                err = UCI_ERR_INVAL;
                ^     ~~~~~~~~~~~~~
 uci.c:533:3: warning: Value stored to 'err' is never read
                err = UCI_ERR_INVAL;
                ^     ~~~~~~~~~~~~~
 uci.c:565:4: warning: Value stored to 'err' is never read
                        err = UCI_ERR_INVAL;
                        ^     ~~~~~~~~~~~~~
 uci.c:575:3: warning: Value stored to 'err' is never read
                err = UCI_ERR_INVAL;
                ^     ~~~~~~~~~~~~~
 uci.c:584:3: warning: Value stored to 'err' is never read
                err = UCI_ERR_INVAL;
                ^     ~~~~~~~~~~~~~
 uci.c:642:3: warning: Value stored to 'err' is never read
                err = UCI_ERR_INVAL;
                ^     ~~~~~~~~~~~~~
 uci.c:651:3: warning: Value stored to 'err' is never read
                err = UCI_ERR_INVAL;
                ^     ~~~~~~~~~~~~~

Signed-off-by: Petr Štetiar <ynezz@true.cz>
---
 lua/uci.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

Comments

Rosen Penev Nov. 5, 2019, 5:43 a.m. UTC | #1
On Mon, Nov 4, 2019 at 4:40 PM Petr Štetiar <ynezz@true.cz> wrote:
>
> scan-build from clang version 9 has reported following issues:
Note that CMake has integrated clang-tidy support. It supports all the
clang-analyzer stuff and more.
>
>  uci.c:389:3: warning: Value stored to 'err' is never read
>                 err = UCI_ERR_INVAL;
>                 ^     ~~~~~~~~~~~~~
>  uci.c:393:3: warning: Value stored to 'err' is never read
>                 err = UCI_ERR_NOTFOUND;
>                 ^     ~~~~~~~~~~~~~~~~
>  uci.c:417:4: warning: Value stored to 'err' is never read
>                         err = UCI_ERR_INVAL;
>                         ^     ~~~~~~~~~~~~~
>  uci.c:524:3: warning: Value stored to 'err' is never read
>                 err = UCI_ERR_INVAL;
>                 ^     ~~~~~~~~~~~~~
>  uci.c:533:3: warning: Value stored to 'err' is never read
>                 err = UCI_ERR_INVAL;
>                 ^     ~~~~~~~~~~~~~
>  uci.c:565:4: warning: Value stored to 'err' is never read
>                         err = UCI_ERR_INVAL;
>                         ^     ~~~~~~~~~~~~~
>  uci.c:575:3: warning: Value stored to 'err' is never read
>                 err = UCI_ERR_INVAL;
>                 ^     ~~~~~~~~~~~~~
>  uci.c:584:3: warning: Value stored to 'err' is never read
>                 err = UCI_ERR_INVAL;
>                 ^     ~~~~~~~~~~~~~
>  uci.c:642:3: warning: Value stored to 'err' is never read
>                 err = UCI_ERR_INVAL;
>                 ^     ~~~~~~~~~~~~~
>  uci.c:651:3: warning: Value stored to 'err' is never read
>                 err = UCI_ERR_INVAL;
>                 ^     ~~~~~~~~~~~~~
>
> Signed-off-by: Petr Štetiar <ynezz@true.cz>
> ---
>  lua/uci.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/lua/uci.c b/lua/uci.c
> index a7aaad375c20..1ed73e4f67dc 100644
> --- a/lua/uci.c
> +++ b/lua/uci.c
> @@ -386,11 +386,11 @@ uci_lua_get_any(lua_State *L, bool all)
>
>         lookup_ptr(ctx, &ptr, NULL, true);
>         if (!all && !ptr.s) {
> -               err = UCI_ERR_INVAL;
> +               ctx->err = UCI_ERR_INVAL;
>                 goto error;
>         }
>         if (!(ptr.flags & UCI_LOOKUP_COMPLETE)) {
> -               err = UCI_ERR_NOTFOUND;
> +               ctx->err = UCI_ERR_NOTFOUND;
>                 goto error;
>         }
>
> @@ -414,7 +414,7 @@ uci_lua_get_any(lua_State *L, bool all)
>                         uci_push_option(L, ptr.o);
>                         break;
>                 default:
> -                       err = UCI_ERR_INVAL;
> +                       ctx->err = UCI_ERR_INVAL;
>                         goto error;
>         }
>         if (s)
> @@ -521,7 +521,7 @@ uci_lua_rename(lua_State *L)
>                 ptr.option = NULL;
>                 break;
>         default:
> -               err = UCI_ERR_INVAL;
> +               ctx->err = UCI_ERR_INVAL;
>                 goto error;
>         }
>
> @@ -530,7 +530,7 @@ uci_lua_rename(lua_State *L)
>                 goto error;
>
>         if (((ptr.s == NULL) && (ptr.option != NULL)) || (ptr.value == NULL)) {
> -               err = UCI_ERR_INVAL;
> +               ctx->err = UCI_ERR_INVAL;
>                 goto error;
>         }
>
> @@ -562,7 +562,7 @@ uci_lua_reorder(lua_State *L)
>         case 1:
>                 /* Format: uci.set("p.s=v") or uci.set("p.s=v") */
>                 if (ptr.option) {
> -                       err = UCI_ERR_INVAL;
> +                       ctx->err = UCI_ERR_INVAL;
>                         goto error;
>                 }
>                 break;
> @@ -572,7 +572,7 @@ uci_lua_reorder(lua_State *L)
>                 ptr.option = NULL;
>                 break;
>         default:
> -               err = UCI_ERR_INVAL;
> +               ctx->err = UCI_ERR_INVAL;
>                 goto error;
>         }
>
> @@ -581,7 +581,7 @@ uci_lua_reorder(lua_State *L)
>                 goto error;
>
>         if ((ptr.s == NULL) || (ptr.value == NULL)) {
> -               err = UCI_ERR_INVAL;
> +               ctx->err = UCI_ERR_INVAL;
>                 goto error;
>         }
>
> @@ -639,7 +639,7 @@ uci_lua_set(lua_State *L)
>                 ptr.option = NULL;
>                 break;
>         default:
> -               err = UCI_ERR_INVAL;
> +               ctx->err = UCI_ERR_INVAL;
>                 goto error;
>         }
>
> @@ -648,7 +648,7 @@ uci_lua_set(lua_State *L)
>                 goto error;
>
>         if (((ptr.s == NULL) && (ptr.option != NULL)) || (ptr.value == NULL)) {
> -               err = UCI_ERR_INVAL;
> +               ctx->err = UCI_ERR_INVAL;
>                 goto error;
>         }
>
>
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
diff mbox series

Patch

diff --git a/lua/uci.c b/lua/uci.c
index a7aaad375c20..1ed73e4f67dc 100644
--- a/lua/uci.c
+++ b/lua/uci.c
@@ -386,11 +386,11 @@  uci_lua_get_any(lua_State *L, bool all)
 
 	lookup_ptr(ctx, &ptr, NULL, true);
 	if (!all && !ptr.s) {
-		err = UCI_ERR_INVAL;
+		ctx->err = UCI_ERR_INVAL;
 		goto error;
 	}
 	if (!(ptr.flags & UCI_LOOKUP_COMPLETE)) {
-		err = UCI_ERR_NOTFOUND;
+		ctx->err = UCI_ERR_NOTFOUND;
 		goto error;
 	}
 
@@ -414,7 +414,7 @@  uci_lua_get_any(lua_State *L, bool all)
 			uci_push_option(L, ptr.o);
 			break;
 		default:
-			err = UCI_ERR_INVAL;
+			ctx->err = UCI_ERR_INVAL;
 			goto error;
 	}
 	if (s)
@@ -521,7 +521,7 @@  uci_lua_rename(lua_State *L)
 		ptr.option = NULL;
 		break;
 	default:
-		err = UCI_ERR_INVAL;
+		ctx->err = UCI_ERR_INVAL;
 		goto error;
 	}
 
@@ -530,7 +530,7 @@  uci_lua_rename(lua_State *L)
 		goto error;
 
 	if (((ptr.s == NULL) && (ptr.option != NULL)) || (ptr.value == NULL)) {
-		err = UCI_ERR_INVAL;
+		ctx->err = UCI_ERR_INVAL;
 		goto error;
 	}
 
@@ -562,7 +562,7 @@  uci_lua_reorder(lua_State *L)
 	case 1:
 		/* Format: uci.set("p.s=v") or uci.set("p.s=v") */
 		if (ptr.option) {
-			err = UCI_ERR_INVAL;
+			ctx->err = UCI_ERR_INVAL;
 			goto error;
 		}
 		break;
@@ -572,7 +572,7 @@  uci_lua_reorder(lua_State *L)
 		ptr.option = NULL;
 		break;
 	default:
-		err = UCI_ERR_INVAL;
+		ctx->err = UCI_ERR_INVAL;
 		goto error;
 	}
 
@@ -581,7 +581,7 @@  uci_lua_reorder(lua_State *L)
 		goto error;
 
 	if ((ptr.s == NULL) || (ptr.value == NULL)) {
-		err = UCI_ERR_INVAL;
+		ctx->err = UCI_ERR_INVAL;
 		goto error;
 	}
 
@@ -639,7 +639,7 @@  uci_lua_set(lua_State *L)
 		ptr.option = NULL;
 		break;
 	default:
-		err = UCI_ERR_INVAL;
+		ctx->err = UCI_ERR_INVAL;
 		goto error;
 	}
 
@@ -648,7 +648,7 @@  uci_lua_set(lua_State *L)
 		goto error;
 
 	if (((ptr.s == NULL) && (ptr.option != NULL)) || (ptr.value == NULL)) {
-		err = UCI_ERR_INVAL;
+		ctx->err = UCI_ERR_INVAL;
 		goto error;
 	}