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

Refactor UndefinedStructTable parsing logic #24

Closed
jrgerber opened this issue Feb 25, 2021 · 0 comments · Fixed by #26
Closed

Refactor UndefinedStructTable parsing logic #24

jrgerber opened this issue Feb 25, 2021 · 0 comments · Fixed by #26
Assignees

Comments

@jrgerber
Copy link
Owner

The UndefinedStructTable takes a vector of raw SMBIOS table data and parses it into chunks which represent the yet to be defined SMBIOS structures. The logic that does this is contained within:
impl From<Vec<u8>> for UndefinedStructTable

The logic is buggy, difficult to read, and needs a refactor (make it at least look more like functional programming). For example the logic that searches for a double null has a bug which causes it to sometimes exceed the end of the array.

            // next_index is pointing at the start of the string area.
            // The string area is terminated with \0\0.  If no strings exist then its contents is \0\0.
            // Search for \0\0 and point at the byte immediately after it.  That point is either the start of the
            // next structure header or one byte beyond the end of "data".
            let mut a: bool;
            let mut b = true;
            loop {
                if next_index >= len {
                    break;
                }
                a = data[next_index] != 0;
                next_index = next_index + 1;
                if a || b {
                    b = data[next_index] != 0;
                    next_index = next_index + 1;
                }
                if !(a || b) {
                    break;
                }
            }

Further, the logic that guarantees there is a double null at the end of the array is in a loop and does not need to be:

            || data[len - 2] != 0 // 2nd to last byte should be zero and it is not
            || data[len - 1] != 0
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.

1 participant