yterm

commit 334bdb20260ea6991668fdb9d7e20994d0502f3f

Author: mesyeti <mesyeti@mesyeti.uk>

fix UB

 source/backends/soft.c | 9 +++++++--
 source/buffer.c | 9 ++++++++-
 source/event.c | 3 ++-
 source/interpreter.c | 4 ++--
 source/interpreter.h | 4 ++--
 source/interpreter/vt100.c | 7 ++++---
 source/terminal.c | 1 +


diff --git a/source/backends/soft.c b/source/backends/soft.c
index d1adf6856c4944f1d1bbee20d5308610d2b997b8..c4fd69d57a0f277ed56a1321adc82b77e75c9c1a 100644
--- a/source/backends/soft.c
+++ b/source/backends/soft.c
@@ -33,8 +33,9 @@
 static State state;
 
 static uint32_t ColourToPixel(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
-	return r | (g << 8) | (b << 16) | (a << 24);
-	//return r + (rand() % 20) | (g + (rand() % 20) << 8) | (b + (rand() % 20) << 16) | (a << 24);
+	return
+		((uint32_t) r) | (((uint32_t) g) << 8) | (((uint32_t) b) << 16) |
+		(((uint32_t) a) << 24);
 }
 
 static void DrawPixel(int x, int y, uint32_t colour) {
@@ -167,6 +168,10 @@ 			if ((src.x + ix >= texture->width) || (src.y + iy >= texture->height)) continue;
 
 			int sx = ix + src.x;
 			int sy = iy + src.y;
+
+			if ((sx < 0) || (sx >= texture->width) || (sy < 0) || (sy >= texture->height)) {
+				continue;
+			}
 
 			uint32_t srcPix = texture->pixels[(sy * texture->aWidth) + sx];
 			uint8_t  alpha  = Component(srcPix, 3);




diff --git a/source/buffer.c b/source/buffer.c
index 402e9584e8ea282e86f7fb8fb7530628231fdc0a..73ba50f8dbc3a5451c6988728eba1dc95b00b519 100644
--- a/source/buffer.c
+++ b/source/buffer.c
@@ -178,7 +178,14 @@ 	else if (by < 0) {
 		by = -by;
 
 		for (int i = buf->height - by; i --> 0;) {
-			
+			BufCell* src  = Buffer_Get(buf, 0, i - by);
+			BufCell* dest = Buffer_Get(buf, 0, i);
+
+			memcpy(dest, src, rowSize);
+		}
+
+		for (int i = 0; i < by; ++ i) {
+			Buffer_ClearLine(buf, i, BufAttr_Default());
 		}
 	}
 }




diff --git a/source/event.c b/source/event.c
index 38cf4065c13461af13ab7ad36e7f94fee5f92251..5b53cc5d61fa8abbabc3c19fa5842d8c67d74775 100644
--- a/source/event.c
+++ b/source/event.c
@@ -61,7 +61,8 @@ 			}
 		}
 	}
 
-	events[FindFree()] = e;
+	int idx = FindFree();
+	events[idx] = e;
 }
 
 void Event_Update(void) {




diff --git a/source/interpreter/vt100.c b/source/interpreter/vt100.c
index 14462bc90de85b5c29786a68386a68b2f1c55e76..0c50f8a68a48bb9202588fb6ba4f43ca30c0bb70 100644
--- a/source/interpreter/vt100.c
+++ b/source/interpreter/vt100.c
@@ -743,9 +743,10 @@ 		}
 	}
 }
 
-static void OnResize(Interpreter* this, Terminal* terminal) {
-	(void) this;
-	(void) terminal;
+static void OnResize(Interpreter* p_this, Terminal* terminal, int w, int h) {
+	Vt100* this = (Vt100*) p_this->data;
+
+	
 }
 
 static void OnPaste(Interpreter* p_this, Terminal* terminal, const char* data) {




diff --git a/source/interpreter.c b/source/interpreter.c
index 3f685d26a9b4453000e66d6e09720fe1d5667e3a..f5cc7000a26c1d76b42aee1cdb5d7ecda9249cc6 100644
--- a/source/interpreter.c
+++ b/source/interpreter.c
@@ -9,8 +9,8 @@ void Interpreter_OnRead(Interpreter* this, Terminal* terminal, UChar ch) {
 	this->onRead(this, terminal, ch);
 }
 
-void Interpreter_OnResize(Interpreter* this, Terminal* terminal) {
-	this->onResize(this, terminal);
+void Interpreter_OnResize(Interpreter* this, Terminal* terminal, int w, int h) {
+	this->onResize(this, terminal, w, h);
 }
 
 void Interpreter_OnPaste(Interpreter* this, Terminal* terminal, const char* data) {




diff --git a/source/interpreter.h b/source/interpreter.h
index 3c616f7e2a5eb6a8597a2612a29a5b469df992de..a51385f8f4d92ac5b50405ee4237abdcf7b1283a 100644
--- a/source/interpreter.h
+++ b/source/interpreter.h
@@ -10,13 +10,13 @@ 	void* data;
 
 	void (*sendInput)(Interpreter* this, Terminal* terminal, Event* e);
 	void (*onRead)(Interpreter* this, Terminal* terminal, UChar ch);
-	void (*onResize)(Interpreter* this, Terminal* terminal);
+	void (*onResize)(Interpreter* this, Terminal* terminal, int w, int h);
 	void (*onPaste)(Interpreter* this, Terminal* terminal, const char* data);
 };
 
 void Interpreter_SendInput(Interpreter* this, Terminal* terminal, Event* e);
 void Interpreter_OnRead(Interpreter* this, Terminal* terminal, UChar ch);
-void Interpreter_OnResize(Interpreter* this, Terminal* terminal);
+void Interpreter_OnResize(Interpreter* this, Terminal* terminal, int w, int h);
 void Interpreter_OnPaste(Interpreter* this, Terminal* terminal, const char* data);
 
 #endif




diff --git a/source/terminal.c b/source/terminal.c
index e791b979855b03fe0313720fe7f7c174a0a488dd..248e58b03940c5b3308813984162035fbf2e0dac 100644
--- a/source/terminal.c
+++ b/source/terminal.c
@@ -64,4 +64,5 @@ 	terminal->height  = h;
 
 	Buffer_Resize(&terminal->buffer,    w, terminal->buffer.height);
 	SysTerm_UpdateSize(&terminal->term, w, h);
+	Interpreter_OnResize((Interpreter*) terminal->interpreter, terminal, w, h);
 }