Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CFrdutils.c:917 local variable tmppt maybe read before initialization #338

Open
dlmiles opened this issue Oct 7, 2024 · 1 comment
Open

Comments

@dlmiles
Copy link
Contributor

dlmiles commented Oct 7, 2024

https://github.com/RTimothyEdwards/magic/blob/master/cif/CIFrdutils.c#L917 (assignment point)

This block is always taken as does_cross==FALSE as it is assigned on function entry has not yet been changed (making the 2nd part of the if ((!does_cross) || (newdist < tdist)) redundant. So the block is always taken. Maybe there is a logic error here to consider it should be !does_cross&&newdist<tdist but there is no 'break' out of the for loop to indicate that intention.

tmppt should be assigned a safe initialized value so the assignment is not random.
or maybe all assignments to populate tmppt should have a boolean flag to indicate the data is valid and populated so can be used to set does_cross=TRUE for the return value.

SonarCloud ref https://sonarcloud.io/project/issues?open=AZJB17bBNGfDNup0Rkb5&id=dlmiles_magic

This has a 23 stage static analysis what-if scenario of the events leading upto invalid data being assigned and returned.

@RTimothyEdwards
Copy link
Owner

I'm not getting this point. . . if ((!does_cross) || (newdist < tdist) is inside a for() loop. The intention is that this block is always called on the first cycle of the loop, where it sets does_cross to TRUE and initializes tdist. Throughout the rest of the loop, the "if" block is only executed if newdist < tdist. It does look like it could be simplified to just if (newdist < tdist), though.

The intention is that tmppt must be set to something before it is used. I do not know offhand what it would mean for the code to get to the abovementioned "if" block if tmppt were still uninitialized. It's worth setting a tmppt_valid if seg_intersect() returns TRUE (otherwise tmppt is meaningless) and in the two cases where tmppt is set, and then if the code attempts to set respt to tmppt then an error message can be generated, and I can go look into what happened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants