Register
handmade.network»Forums»Bug in CTIME
RFH
AM
6 posts
Bug in CTIME
3 years, 5 months ago
I found a bug in CTIME, which only hits when you run ctime -stats on a .ctm file on which a single build is recorded. That is, if you do this:
1
2
3
4
ctime -begin tst.ctm  # tst.ctm is created here
ctime -end tst.ctm
ctime -stats tst.ctm
----> segmentation fault

After the next build is recorded, it works fine. I tracked the offender to this line of code inside the Stat() function:
1
2
3
4
5
6
7
8
9
            UpdateStatGroup(Group, Entry);
            UpdateStatGroup(&AllStats, Entry);

            AllMs += (double)Entry->MillisecondsElapsed;

            {
                int GraphIndex = (int)(((double)(ThisDayIndex-FirstDayAt)/DaySpan)*(double)GRAPH_WIDTH);
                UpdateStatGroup(TotalGraph.Buckets + GraphIndex, Entry);   // <------ problem
            }

"TotalGraph.Buckets+GraphIndex" accesses illegal memory. This was as far as I got. Of course, this is not a critical bug, since after the first couple of uses it goes away, and I imagine most people will have missed it completely.