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

Fix an IndexOutOfRangeException in DragCube.Load() #232

Merged
merged 1 commit into from
Oct 7, 2024

Conversation

Nazfib
Copy link
Contributor

@Nazfib Nazfib commented Jun 18, 2024

The name field in a DRAG_CUBE config node is supposed to be optional. However, when the name is not included in the list of values, an IndexOutOfRangeException is thrown.

Even when not loaded from a config file, when the name field on a DragCube object is the empty string (for example, when it is default-constructed in code) it is not included in the string returned by DragCube.SaveToString(); this causes a problem when the FlightIntegrator.Setup() method uses this string to clone drag cubes.

The first instructions in DragCube.Load(string[] data) are:

  • Check if it has the correct length (24 or 25), logging an error and returning if this is not the case
  • Check if the length is 12; if it is not, take the first field as the name and skip it.

That last check should have been against a length of 24 instead; this patch replaces the first occurrence of ldc.i4.s 12 in the code by ldc.i4.s 24.

I've checked KSP version 1.0.5 (the oldest version available via Steam), and the bug was already present in that version; the code seems to be unchanged between then and version 1.12.5.

The name field in a DRAG_CUBE config node is supposed to be optional.
However, when the name is not included in the list of values, an
IndexOutOfRangeException is thrown.

Even when not loaded from a config file, when the name field on a
DragCube object is the empty string (for example, when it is
default-constructed in code) it is not included in the string returned
by DragCube.SaveToString(); this causes a problem when the
FlightIntegrator.Setup() method uses this string to create a clone of a
drag cube.

The first instructions in DragCube.Load(string[] data) are:
 - Check if it has the correct length (24 or 25), logging an error and
   returning if this is not the case
 - Check if the length is 12; if it is not, take the first field as the
   name and skip it.

That last check should have been against a length of 24 instead; this
patch replaces the first occurrence of ldc.i4.s 12 in the code by
ldc.i4.s 24.

I've checked KSP version 1.0.5 (the oldest version available via Steam),
and the bug was already present in that version; the code seems to be
unchanged between then and version 1.12.5.
@JonnyOThan
Copy link
Contributor

Thanks for the patch!

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

Successfully merging this pull request may close these issues.

2 participants