From 6753e9960492b1398cf3daf81d37ae6059421a0b Mon Sep 17 00:00:00 2001 From: Michael du Breuil Date: Fri, 27 Mar 2020 19:45:43 -0700 Subject: [PATCH] AP_Scripting: Add a return around luaL_error This is the normal method of calling luaL_error which longjmp's away, and it helps the static analysis tools realize that anything afterwards will not be reached --- libraries/AP_Scripting/generator/src/main.c | 2 +- libraries/AP_Scripting/lua_generated_bindings.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/AP_Scripting/generator/src/main.c b/libraries/AP_Scripting/generator/src/main.c index faca5ca96e..f5759f6b48 100644 --- a/libraries/AP_Scripting/generator/src/main.c +++ b/libraries/AP_Scripting/generator/src/main.c @@ -1330,7 +1330,7 @@ void emit_userdata_method(const struct userdata *data, const struct method *meth // extract the userdata, it was a pointer, so we need to grab it fprintf(source, " %s * ud = *check_%s(L, 1);\n", data->name, data->sanatized_name); fprintf(source, " if (ud == NULL) {\n"); - fprintf(source, " luaL_error(L, \"Internal error, null pointer\");\n"); + fprintf(source, " return luaL_error(L, \"Internal error, null pointer\");\n"); fprintf(source, " }\n"); break; } diff --git a/libraries/AP_Scripting/lua_generated_bindings.cpp b/libraries/AP_Scripting/lua_generated_bindings.cpp index 7e678f8fbc..1e4b572b1a 100644 --- a/libraries/AP_Scripting/lua_generated_bindings.cpp +++ b/libraries/AP_Scripting/lua_generated_bindings.cpp @@ -2519,7 +2519,7 @@ static int AP_HAL__UARTDriver_set_flow_control(lua_State *L) { binding_argcheck(L, 2); AP_HAL::UARTDriver * ud = *check_AP_HAL__UARTDriver(L, 1); if (ud == NULL) { - luaL_error(L, "Internal error, null pointer"); + return luaL_error(L, "Internal error, null pointer"); } const lua_Integer raw_data_2 = luaL_checkinteger(L, 2); luaL_argcheck(L, ((raw_data_2 >= static_cast(AP_HAL::UARTDriver::FLOW_CONTROL_DISABLE)) && (raw_data_2 <= static_cast(AP_HAL::UARTDriver::FLOW_CONTROL_AUTO))), 2, "argument out of range"); @@ -2534,7 +2534,7 @@ static int AP_HAL__UARTDriver_available(lua_State *L) { binding_argcheck(L, 1); AP_HAL::UARTDriver * ud = *check_AP_HAL__UARTDriver(L, 1); if (ud == NULL) { - luaL_error(L, "Internal error, null pointer"); + return luaL_error(L, "Internal error, null pointer"); } const uint32_t data = ud->available(); @@ -2547,7 +2547,7 @@ static int AP_HAL__UARTDriver_write(lua_State *L) { binding_argcheck(L, 2); AP_HAL::UARTDriver * ud = *check_AP_HAL__UARTDriver(L, 1); if (ud == NULL) { - luaL_error(L, "Internal error, null pointer"); + return luaL_error(L, "Internal error, null pointer"); } const lua_Integer raw_data_2 = luaL_checkinteger(L, 2); luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(UINT8_MAX, UINT8_MAX))), 2, "argument out of range"); @@ -2564,7 +2564,7 @@ static int AP_HAL__UARTDriver_read(lua_State *L) { binding_argcheck(L, 1); AP_HAL::UARTDriver * ud = *check_AP_HAL__UARTDriver(L, 1); if (ud == NULL) { - luaL_error(L, "Internal error, null pointer"); + return luaL_error(L, "Internal error, null pointer"); } const int16_t data = ud->read(); @@ -2576,7 +2576,7 @@ static int AP_HAL__UARTDriver_begin(lua_State *L) { binding_argcheck(L, 2); AP_HAL::UARTDriver * ud = *check_AP_HAL__UARTDriver(L, 1); if (ud == NULL) { - luaL_error(L, "Internal error, null pointer"); + return luaL_error(L, "Internal error, null pointer"); } const uint32_t raw_data_2 = coerce_to_uint32_t(L, 2); luaL_argcheck(L, ((raw_data_2 >= MAX(1U, 0U)) && (raw_data_2 <= MIN(UINT32_MAX, UINT32_MAX))), 2, "argument out of range");