Menu

#18 realloc() return failure handling of v2.0.27 in SDL_gfxPrimitives.c

v1.0 (example)
open
nobody
None
5
2024-04-06
2024-04-06
Ozkan Sezer
No

I am a bit confused about the realloc() return failure handling of
v2.0.27 in SDL_gfxPrimitives.c:

In filledPolygonColorMT() around lines 5262-5269 after temp realloc
success, there is the following code:

            if (!gfxPrimitivesPolyIntsNew) {
                if (!gfxPrimitivesPolyInts) {
                    free(gfxPrimitivesPolyInts);
                    gfxPrimitivesPolyInts = NULL;
                }
                gfxPrimitivesPolyAllocated = 0;
            }

(1) The extra tmp pointer seems not necessary: gfxPrimitivesPolyIntsNew
itself is a temp pointer itself for that purpose, yes?

(2) if (!gfxPrimitivesPolyIntsNew) can not ever be true, because you
already check tmp being not NULL.

(3) if tmp==NULL, the new code skips if (!gfxPrimitivesPolyIntsNew)
block altogether. Considering how gfxPrimitivesPolyInts is assigned
above around lines 5239-5247, I don't know freeing gfxPrimitivesPolyInts
is the right thing to do now. Also: the if (!gfxPrimitivesPolyInts)
condition in there seems to be inverted and it actually should be
if (!gfxPrimitivesPolyInts) ???

Can we clear these up please?

Discussion


Log in to post a comment.

MongoDB Logo MongoDB