summaryrefslogtreecommitdiff
path: root/contrib/seg/seg.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/seg/seg.c')
-rw-r--r--contrib/seg/seg.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/contrib/seg/seg.c b/contrib/seg/seg.c
index e964560053d..a7effc1b190 100644
--- a/contrib/seg/seg.c
+++ b/contrib/seg/seg.c
@@ -928,9 +928,13 @@ restore(char *result, float val, int n)
/*
* Put a cap on the number of significant digits to avoid garbage in the
- * output and ensure we don't overrun the result buffer.
+ * output and ensure we don't overrun the result buffer. (n should not be
+ * negative, but check to protect ourselves against corrupted data.)
*/
- n = Min(n, FLT_DIG);
+ if (n <= 0)
+ n = FLT_DIG;
+ else
+ n = Min(n, FLT_DIG);
/* remember the sign */
sign = (val < 0 ? 1 : 0);