From 6d055e5df19bb4d85712d7a6c60a0563efecd382 Mon Sep 17 00:00:00 2001 From: SteveMcNeill Date: Thu, 24 Nov 2022 08:34:31 -0500 Subject: [PATCH 1/3] Bugfix to _FONT Fonts 9, 15, and 17 can *only* be used in SCREEN 0. Attempting to use them in graphic screens results in a seg fault and an instant program crash on Windows. This is definitely the most undesirable of behaviors for a program, and can easily be caught and dealt with just by tossing a simple "Illegal Function Call" error for the issue. --- internal/c/libqb.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/internal/c/libqb.cpp b/internal/c/libqb.cpp index 32ace64ff..afafd3dd5 100644 --- a/internal/c/libqb.cpp +++ b/internal/c/libqb.cpp @@ -25788,16 +25788,31 @@ void sub__font(int32 f, int32 i, int32 passed) { i2 = 0; if (f == 8) i2 = 1; - if (f == 9) + if (f == 9) { i2 = 1; + if (!im->text) { + error(5); + return; + } // font 9 can *only* be used on text surfaces + } if (f == 14) i2 = 1; - if (f == 15) + if (f == 15) { i2 = 1; + if (!im->text) { + error(5); + return; + } // font 15 can *only* be used on text surfaces + } if (f == 16) i2 = 1; - if (f == 17) + if (f == 17) { i2 = 1; + if (!im->text) { + error(5); + return; + } // font 17 can *only* be used on text surfaces + } if (f >= 32 && f <= lastfont) { if (font[f]) i2 = 1; From 0d76a7bbedea1c707956da1025e1cf3c7b9866f9 Mon Sep 17 00:00:00 2001 From: SteveMcNeill Date: Thu, 24 Nov 2022 15:00:54 -0500 Subject: [PATCH 2/3] Simplify multi-line logic to single line. --- internal/c/libqb.cpp | 38 ++++++++------------------------------ 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/internal/c/libqb.cpp b/internal/c/libqb.cpp index afafd3dd5..691ec39ca 100644 --- a/internal/c/libqb.cpp +++ b/internal/c/libqb.cpp @@ -25761,7 +25761,7 @@ got_font_index: void sub__font(int32 f, int32 i, int32 passed) { //_FONT "?[,?]" - static int32 i2; + int32 i2 = 0; //no need for a static variable here, when we just init it to zero before ever using it. static img_struct *im; if (new_error) return; @@ -25785,33 +25785,11 @@ void sub__font(int32 f, int32 i, int32 passed) { } im = &img[i]; // validate f - i2 = 0; - if (f == 8) + if ((f == 8) || (f == 9) || ((f > 13) && (f < 18))) // built-in fonts 8, 9, 13, 14, 15, 16 should be valid i2 = 1; - if (f == 9) { - i2 = 1; - if (!im->text) { - error(5); - return; - } // font 9 can *only* be used on text surfaces - } - if (f == 14) - i2 = 1; - if (f == 15) { - i2 = 1; - if (!im->text) { - error(5); - return; - } // font 15 can *only* be used on text surfaces - } - if (f == 16) - i2 = 1; - if (f == 17) { - i2 = 1; - if (!im->text) { - error(5); - return; - } // font 17 can *only* be used on text surfaces + if (((f == 9) || (f == 15) || (f == 17)) && (!im->text)) { // but 9, 15, and 17 are *ONLY* valid for text screes + error(5); + return; } if (f >= 32 && f <= lastfont) { if (font[f]) @@ -25822,10 +25800,10 @@ void sub__font(int32 f, int32 i, int32 passed) { return; } - if (im->text && ((fontflags[f] & 16) == 0)) { - error(5); + if (im->text && ((fontflags[f] & 16) == 0)) { // fontflags[f] & 16 is the bit which we set for MONOSPACE fonts. If it's a SCREEN 0 screen, and the font + error(5);// isn't monospaced, toss and error and return. return; - } // only monospace fonts can be used on text surfaces + } // note: font changes to text screen mode images requires: // i) font change across all screen pages // ii) locking of the display From ca7d6ee289bbd1fee79200999b19587865435823 Mon Sep 17 00:00:00 2001 From: SteveMcNeill Date: Fri, 25 Nov 2022 00:52:29 -0500 Subject: [PATCH 3/3] fix comment Whoops! Not enough coffee, I guess. ;) --- internal/c/libqb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/c/libqb.cpp b/internal/c/libqb.cpp index 691ec39ca..dc60e93ec 100644 --- a/internal/c/libqb.cpp +++ b/internal/c/libqb.cpp @@ -25785,7 +25785,7 @@ void sub__font(int32 f, int32 i, int32 passed) { } im = &img[i]; // validate f - if ((f == 8) || (f == 9) || ((f > 13) && (f < 18))) // built-in fonts 8, 9, 13, 14, 15, 16 should be valid + if ((f == 8) || (f == 9) || ((f > 13) && (f < 18))) // built-in fonts 8, 9, 14, 15, 16, 17 should be valid i2 = 1; if (((f == 9) || (f == 15) || (f == 17)) && (!im->text)) { // but 9, 15, and 17 are *ONLY* valid for text screes error(5);