Skip to content

Fix `attempt to subtract with overflow` error in `get_glyph_kern_advance`

Jeremy Soller requested to merge mitchmindtree:overflow_fix into master

Created by: mitchmindtree

This fixes dylanede/rusttype#30 and PistonDevelopers/conrod#874.

Here's the equivalent line in the original C header. I wasn't 100% sure of the behaviour here, the operation basically seems to be this:

int a = (unsigned short)b - (int)c

After reading this SO post, it seems like b is converted to the result type int before the subtraction operation takes place? This even seems to be the case when doing int = (unsigned int) - (unsigned int);.

Anyways, I believe this PR changes the behaviour to more accurately represent the original C code behaviour and does seem to fix the bug when testing the aforementioned downstream issues.

Merge request reports