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

Minor fixes to pacify Coverity code scan #377

Closed
wants to merge 3 commits into from

Conversation

simonis
Copy link
Contributor

@simonis simonis commented Dec 14, 2016

Hi Behdad,

we regularly run Coverity code scans on the OpenJDK sources and recently discovered two issues with HarfBuzz. While the discovered issues are not real errors, we think that fixing them my be nevertheless worthwile in order to increase the readability of the source code.

We just wanted to ask, if you are willing to accept these changes in the upstream HarfBuzz repository because only then it would make sense to also fix them in the OpenJDK copy of HarfBuzz.

The first issue found by Coverity is the last of the following four lines from src/hb-ot-font.cc:

if (!subtable) subtable = cmap->find_subtable (0, 2);
if (!subtable) subtable = cmap->find_subtable (0, 1);
if (!subtable) subtable = cmap->find_subtable (0, 0);
if (!subtable)(subtable = cmap->find_subtable (3, 0)) && (symbol = true);

From the whole context it really took me some time to understand that 'symbol' should only be set to true if 'subtable' is set from 'cmap->find_subtable (3, 0)'. Coverity reports an "assignment instead of compare" which is a false positive, but we think the could would be much more readable if changed to look as follows:

if (!subtable)
{
  subtable = cmap->find_subtable (3, 0);
  if (subtable) symbol = true;
}

The second issue is related to the following definition in src/hb-ot-layout-gpos-table.hh:

ValueFormat  valueFormat1;           /* Defines the types of data in
                                       * ValueRecord1--for the first glyph
                                       * in the pair--may be zero (0) */
 ValueFormat  valueFormat2;           /* Defines the types of data in
                                       * ValueRecord2--for the second glyph
                                       * in the pair--may be zero (0) */

Throughout hb-ot-layout-gpos-table.hh, '&valueFormat1' is used as if it were an array of two ValueFormat objects. While extremely unlikely, a compiler could theoretically insert padding between 'valueFormat1' and 'valueFormat2' which would make the code incorrect. We would therefore propose to simply change the previous definiton into a real array:

ValueFormat  valueFormat[2];         /* [0] Defines the types of data in
                                      * ValueRecord1--for the first glyph
                                      * in the pair--may be zero (0) */
                                     /* [1] Defines the types of data in
                                      * ValueRecord2--for the second glyph
                                      * in the pair--may be zero (0) */

and change the code which uses 'valueFormat' accordingly.

Thank youand best regards,
Volker

@behdad
Copy link
Member

behdad commented Dec 18, 2016

Dear Volker. Thanks for the patch. Both are indeed very good suggestions. I'll merge.

@behdad behdad closed this in ad27388 Dec 18, 2016
@simonis
Copy link
Contributor Author

simonis commented Dec 18, 2016 via email

iongchun pushed a commit to iongchun/harfbuzz that referenced this pull request Jan 12, 2017
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 this pull request may close these issues.

None yet

4 participants