From c462509adfd68e8b849b8a6713360fb4f9026578 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Thu, 10 Apr 2025 02:00:58 +0300 Subject: fixed formatting of the smallest possible integer * In other words, fixed `-9223372036854775808\` on --with-teco-integer=64 (which is the default). * The reason is that ABS(G_MININT64) == G_MININT64 since -G_MININT64 == G_MININT64. It is therefore important not to call ABS() on arbitrary teco_int_t's. --- src/expressions.c | 4 ++-- src/view.c | 1 + tests/atlocal.in | 7 +++++++ tests/testsuite.at | 9 +++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/expressions.c b/src/expressions.c index c48e7b0..f802c6e 100644 --- a/src/expressions.c +++ b/src/expressions.c @@ -399,11 +399,11 @@ teco_expressions_format(gchar *buffer, teco_int_t number, teco_qreg_t *qreg) gchar *p = buffer + TECO_EXPRESSIONS_FORMAT_LEN; - teco_int_t v = ABS(number); + teco_int_t v = number; *--p = '\0'; do { - *--p = '0' + (v % radix); + *--p = '0' + ABS(v % radix); if (*p > '9') *p += 'A' - '9' - 1; } while ((v /= radix)); diff --git a/src/view.c b/src/view.c index df09aac..71d74e2 100644 --- a/src/view.c +++ b/src/view.c @@ -612,6 +612,7 @@ teco_view_glyphs2bytes_relative(teco_view_t *ctx, gsize pos, teco_int_t n) { if (!n) return pos; + /* NOTE: Does not work for n == G_MININT64. */ if (ABS(n) > TECO_RELATIVE_LIMIT) return teco_view_glyphs2bytes(ctx, teco_view_bytes2glyphs(ctx, pos) + n); diff --git a/tests/atlocal.in b/tests/atlocal.in index 8465f96..1992c54 100644 --- a/tests/atlocal.in +++ b/tests/atlocal.in @@ -26,6 +26,13 @@ ESCAPE=`printf '\33'` # is used. SCITECOPATH="@abs_top_srcdir@/lib" +TECO_INTEGER=@TECO_INTEGER@ + +MAXINT32=2147483647 +MININT32=-2147483648 +MAXINT64=9223372036854775807 +MININT64=-9223372036854775808 + GREP="@GREP@" # Glib debug options diff --git a/tests/testsuite.at b/tests/testsuite.at index 20a76c5..d8d88e1 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -117,6 +117,15 @@ AT_CHECK([$SCITECO -e "[[\$ @FG'..' ]]\$ :Q\$-1Q\$-^^r\"=(0/0)'"], 0, ignore, ig AT_CHECK([$SCITECO -e "[[: @I/XXX/ ]]: .\"N(0/0)'"], 0, ignore, ignore) AT_CLEANUP +AT_SETUP([Formatting numbers]) +# MAXINT32/MININT32: should always work. +AT_CHECK([$SCITECO -e "$MAXINT32\\ J::@S/$MAXINT32/\"F(0/0)'"], 0, ignore, ignore) +AT_CHECK([$SCITECO -e "$MININT32\\ J::@S/$MININT32/\"F(0/0)'"], 0, ignore, ignore) +AT_SKIP_IF([test $TECO_INTEGER -lt 64]) +AT_CHECK([$SCITECO -e "$MAXINT64\\ J::@S/$MAXINT64/\"F(0/0)'"], 0, ignore, ignore) +AT_CHECK([$SCITECO -e "$MININT64\\ J::@S/$MININT64/\"F(0/0)'"], 0, ignore, ignore) +AT_CLEANUP + AT_SETUP([Convert between line and glyph positions]) AT_CHECK([$SCITECO -e "@I/1^J2^J3/J 2^QC :^Q-3\"N(0/0)'"], 0, ignore, ignore) AT_CLEANUP -- cgit v1.2.3