From 7a23010232312c24cde6070a50dbb5433ce52a59 Mon Sep 17 00:00:00 2001 From: Martin Burggraf Date: Thu, 13 Aug 2015 21:16:40 +0200 Subject: [PATCH] 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 Signed-off-by: Alan Coopersmith Part-of: --- xkb/xkbtext.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/xkb/xkbtext.c b/xkb/xkbtext.c index 55939aba7..188c9ffb1 100644 --- a/xkb/xkbtext.c +++ b/xkb/xkbtext.c @@ -622,7 +622,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) { @@ -630,9 +630,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); }