mirror of
https://github.com/ArduPilot/ardupilot.git
synced 2026-02-08 01:02:00 +08:00
AP_Scripting: use luaL_checklstring for serial port writestring
Avoids potential null pointer dereferences if a port write method can't handle a null pointer when doing a zero length write. Also provides a nice type error if something that can't be converted to a string is passed.
This commit is contained in:
committed by
Andrew Tridgell
parent
a20dd5af68
commit
55889f6db7
@@ -813,7 +813,7 @@ int lua_serial_writestring(lua_State *L)
|
||||
|
||||
// get the bytes the user wants to write, along with their length
|
||||
size_t req_bytes;
|
||||
const char *data = lua_tolstring(L, 2, &req_bytes);
|
||||
const char *data = luaL_checklstring(L, 2, &req_bytes);
|
||||
|
||||
// write up to that number of bytes
|
||||
const uint32_t written_bytes = port->write((const uint8_t*)data, req_bytes);
|
||||
|
||||
Reference in New Issue
Block a user