xkb: correcting mathematical nonsense in XkbGeomFPText

Fixes formatting of negative numbers, so they don't show minus sign
after the decimal point.

(cherry picked from xorg/lib/libxkbfile@d2ec504fec2550f4fd046e801b34317ef4a4bab9)

Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
(cherry picked from commit 7a23010232)

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1895>
This commit is contained in:
Martin Burggraf 2015-08-13 21:16:40 +02:00 committed by Olivier Fourdan
parent ed54cc2a03
commit bd43d90cd1

View file

@ -623,7 +623,7 @@ XkbGeomFPText(int val, unsigned format)
{
int whole, frac;
char *buf;
const int bufsize = 12;
const int bufsize = 13;
buf = tbGetBuffer(bufsize);
if (format == XkbCFile) {
@ -631,9 +631,17 @@ XkbGeomFPText(int val, unsigned format)
}
else {
whole = val / XkbGeomPtsPerMM;
frac = val % XkbGeomPtsPerMM;
if (frac != 0)
snprintf(buf, bufsize, "%d.%d", whole, frac);
frac = abs(val % XkbGeomPtsPerMM);
if (frac != 0) {
if (val < 0)
{
int wholeabs;
wholeabs = abs(whole);
snprintf(buf, bufsize, "-%d.%d", wholeabs, frac);
}
else
snprintf(buf, bufsize, "%d.%d", whole, frac);
}
else
snprintf(buf, bufsize, "%d", whole);
}