[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[leafnode-list] Riddle



The following piece of code from texpire.c (around line 448) segfaults
in the sprintf line:

    /* check whether file entries are legal */
    /* save threads if an article in the thread is not killed */
    for ( current = (acount-1); current >= 0; current-- ) {
        sprintf( artfile, "%lu", articles[current].artno );
	...
    }

Segfault looks like this (from gdb):

Program received signal SIGSEGV, Segmentation fault.
0x8049f4e in dogroup (g=0x402f82d0) at ./texpire.c:448
448             sprintf( artfile, "%lu", articles[current].artno );
(gdb) print acount
$1 = 8986
(gdb) print current
$2 = 8986

This obviously cannot work since "articles" should be an array from
0 to 8985; therefore access to articles[8986] will cause a crash.

How can "current" be equal to "acount"? Neither variable is modified
in the for() loop, as far as I can see. Maybe it's because the program
has been compiled with -O2?

(Of course I can think of ways of working around this, but I want
 to understand why the code is failing...)

--Cornelius.

-- 
/* Cornelius Krasel, U Wuerzburg, Dept. of Pharmacology, Versbacher Str. 9 */
/* D-97078 Wuerzburg, Germany   email: krasel@xxxxxxxxxxxxxxxxxxxxxxxxxxxx */
/* "Science is the game we play with God to find out what His rules are."  */

-- 
leafnode-list@xxxxxxxxxxxxxxxxxxxxxxxxxxxx -- mailing list for leafnode
To unsubscribe, send mail with "unsubscribe" in the subject to the list