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

Re: [leafnode-list] Riddle

krasel@xxxxxxxxxxxxxxxxxxxxxxxxxxxx (Cornelius Krasel) writes:

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

You can't be sure if that's what the CPU is really doing without
intermixed assembler source when using any optimization.

> 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?

No, it's because you don't compile with -Wall -W and therefore don't see
the bug that someone else pointed out. Since the loop condition will be
optimized to nothing, and current might be a local register variable for
the loop, you may be unable to track that with -O2. Try make clean ;
make CFLAGS="-O1 -W -Wall" (note that this will not show any syslog
problems on Linux since the syslog include file sucks, compile on
FreeBSD or update to 2.0b5_ma7).

This is how my texpire.c looks in that area (should be much like yours
but faster and smaller for str_ulong -- which came late in 2.0b5_maX):

    for(current = acount; current > 0; current--) {
        articles[current-1].kill = 1;   /* by default, kill all articles */
        str_ulong(artfile, articles[current-1].artno);

that "-1" is not for fun, but because current-- goes from 0 to ULONG_MAX
rather than from 0 to -1.

If you want to transform the index coordinates, you can no longer use
unsigned. However, if you're switching to signed, you're looking for a
lot of work that will surely introduce new bugs.

Matthias Andree

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