server/telnet: enhance telnet_move_cursor
[fw/openocd] / src / server / telnet_server.c
index f7b3f6449bbfda33c3daa894a1ad963f7ccdb052..36b017c58ebb2916d81ad42b7ca0e5b6c5eca4e4 100644 (file)
@@ -352,10 +352,14 @@ static int telnet_history_print(struct connection *connection)
 
 static void telnet_move_cursor(struct connection *connection, size_t pos)
 {
-       struct telnet_connection *tc;
+       struct telnet_connection *tc = connection->priv;
        size_t tmp;
 
-       tc = connection->priv;
+       if (pos == tc->line_cursor) /* nothing to do */
+               return;
+
+       if (pos > tc->line_size) /* out of bounds */
+               return;
 
        if (pos < tc->line_cursor) {
                tmp = tc->line_cursor - pos;