Xref: news2.mv.net comp.os.linux.development.apps:21130 comp.os.msdos.djgpp:7551 Newsgroups: comp.os.msdos.djgpp,comp.os.linux.development.apps From: dolittle AT weniac DOT math DOT toronto DOT edu (Ed Doolittle) Subject: Linux libgrx 1.0.4, g++ segfaults solved Message-ID: Sender: news AT utcc DOT utoronto DOT ca (News) Reply-To: dolittle AT math DOT toronto DOT edu Organization: UTCC Campus Access Date: Fri, 16 Aug 1996 01:52:03 GMT Lines: 63 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp I posted previously on the subject of segfaults in g++ programs linked with libgrx under Linux. It took me quite a while to track the problem down, but thanks to the advice of a number of kind people on these newsgroups I have found what seems to be a number of errors in Linux libgrx 1.0.4. In order to do the job, I had to do the following. * recompile the library with debugging information * link the applications with ElectricFence * run them under gdb on a second terminal attached to my computer with standard error redirected to the currently displayed virtual console, e.g., gdb testshape 2> /dev/tty1 The latter step was necessary because variables and pointers would get corrupted when gdb forced the console back into text mode after a segfault, rendering the backtrace information almost worthless. Three off-by-one errors turned up in lnxmode.c. I suspect there may be more, but someone who knows more about the code ought to have a look at it to determine whether the errors I have identified really are errors, and check that I have fixed them properly, and make sure that there are no others. I'm all set up to debug the library now :) so if someone wants to send me code to test, I would be more than happy. Ed --- lnxmode.c.orig Thu Aug 15 20:19:38 1996 +++ lnxmode.c Thu Aug 15 20:21:48 1996 @@ -199,7 +199,7 @@ return; - for ( i = start; i <= end; i++) + for ( i = start; i < end; i++) { if (Dirty[i].flag == TRUE) { @@ -234,7 +234,7 @@ int i; if (Accel == TRUE) return; - for (i = 0; i <= _GrScreenY; i++) + for (i = 0; i < _GrScreenY; i++) { Dirty[i].flag =TRUE; Dirty[i].starting = 0; @@ -425,7 +425,7 @@ info = info_tmp; } } - memset(&GM[modes+1], 0, sizeof(GR_DRIVER_MODE_ENTRY)); + memset(&GM[modes], 0, sizeof(GR_DRIVER_MODE_ENTRY)); /* Third sort table */ for (i=modes-1; i>0; --i) -- Ed Doolittle "Being on time is like being on fire."