[Concept,15/42] video: Correct cursor handling when the the left side

Message ID 20250919201507.4024144-16-sjg@u-boot.org
State New
Headers
Series video: Support a cursor more generally |

Commit Message

Simon Glass Sept. 19, 2025, 8:14 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

There is normally a prompt which prevents the cursor ever being on the
far left. However we should check for this to avoid a potential crash.

Add a check for x being at least 0 in console_set_cursor_visible()

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/video/console_normal.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
  

Patch

diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c
index 9509f81f40f..68d47eb8da6 100644
--- a/drivers/video/console_normal.c
+++ b/drivers/video/console_normal.c
@@ -92,11 +92,12 @@  static int __maybe_unused console_set_cursor_visible(struct udevice *dev,
 		return -ENOSYS;
 
 	x += index * fontdata->width;
-	start = vid_priv->fb + y * vid_priv->line_length + x * pbytes;
 
 	/* place the cursor 1 pixel before the start of the next char */
-	x -= 1;
+	if (x > 0)
+		x -= 1;
 
+	start = vid_priv->fb + y * vid_priv->line_length + x * pbytes;
 	line = start;
 	draw_cursor_vertically(&line, vid_priv, vc_priv->y_charsize,
 			       NORMAL_DIRECTION);