Skip to content
Snippets Groups Projects
Commit 61d3c0d5 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Fix font insanity and Clang warnings.

Since this was originally Pascal, there's a tonne of 1-based indexed
arrays, and the font ones were sized by number of elements, meaning
it was chock full of buffer overflows.  Also, the Pascal string
handling was crazy.

There were also some file IO issues floating around.

This fixes all of those issues and also Closes #179
parent f63b6ad6
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #673 passed
...@@ -208,7 +208,7 @@ blockcenter(void) ...@@ -208,7 +208,7 @@ blockcenter(void)
blocklefttrim(); blocklefttrim();
for (y = Y1; y <= Y2; y++) { for (y = Y1; y <= Y2; y++) {
for (x = X1; x <= X2; x++) for (x = X1; x <= X2; x++)
if ((Screen[ActivePage][y][x << 1] == 32)) if (Screen[ActivePage][y][x << 1] == 32)
d++; d++;
d /= 2; d /= 2;
while (d >= 1) { while (d >= 1) {
......
...@@ -29,11 +29,13 @@ insertfont(char *Name) ...@@ -29,11 +29,13 @@ insertfont(char *Name)
fseek(fp, 0, SEEK_SET); fseek(fp, 0, SEEK_SET);
/* Read Font Header in TDFont */ /* Read Font Header in TDFont */
TDFont.Sign[0] = fgetc(fp); TDFont.Sign[0] = fgetc(fp);
for (x = 0; x < 19; x++) for (x = 1; x < 20; x++)
TDFont.Sign[x] = fgetc(fp); TDFont.Sign[x] = fgetc(fp);
TDFont.Sign[18] = 0; TDFont.Sign[19] = 0;
if (strcmp(TDFont.Sign, "TheDraw FONTS file") != 0) if (strcmp(TDFont.Sign, "\x13" "TheDraw FONTS file") != 0) {
printf("Invalid font file %s\n", Name);
return; return;
}
for (x = 0; x <= 3; x++) for (x = 0; x <= 3; x++)
TDFont.a[x] = fgetc(fp); TDFont.a[x] = fgetc(fp);
for (x = 0; x <= 16; x++) for (x = 0; x <= 16; x++)
...@@ -50,7 +52,7 @@ insertfont(char *Name) ...@@ -50,7 +52,7 @@ insertfont(char *Name)
Header.NumberofFonts++; Header.NumberofFonts++;
/* Make FontRecord */ /* Make FontRecord */
memcpy(&fr[Header.NumberofFonts].FontName, &TDFont.Name, 16); memcpy(&fr[Header.NumberofFonts].FontName, &TDFont.Name, 17);
fr[Header.NumberofFonts].Length = size; fr[Header.NumberofFonts].Length = size;
fr[Header.NumberofFonts].FilePos = FilePos; fr[Header.NumberofFonts].FilePos = FilePos;
FilePos += size; FilePos += size;
...@@ -82,9 +84,6 @@ int main(int argnum, char *args[]) ...@@ -82,9 +84,6 @@ int main(int argnum, char *args[])
printf("can't open %s for read\n",args[1]); printf("can't open %s for read\n",args[1]);
return(1); return(1);
} }
CreateFontFile();
/*Huh ? It 's not open! */
/* fseek(font, 0, SEEK_SET); */
while (1) { while (1) {
fgets(filename, 255, fp); fgets(filename, 255, fp);
if (!feof(fp)) { if (!feof(fp)) {
...@@ -107,13 +106,13 @@ int main(int argnum, char *args[]) ...@@ -107,13 +106,13 @@ int main(int argnum, char *args[])
return(1); return(1);
} }
/* Header */ /* Header */
fwrite(&Header.sign, 1, 10, font); fwrite("\x09" "Font File", 10, 1, font);
Header.NumberofFonts=LE_SHORT(Header.NumberofFonts); Header.NumberofFonts=LE_SHORT(Header.NumberofFonts);
fwrite(&Header.NumberofFonts, 2, 1, font); fwrite(&Header.NumberofFonts, 2, 1, font);
Header.NumberofFonts=LE_SHORT(Header.NumberofFonts); Header.NumberofFonts=LE_SHORT(Header.NumberofFonts);
/* Font Headers */ /* Font Headers */
for (x = 1; x <= Header.NumberofFonts; x++) { for (x = 1; x <= Header.NumberofFonts; x++) {
for (y = 0; y <= 16; y++) for (y = 0; y < 17; y++)
fputc(fr[x].FontName[y], font); fputc(fr[x].FontName[y], font);
fr[x].FilePos=LE_LONG(fr[x].FilePos); fr[x].FilePos=LE_LONG(fr[x].FilePos);
fwrite(&fr[x].FilePos, 4, 1, font); fwrite(&fr[x].FilePos, 4, 1, font);
......
...@@ -22,24 +22,24 @@ DrawBox(int x1, int y1, int x2, int y2) ...@@ -22,24 +22,24 @@ DrawBox(int x1, int y1, int x2, int y2)
exit(1); exit(1);
i=0; i=0;
buf[i++]=218; buf[i++]='\xda';
buf[i++]=ATTR_NORM_HIGH; buf[i++]=ATTR_NORM_HIGH;
for(x=2;x<=width-4;x++) { for(x=2;x<=width-4;x++) {
buf[i++]=196; buf[i++]='\xc4';
buf[i++]=ATTR_NORM_HIGH; buf[i++]=ATTR_NORM_HIGH;
} }
buf[i++]=196; buf[i++]='\xc4';
buf[i++]=ATTR_NORM_HIGH; buf[i++]=ATTR_NORM_HIGH;
buf[i++]=191; buf[i++]='\xbf';
buf[i++]=ATTR_NORM_HIGH; buf[i++]=ATTR_NORM_HIGH;
puttext(x1,y1,x2,y1,buf); puttext(x1,y1,x2,y1,buf);
buf[i-2]=217; buf[i-2]='\xd9';
buf[0]=192; buf[0]='\xc0';
puttext(x1,y2,x2,y2,buf); puttext(x1,y2,x2,y2,buf);
i=0; i=0;
for(y=1; y<=height-2;y++) { for(y=1; y<=height-2;y++) {
buf[i++]=179; buf[i++]='\xb3';
if(y==1 || y==height-2) if(y==1 || y==height-2)
buf[i++]=ATTR_NORM_HIGH; buf[i++]=ATTR_NORM_HIGH;
else if (y==2 || y==height-3) else if (y==2 || y==height-3)
......
...@@ -6,14 +6,14 @@ ...@@ -6,14 +6,14 @@
#include "homedir.h" #include "homedir.h"
#include "fonts.h" #include "fonts.h"
#define TheDrawFontSize 254 #define TheDrawFontSize 252
MysticDrawFontHeader Header; MysticDrawFontHeader Header;
FontRecord FontRec; FontRecord FontRec;
TheDrawFont TDFont; TheDrawFont TDFont;
unsigned short SFont; unsigned short SFont;
unsigned char Outline, MaxX, MaxY; unsigned char Outline, MaxX, MaxY;
unsigned char Chars[60][24]; unsigned char Chars[61][25];
char *OutlineCharSet[20] = { char *OutlineCharSet[20] = {
"컴납悶悶잎잎늘 ", "컴납悶悶잎잎늘 ",
"羔납辣悶禿잎돤 ", "羔납辣悶禿잎돤 ",
......
...@@ -4,18 +4,18 @@ ...@@ -4,18 +4,18 @@
#define HeaderSize 12 #define HeaderSize 12
#define FontRecordSize 25 #define FontRecordSize 25
typedef struct { typedef struct {
char FontName[16]; char FontName[17];
unsigned long FilePos; unsigned long FilePos;
unsigned long Length; unsigned long Length;
} FontRecord; } FontRecord;
typedef struct { typedef struct {
char sign[9]; char sign[10];
unsigned short NumberofFonts; unsigned short NumberofFonts;
} MysticDrawFontHeader; } MysticDrawFontHeader;
typedef struct { typedef struct {
char Sign[19]; char Sign[20];
char a[3]; char a[3];
char Name[16]; char Name[16];
unsigned char FontType; unsigned char FontType;
...@@ -30,7 +30,7 @@ extern FontRecord FontRec; ...@@ -30,7 +30,7 @@ extern FontRecord FontRec;
extern TheDrawFont TDFont; extern TheDrawFont TDFont;
extern unsigned short SFont; extern unsigned short SFont;
extern unsigned char Outline, MaxX, MaxY; extern unsigned char Outline, MaxX, MaxY;
extern unsigned char Chars[60][24]; extern unsigned char Chars[61][25];
void CreateFontFile(void); void CreateFontFile(void);
void Openfont(int num); void Openfont(int num);
......
...@@ -143,6 +143,7 @@ void ...@@ -143,6 +143,7 @@ void
ShowFont(int number) ShowFont(int number)
{ {
int a = 0, x, ch; int a = 0, x, ch;
textattr(7);
clrscr(); clrscr();
Openfont(number); Openfont(number);
do { do {
...@@ -186,6 +187,7 @@ ShowFont(int number) ...@@ -186,6 +187,7 @@ ShowFont(int number)
break; break;
} }
} while (toupper(ch) != 'Q'); } while (toupper(ch) != 'Q');
textattr(7);
clrscr(); clrscr();
} }
...@@ -241,7 +243,7 @@ main(int argc, char **argv) ...@@ -241,7 +243,7 @@ main(int argc, char **argv)
textattr(24); textattr(24);
else else
textattr(8); textattr(8);
for (x = x; x <= 16; x++) for (; x <= 16; x++)
putch(250); putch(250);
textattr(10); textattr(10);
cprintf("%02d", (size[y + c] / 1024)); cprintf("%02d", (size[y + c] / 1024));
...@@ -326,6 +328,7 @@ main(int argc, char **argv) ...@@ -326,6 +328,7 @@ main(int argc, char **argv)
fclose(fp); fclose(fp);
fclose(fp2); fclose(fp2);
fclose(fp3); fclose(fp3);
textattr(7);
clrscr(); clrscr();
break; break;
} }
...@@ -393,6 +396,7 @@ main(int argc, char **argv) ...@@ -393,6 +396,7 @@ main(int argc, char **argv)
fclose(fp3); fclose(fp3);
remove(FontFile); remove(FontFile);
rename("tmp.fnt", FontFile); rename("tmp.fnt", FontFile);
textattr(7);
clrscr(); clrscr();
break; break;
case 10: case 10:
......
...@@ -605,14 +605,14 @@ LoadFile(char *Name) ...@@ -605,14 +605,14 @@ LoadFile(char *Name)
TxtCol = 7; TxtCol = 7;
LastLine = 0; LastLine = 0;
ch = strlen(Name) - 3; ch = strlen(Name) - 3;
if ((toupper(Name[ch++]) == 'B') & (toupper(Name[ch++]) == 'I') & (toupper(Name[ch]) == 'N')) { if ((toupper(Name[ch++]) == 'B') && (toupper(Name[ch++]) == 'I') && (toupper(Name[ch]) == 'N')) {
unsigned char line[160]; unsigned char line[160];
do { do {
fread(&line, 1, 160, fp); fread(&line, 1, 160, fp);
memcpy(Screen[ActivePage][CursY], &line, 160); memcpy(Screen[ActivePage][CursY], &line, 160);
CursY++; CursY++;
} while (!feof(fp)); } while (!feof(fp));
} else } else {
/* Check for "known" extensions */ /* Check for "known" extensions */
ext=getfext(Name); ext=getfext(Name);
if(ext) { if(ext) {
...@@ -665,6 +665,7 @@ LoadFile(char *Name) ...@@ -665,6 +665,7 @@ LoadFile(char *Name)
} }
} while ((avt_rep && b == 3) || (ans_rep > 0)); } while ((avt_rep && b == 3) || (ans_rep > 0));
} while (!feof(fp)); } while (!feof(fp));
}
ReadSauce(fp); ReadSauce(fp);
fclose(fp); fclose(fp);
LastLine = CursY; LastLine = CursY;
...@@ -799,7 +800,7 @@ load(void) ...@@ -799,7 +800,7 @@ load(void)
attr=(7 + 16); attr=(7 + 16);
else else
attr=(7); attr=(7);
buf[(x*77+13)*2]=250; buf[(x*77+13)*2]='\xfa';
buf[(x*77+13)*2+1]=attr; buf[(x*77+13)*2+1]=attr;
if (y == x) if (y == x)
attr=(15 + 16); attr=(15 + 16);
...@@ -810,7 +811,7 @@ load(void) ...@@ -810,7 +811,7 @@ load(void)
attr=(7 + 16); attr=(7 + 16);
else else
attr=(7); attr=(7);
buf[(x*77+42)*2]=250; buf[(x*77+42)*2]='\xfa';
buf[(x*77+42)*2+1]=attr; buf[(x*77+42)*2+1]=attr;
if (y == x) if (y == x)
attr=(15 + 16); attr=(15 + 16);
...@@ -821,7 +822,7 @@ load(void) ...@@ -821,7 +822,7 @@ load(void)
textattr(7 + 16); textattr(7 + 16);
else else
textattr(7); textattr(7);
buf[(x*77+61)*2]=250; buf[(x*77+61)*2]='\xfa';
buf[(x*77+61)*2+1]=attr; buf[(x*77+61)*2+1]=attr;
if (y == x) if (y == x)
attr=(15 + 16); attr=(15 + 16);
......
...@@ -135,7 +135,7 @@ Menues(int x, int y) ...@@ -135,7 +135,7 @@ Menues(int x, int y)
int int
menue(void) menue(void)
{ {
int x, a, b, i; int a, b, i;
char buf[80*2*2]; char buf[80*2*2];
b = 0; b = 0;
ActiveMenue = 1; ActiveMenue = 1;
...@@ -144,7 +144,7 @@ menue(void) ...@@ -144,7 +144,7 @@ menue(void)
if (ActiveMenue != b) { if (ActiveMenue != b) {
ShowScreen(0, 0); ShowScreen(0, 0);
i=0; i=0;
buf[i++]=223; buf[i++]='\xdf';
buf[i++]=ATTR_NORM_LOW; buf[i++]=ATTR_NORM_LOW;
i+=bufprintf(buf+i,ActiveMenue==1?ATTR_NORM_BAR_CURR:ATTR_NORM_BAR," FILES "); i+=bufprintf(buf+i,ActiveMenue==1?ATTR_NORM_BAR_CURR:ATTR_NORM_BAR," FILES ");
i+=bufprintf(buf+i,ActiveMenue==2?ATTR_NORM_BAR_CURR:ATTR_NORM_BAR,"FONTS "); i+=bufprintf(buf+i,ActiveMenue==2?ATTR_NORM_BAR_CURR:ATTR_NORM_BAR,"FONTS ");
...@@ -153,11 +153,11 @@ menue(void) ...@@ -153,11 +153,11 @@ menue(void)
i+=bufprintf(buf+i,ActiveMenue==5?ATTR_NORM_BAR_CURR:ATTR_NORM_BAR,"MISC. "); i+=bufprintf(buf+i,ActiveMenue==5?ATTR_NORM_BAR_CURR:ATTR_NORM_BAR,"MISC. ");
i+=bufprintf(buf+i,ActiveMenue==6?ATTR_NORM_BAR_CURR:ATTR_NORM_BAR,"TOGGLES "); i+=bufprintf(buf+i,ActiveMenue==6?ATTR_NORM_BAR_CURR:ATTR_NORM_BAR,"TOGGLES ");
i+=bufprintf(buf+i,ActiveMenue==7?ATTR_NORM_BAR_CURR:ATTR_NORM_BAR,"HELP"); i+=bufprintf(buf+i,ActiveMenue==7?ATTR_NORM_BAR_CURR:ATTR_NORM_BAR,"HELP");
buf[i++]=219; buf[i++]='\xdb';
buf[i++]=ATTR_NORM_LOW; buf[i++]=ATTR_NORM_LOW;
buf[i++]=220; buf[i++]='\xdc';
buf[i++]=ATTR_NORM_LOW; buf[i++]=ATTR_NORM_LOW;
buf[i++]=223; buf[i++]='\xdf';
buf[i]=ATTR_NORM_LOW; buf[i]=ATTR_NORM_LOW;
puttext(1,1,80,1,buf); puttext(1,1,80,1,buf);
} }
......
...@@ -266,31 +266,31 @@ SelectColor(void) ...@@ -266,31 +266,31 @@ SelectColor(void)
memset(buf,0,sizeof(buf)); memset(buf,0,sizeof(buf));
bufprintf(buf+(5*51+21)*2,8,"B - BLINK"); bufprintf(buf+(5*51+21)*2,8,"B - BLINK");
i=(1*51+2)*2; i=(1*51+2)*2;
buf[i++]=176; buf[i++]='\xb0';
buf[i++]=15; buf[i++]=15;
buf[i++]=176; buf[i++]='\xb0';
buf[i++]=15; buf[i++]=15;
buf[i++]=32; buf[i++]=32;
buf[i++]=15; buf[i++]=15;
for (a = 1; a <= 15; a++) { for (a = 1; a <= 15; a++) {
buf[i++]=219; buf[i++]='\xdb';
buf[i++]=a; buf[i++]=a;
buf[i++]=219; buf[i++]='\xdb';
buf[i++]=a; buf[i++]=a;
buf[i++]=32; buf[i++]=32;
buf[i++]=a; buf[i++]=a;
} }
i=(3*51+13)*2; i=(3*51+13)*2;
buf[i++]=176; buf[i++]='\xb0';
buf[i++]=15; buf[i++]=15;
buf[i++]=176; buf[i++]='\xb0';
buf[i++]=15; buf[i++]=15;
buf[i++]=32; buf[i++]=32;
buf[i++]=15; buf[i++]=15;
for (a = 1; a <= 7; a++) { for (a = 1; a <= 7; a++) {
buf[i++]=219; buf[i++]='\xdb';
buf[i++]=a; buf[i++]=a;
buf[i++]=219; buf[i++]='\xdb';
buf[i++]=a; buf[i++]=a;
buf[i++]=32; buf[i++]=32;
buf[i++]=a; buf[i++]=a;
...@@ -415,7 +415,7 @@ translate(char a) ...@@ -415,7 +415,7 @@ translate(char a)
case 'N': case 'N':
return ''; return '';
case 'u': case 'u':
return 150; return '\x96';
case 'U': case 'U':
return ''; return '';
case 'Y': case 'Y':
...@@ -464,7 +464,7 @@ inputfield(char *Str, int length, int x1, int y) ...@@ -464,7 +464,7 @@ inputfield(char *Str, int length, int x1, int y)
oldy=wherey(); oldy=wherey();
do { do {
for (x = 1; x <= length; x++) { for (x = 1; x <= length; x++) {
buf[(x-1)*2]=250; buf[(x-1)*2]='\xfa';
buf[(x-1)*2+1]=8; buf[(x-1)*2+1]=8;
} }
bufprintf(buf,7,"%.*s",length,nul); bufprintf(buf,7,"%.*s",length,nul);
......
...@@ -309,21 +309,21 @@ SauceSet(void) ...@@ -309,21 +309,21 @@ SauceSet(void)
do { do {
bufprintf(buf,15,"%s",SauceDescr.Title); bufprintf(buf,15,"%s",SauceDescr.Title);
for (b = strlen(SauceDescr.Title); b < 35; b++) { for (b = strlen(SauceDescr.Title); b < 35; b++) {
buf[b*2]=250; buf[b*2]='\xfa';
buf[b*2+1]=7; buf[b*2+1]=7;
} }
puttext(29,11,63,11,buf); puttext(29,11,63,11,buf);
bufprintf(buf,15,"%s", SauceDescr.Author); bufprintf(buf,15,"%s", SauceDescr.Author);
for (b = strlen(SauceDescr.Author); b < 20; b++) { for (b = strlen(SauceDescr.Author); b < 20; b++) {
buf[b*2]=250; buf[b*2]='\xfa';
buf[b*2+1]=7; buf[b*2+1]=7;
} }
puttext(29,12,48,12,buf); puttext(29,12,48,12,buf);
bufprintf(buf,15,"%s", SauceDescr.Group); bufprintf(buf,15,"%s", SauceDescr.Group);
for (b = strlen(SauceDescr.Group); b < 20; b++) { for (b = strlen(SauceDescr.Group); b < 20; b++) {
buf[b*2]=250; buf[b*2]='\xfa';
buf[b*2+1]=7; buf[b*2+1]=7;
} }
puttext(29, 13, 48, 13, buf); puttext(29, 13, 48, 13, buf);
......
...@@ -1062,7 +1062,6 @@ main(int argnum, char *args[]) ...@@ -1062,7 +1062,6 @@ main(int argnum, char *args[])
CharSet[9] = NCharSet[9]; CharSet[9] = NCharSet[9];
CharSet[10] = NCharSet[10]; CharSet[10] = NCharSet[10];
CharSet[11] = NCharSet[11]; CharSet[11] = NCharSet[11];
CharSet[12] = NCharSet[12];
for (a = 0; a < 4; a++) for (a = 0; a < 4; a++)
for (y = 0; y <= MaxLines; y++) { for (y = 0; y <= MaxLines; y++) {
......
...@@ -48,10 +48,10 @@ tabsetup(void) ...@@ -48,10 +48,10 @@ tabsetup(void)
memset(buf,0,sizeof(buf)); memset(buf,0,sizeof(buf));
for (y = 1; y <= 80; y++) { for (y = 1; y <= 80; y++) {
if (tabs[y] == TRUE) { if (tabs[y] == TRUE) {
buf[(y-1)*2]=254; buf[(y-1)*2]='\xfe';
buf[(y-1)*2+1]=7; buf[(y-1)*2+1]=7;
} else { } else {
buf[(y-1)*2]=250; buf[(y-1)*2]='\xfa';
buf[(y-1)*2+1]=7; buf[(y-1)*2+1]=7;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment