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

Typo and Possible Change to "Calculating Checksums" Section #1189

Open
Magicalbat opened this issue Jan 5, 2025 · 0 comments
Open

Typo and Possible Change to "Calculating Checksums" Section #1189

Magicalbat opened this issue Jan 5, 2025 · 0 comments

Comments

@Magicalbat
Copy link

Description

In the function provided to calculate the checksum of a table, there is a typo. The variable Endptr is defined, but the variable EndPtr is used in the next line.

Also, this function was confusing to me when I first read it. This function operates on a uint32_t array, but fails to mention that the uint32_t units have to be interpreted as big endian. I initially thought that I could interpret a uint8_t pointer array as a uint32_t pointer and run this function, but that obviously does not work because my computer is little endian. I think that it would be helpful to add a note either to the section or to the code that each uint32_t unit is still big endian. The function could also be rewritten to accept a uint8_t pointer:

uint32_t
CalcTableChecksum(uint8_t *Table, uint32_t Length)
{
    uint32_t Sum = 0L;

    for (uint32_t i = 0; i < ((Length + 3) & ~3); i += 4) {
        Sum += ((uint32_t)Table[i] << 24) |
            ((uint32_t)Table[i + 1] << 16) |
            ((uint32_t)Table[i + 2] << 8) |
            ((uint32_t)Table[i + 3]);
    }

    return Sum;
}

As with the original function, this one assumes that Table is padded with zeros, but this is always true if the Table pointer is derived directly from the file data.

Page URL

https://learn.microsoft.com/en-us/typography/opentype/spec/otff#calculating-checksums

Content source URL

https://github.com/MicrosoftDocs/typography/blob/live/typographydocs/opentype/spec/otff.md

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

No branches or pull requests

1 participant