ralphmelton: (Default)
[personal profile] ralphmelton
Mike had a problem with code that I'd written back in 1998. It seemed that under AIX, if he compiled with optimization for the caller of document clustering, the regression test broke. Optimizing the document clustering code itself didn't matter at all.

I thought about this for a bit and suggested some debugging ideas, and finally thought, "Oh, maybe this could be the problem." I checked:
that hypothesis was the problem.
It was my fault; it was in the document clustering code.
The bug had gone unnoticed for three years (and the code had gone through code review).
It was fixed by removing a single character.

I am simultaneously proud for spotting this and embarrassed for having made the error in the first place.

I'll let the C++-heads think about this before reading

The answer:
The function being called involved a reference parameter.
The reference parameter was being passed a temporary.
A data structure returned by the function was keeping that reference past the lifetime of the function.
The optimized code was being more proactive about reusing the storage used for that temporary, and that was wreaking havoc on the data structure that had the reference to the stale temporary.

The solution was to remove the '&' to turn the reference into a copy.

Profile

ralphmelton: (Default)
ralphmelton

April 2018

S M T W T F S
1234567
891011121314
151617181920 21
22232425262728
2930     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 14th, 2025 09:06 pm
Powered by Dreamwidth Studios