Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libcurses Reapply fix for big-endian environments,...



details:   https://anonhg.NetBSD.org/src/rev/6e6240261112
branches:  trunk
changeset: 982194:6e6240261112
user:      rin <rin%NetBSD.org@localhost>
date:      Sun Apr 04 09:49:13 2021 +0000

description:
Reapply fix for big-endian environments, which was lost when GSoC results
were merged...

http://www.nerv.org/netbsd/?q=id:20200620T075016Z.3584036ccf31f69ee76ea4a02e9be30ff081df21

> Fix false positive for mvscanw tests on big endian machines.
>
> When conversion specifier is not a derivative form of "%s", retrieve
> input as 32bit integer, and then convert to string literal. Then we
> can avoid interpretation from ASCII code to integer, which is
> apparently byte-order depended.

diffstat:

 tests/lib/libcurses/slave/curses_commands.c |  15 ++++++++++++---
 tests/lib/libcurses/tests/mvscanw           |   6 ++++--
 2 files changed, 16 insertions(+), 5 deletions(-)

diffs (50 lines):

diff -r 81a4f020569e -r 6e6240261112 tests/lib/libcurses/slave/curses_commands.c
--- a/tests/lib/libcurses/slave/curses_commands.c       Sun Apr 04 09:42:08 2021 +0000
+++ b/tests/lib/libcurses/slave/curses_commands.c       Sun Apr 04 09:49:13 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: curses_commands.c,v 1.24 2021/04/04 09:42:08 rin Exp $ */
+/*     $NetBSD: curses_commands.c,v 1.25 2021/04/04 09:49:13 rin Exp $ */
 
 /*-
  * Copyright 2009 Brett Lymn <blymn%NetBSD.org@localhost>
@@ -1986,10 +1986,19 @@
        ARGC(3);
        ARG_INT(0, y);
        ARG_INT(1, x);
-       ARG_STRING(2, fmt);     /* Must have a single "%s" in this test. */
+       ARG_STRING(2, fmt);
 
        report_count(2);
-       report_return(ret = mvscanw(y, x, fmt, string));
+       if (strchr(fmt, 's') != NULL) {
+               report_return(ret = mvscanw(y, x, fmt, string));
+       } else {
+               int val; /* XXX assume 32-bit integer */
+               report_return(ret = mvscanw(y, x, fmt, &val));
+               if (ret == ERR)
+                       goto out;
+               snprintf(string, sizeof(string), fmt, val);
+       }
+out:
        /*
         * When mvscanw(3) fails, string is not modified.
         * Let's ignore the 2nd result for this case.
diff -r 81a4f020569e -r 6e6240261112 tests/lib/libcurses/tests/mvscanw
--- a/tests/lib/libcurses/tests/mvscanw Sun Apr 04 09:42:08 2021 +0000
+++ b/tests/lib/libcurses/tests/mvscanw Sun Apr 04 09:49:13 2021 +0000
@@ -1,11 +1,13 @@
+# XXX
+# For this test, only one string or 32-bit integer are supported as
+# conversion specifiers at the moment.
 include start
 input "testing 1 2 3\n"
 call2 OK "testing" mvscanw 3 5 "%s"
 input "testing 1 2 3\n"
 call2 OK "test" mvscanw 3 5 "%4s"
-# 50 will translate into number 2 in ascii
 input "50 12\n"
-call2 OK "2" mvscanw 3 5 "%d"
+call2 OK "50" mvscanw 3 5 "%d"
 input "aa bb 50 12\n"
 # expect ERR because input has alpha and scanw wants integer
 call2 ERR "ERR" mvscanw 3 5 "%d"



Home | Main Index | Thread Index | Old Index