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

there are three suspicious bugs #175

Open
3 tasks
umjammer opened this issue Nov 20, 2019 · 2 comments · May be fixed by #176
Open
3 tasks

there are three suspicious bugs #175

umjammer opened this issue Nov 20, 2019 · 2 comments · May be fixed by #176

Comments

@umjammer
Copy link

hi, i'm porting DiscUtils to Java.
when i used SpotBugs, it pointed out 3 suspicious bugs.

1. RpC: Repeated conditional tests (RpC_REPEATED_CONDITIONAL_TEST)

The code contains a conditional test is performed twice, one right after the other (e.g., x == 0 || x == 0). Perhaps the second occurrence is intended to be something else (e.g., x == 0 || y == 0).

else if (!_runs[i].IsSparse && !_runs[i].IsSparse &&

  1. the index of _runs at the second condition might be i + 1, right ???

2. This method DiscUtils.Core.LogicalDiskManager.DynamicDisk.GetPrivateHeader(VirtualDisk) continues a loop after finding an equality condition

This method continues with a loop, and does not break out of it, after finding and setting a variable in an if condition based on equality. Since continuing on in the loop would seem to be unlikely to find the item again, breaking at this point would seem to be the proper action.

foreach (PartitionInfo part in pt.Partitions)
{
if (part.GuidType == GuidPartitionTypes.WindowsLdmMetadata)
{
headerPos = part.LastSector * Sizes.Sector;
}
}

  1. is this code intended?

3. This method DiscUtils.Core.Partitions.BiosExtendedPartitionTable.GetMetadataDiskExtents() continues a loop after finding an equality condition

Example:

int age = 0;
for (Person p : people) {
    if (p.getName().equals("Dave")) {
        age = p.getAge();
    }
}

It is likely you wanted a break after getting the age for "Dave".

for (int offset = 0x1BE; offset <= 0x1EE; offset += 0x10)
{
BiosPartitionRecord thisPart = new BiosPartitionRecord(sector, offset, partPos, -1);
if (thisPart.StartCylinder != 0 || thisPart.StartHead != 0 || thisPart.StartSector != 0)
{
if (thisPart.PartitionType == 0x05 || thisPart.PartitionType == 0x0F)
{
nextPartPos = _firstSector + thisPart.LBAStart;
}
}
}

  1. is this code intended?

thanks,

@LordMike
Copy link
Member

Technically the latter two would find the "last" entry .. although your finding is probably correct. I'll see about getting this in.

Thanks for spotting these ;)

@LordMike
Copy link
Member

And yes. The first one should be the next index being tested. It's collapsing data runs.

LordMike added a commit that referenced this issue Nov 21, 2019
@LordMike LordMike linked a pull request Nov 21, 2019 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants