PDA

View Full Version : Strange line in NSBezierPath-OAExtensions.m


norrkross
2008-09-02, 04:17 AM
I wonder if this is a bug:

NSBezierPath-OAExtensions.m:576 in -allIntersectionsWithPath:

intersections = realloc(intersections, sizeof(*intersections) * (listSize = intersectionCount));

Is the "=" intentional? I don't even understand what this method does and the only reason I'm looking at it is because LLVM/Clang complains so it's perhaps nothing...

Cheers,
Martin

Andrew
2008-09-02, 11:33 AM
I'm not familiar with that code, and I would agree that that causes one to do a bit of a double-take when looking at the code, but offhand it looks intentional. If you look around to see where listSize gets changed, it's in three places, and all three have the same pattern of assignment directly inline with calculation for memory allocation.

Wim Lewis
2008-10-02, 01:21 PM
I probably wrote that. Yes, it's intentional; it's an idiom for keeping listSize in sync with the allocated size of the list. Old C coding habits die hard.

Interesting that clang complains about it. gcc has some heuristics for when to complain about legal-but-possibly-erroneous code like that; clang's heuristics are presumably different.