Module Name: src
Committed By: rin
Date: Sat Jun 20 07:50:16 UTC 2020
Modified Files:
src/tests/lib/libcurses/slave: curses_commands.c
src/tests/lib/libcurses/tests: mvscanw
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/lib/libcurses/slave/curses_commands.c
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libcurses/tests/mvscanw
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/lib/libcurses/slave/curses_commands.c
diff -u src/tests/lib/libcurses/slave/curses_commands.c:1.9 src/tests/lib/libcurses/slave/curses_commands.c:1.10
--- src/tests/lib/libcurses/slave/curses_commands.c:1.9 Sun May 26 07:47:37 2019
+++ src/tests/lib/libcurses/slave/curses_commands.c Sat Jun 20 07:50:16 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: curses_commands.c,v 1.9 2019/05/26 07:47:37 blymn Exp $ */
+/* $NetBSD: curses_commands.c,v 1.10 2020/06/20 07:50:16 rin Exp $ */
/*-
* Copyright 2009 Brett Lymn <[email protected]>
@@ -3061,7 +3061,7 @@ cmd_mvprintw(int nargs, char **args)
void
cmd_mvscanw(int nargs, char **args)
{
- int y, x;
+ int y, x, val;
char string[256];
if (check_arg_count(nargs, 3) == 1)
@@ -3081,7 +3081,13 @@ cmd_mvscanw(int nargs, char **args)
/* XXX - call2 */
report_count(2);
- report_return(mvscanw(y, x, args[2], &string));
+ if (strchr(args[2], 's') != NULL)
+ report_return(mvscanw(y, x, args[2], &string));
+ else {
+ /* XXX assume 32bit integer */
+ report_return(mvscanw(y, x, args[2], &val));
+ snprintf(string, sizeof(string), args[2], val);
+ }
report_status(string);
}
Index: src/tests/lib/libcurses/tests/mvscanw
diff -u src/tests/lib/libcurses/tests/mvscanw:1.3 src/tests/lib/libcurses/tests/mvscanw:1.4
--- src/tests/lib/libcurses/tests/mvscanw:1.3 Fri Feb 7 19:56:51 2020
+++ src/tests/lib/libcurses/tests/mvscanw Sat Jun 20 07:50:16 2020
@@ -1,11 +1,12 @@
+# XXX For this test, only one string or 32bit 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 "2" mvscanw 3 5 "%d"
+call2 ERR "50" mvscanw 3 5 "%d"