Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
c/shared/source/t1write/t1write.c: fix u8/u16 type mismatch on derefe…
Browse files Browse the repository at this point in the history
…rence (gcc-14)

Upcoming `gcc-14` enabled a few warnings into errors, like
`-Wincompatible-pointer-types`. This caused `afdko` build to fail as:

    /build/afdko/c/shared/source/t1write/t1write.c: In function ‘saveCstr’:
    /build/afdko/c/shared/source/t1write/t1write.c:348:28: error: passing argument 3 of ‘writeTmp’ from incompatible pointer type [-Wincompatible-pointer-types]
      348 |         if (writeTmp(h, 1, &info->iFD))
          |                            ^~~~~~~~~~
          |                            |
          |                            uint16_t * {aka short unsigned int *}

The code attempts to use only one byte of 16-bit value. The code very
likely is broken on a big-endian system.

The change explicitly truncates 16-bit value down to 8 bit value to
retain existing behaviour on both BE and LE systems.
trofi committed Dec 6, 2023
1 parent 057e354 commit 68b0a89
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion c/shared/source/t1write/t1write.c
Original file line number Diff line number Diff line change
@@ -345,7 +345,8 @@ static int saveCstr(t1wCtx h, abfGlyphInfo *info,
if (info != NULL && info->flags & ABF_GLYPH_CID &&
!(h->arg.flags & T1W_TYPE_HOST)) {
/* CID-keyed incremental download; write fd index */
if (writeTmp(h, 1, &info->iFD))
unsigned char c = info->iFD;
if (writeTmp(h, 1, &c))
return 1;
cstr->length++;
}

0 comments on commit 68b0a89

Please sign in to comment.