Hi all,
I have just downloaded compiled and tested grx234s.zip from simtelnet
I have found a bug in __gr_text_installfont() contained in src/bgi/text1.c which prevents the loading of chr files. Comparing with grx-2.3.1 it is due to an error in an attempt to sanitize the last parameter (char *name) to make it const. In the old version it was modified in the function and pointed after exit to an invalid (freed) location. But one needs an other temporary pointer temp1 to keep the addresss of the origin of the temporary buffer allocated by temp, and pass temp1 to fopen(). After the while loop temp itself points to the end of the buffer !
The error is corrected by the following diff
diff -p -N -C3 -r grx234.ori/src/bgi/text1.c grx234/src/bgi/text1.c *** grx234.ori/src/bgi/text1.c Fri Jan 12 14:43:28 2001 --- grx234/src/bgi/text1.c Wed Feb 21 18:23:14 2001 *************** int __gr_text_installfont( int start, in *** 67,72 **** --- 67,73 ---- void *font; int res; char *temp = alloca(strlen(name)+1+4); + char *temp1;
#ifdef __linux__ # define CHG_CHAR '\' *************** int __gr_text_installfont( int start, in *** 79,85 **** if (temp != NULL) { int have_ext = FALSE; strcpy(temp, name); ! name = temp; while (*temp != '\0') { if (*temp == CHG_CHAR) *temp = NEW_CHAR; else *temp = (tolower)(*temp); --- 80,86 ---- if (temp != NULL) { int have_ext = FALSE; strcpy(temp, name); ! temp1 = temp; while (*temp != '\0') { if (*temp == CHG_CHAR) *temp = NEW_CHAR; else *temp = (tolower)(*temp); *************** int __gr_text_installfont( int start, in *** 88,97 **** ++temp; } if (!have_ext) ! strcat(temp, ".chr"); }
! ff = fopen(temp, "rb"); if (ff == NULL) return grFileNotFound; fseek( ff, 0, SEEK_END); --- 89,98 ---- ++temp; } if (!have_ext) ! strcat(temp1, ".chr"); }
! ff = fopen(temp1, "rb"); if (ff == NULL) return grFileNotFound; fseek( ff, 0, SEEK_END);
I have also corrected some pascal files:
bgi2grx.pas
it is necessary to correct the drawpoly and fillpoly declarations:
var PolyPoints: array of PointType
while being logical in pascal is wrong in an interface to C for an open array: gpc adds some invisible parameter(s) in addition to the address of the beginning of the array, which are not contained in the C parameters. The solution is to use an untyped variable:
var PolyPoints
I have also made some changes to make this file compile with more recent versions of gpc (change in declaration of external variables, removal of now invalid __soso__ declarations)
A diff containing these corrections, some other sanitizations, and makefiles for dj2 in the pascal directories, as well as the above diff can be retrieved at
ftp://agnes.dida.physik.uni-essen.de/home/maurice/grx234.diff
hope this helps
Maurice