Module Name:    src
Committed By:   rin
Date:           Sun Apr  4 09:49:13 UTC 2021

Modified Files:
        src/tests/lib/libcurses/slave: curses_commands.c
        src/tests/lib/libcurses/tests: mvscanw

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/tests/lib/libcurses/slave/curses_commands.c
cvs rdiff -u -r1.6 -r1.7 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.24 src/tests/lib/libcurses/slave/curses_commands.c:1.25
--- src/tests/lib/libcurses/slave/curses_commands.c:1.24	Sun Apr  4 09:42:08 2021
+++ src/tests/lib/libcurses/slave/curses_commands.c	Sun Apr  4 09:49:13 2021
@@ -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 <bl...@netbsd.org>
@@ -1986,10 +1986,19 @@ cmd_mvscanw(int nargs, char **args)
 	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.

Index: src/tests/lib/libcurses/tests/mvscanw
diff -u src/tests/lib/libcurses/tests/mvscanw:1.6 src/tests/lib/libcurses/tests/mvscanw:1.7
--- src/tests/lib/libcurses/tests/mvscanw:1.6	Sun Apr  4 09:42:08 2021
+++ src/tests/lib/libcurses/tests/mvscanw	Sun Apr  4 09:49:13 2021
@@ -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"

Reply via email to