Sat Jun 20 07:50:16 2020 UTC ()
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.


(rin)
diff -r1.9 -r1.10 src/tests/lib/libcurses/slave/curses_commands.c
diff -r1.3 -r1.4 src/tests/lib/libcurses/tests/mvscanw

cvs diff -r1.9 -r1.10 src/tests/lib/libcurses/slave/curses_commands.c (expand / switch to unified diff)

--- src/tests/lib/libcurses/slave/curses_commands.c 2019/05/26 07:47:37 1.9
+++ src/tests/lib/libcurses/slave/curses_commands.c 2020/06/20 07:50:16 1.10
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: curses_commands.c,v 1.9 2019/05/26 07:47:37 blymn Exp $ */ 1/* $NetBSD: curses_commands.c,v 1.10 2020/06/20 07:50:16 rin Exp $ */
2 2
3/*- 3/*-
4 * Copyright 2009 Brett Lymn <blymn@NetBSD.org> 4 * Copyright 2009 Brett Lymn <blymn@NetBSD.org>
5 * 5 *
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * This code has been donated to The NetBSD Foundation by the Author. 8 * This code has been donated to The NetBSD Foundation by the Author.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -3051,47 +3051,53 @@ cmd_mvprintw(int nargs, char **args) @@ -3051,47 +3051,53 @@ cmd_mvprintw(int nargs, char **args)
3051 report_count(1); 3051 report_count(1);
3052 report_error("BAD ARGUMENT"); 3052 report_error("BAD ARGUMENT");
3053 return; 3053 return;
3054 } 3054 }
3055 3055
3056 report_count(1); 3056 report_count(1);
3057 report_return(mvprintw(y, x, args[2], args[3])); 3057 report_return(mvprintw(y, x, args[2], args[3]));
3058} 3058}
3059 3059
3060 3060
3061void 3061void
3062cmd_mvscanw(int nargs, char **args) 3062cmd_mvscanw(int nargs, char **args)
3063{ 3063{
3064 int y, x; 3064 int y, x, val;
3065 char string[256]; 3065 char string[256];
3066 3066
3067 if (check_arg_count(nargs, 3) == 1) 3067 if (check_arg_count(nargs, 3) == 1)
3068 return; 3068 return;
3069 3069
3070 if (sscanf(args[0], "%d", &y) == 0) { 3070 if (sscanf(args[0], "%d", &y) == 0) {
3071 report_count(1); 3071 report_count(1);
3072 report_error("BAD ARGUMENT"); 3072 report_error("BAD ARGUMENT");
3073 return; 3073 return;
3074 } 3074 }
3075 3075
3076 if (sscanf(args[1], "%d", &x) == 0) { 3076 if (sscanf(args[1], "%d", &x) == 0) {
3077 report_count(1); 3077 report_count(1);
3078 report_error("BAD ARGUMENT"); 3078 report_error("BAD ARGUMENT");
3079 return; 3079 return;
3080 } 3080 }
3081 3081
3082 /* XXX - call2 */ 3082 /* XXX - call2 */
3083 report_count(2); 3083 report_count(2);
3084 report_return(mvscanw(y, x, args[2], &string)); 3084 if (strchr(args[2], 's') != NULL)
 3085 report_return(mvscanw(y, x, args[2], &string));
 3086 else {
 3087 /* XXX assume 32bit integer */
 3088 report_return(mvscanw(y, x, args[2], &val));
 3089 snprintf(string, sizeof(string), args[2], val);
 3090 }
3085 report_status(string); 3091 report_status(string);
3086} 3092}
3087 3093
3088 3094
3089void 3095void
3090cmd_mvvline(int nargs, char **args) 3096cmd_mvvline(int nargs, char **args)
3091{ 3097{
3092 int y, x, n; 3098 int y, x, n;
3093 chtype *ch; 3099 chtype *ch;
3094 3100
3095 if (check_arg_count(nargs, 4) == 1) 3101 if (check_arg_count(nargs, 4) == 1)
3096 return; 3102 return;
3097 3103

cvs diff -r1.3 -r1.4 src/tests/lib/libcurses/tests/mvscanw (expand / switch to unified diff)

--- src/tests/lib/libcurses/tests/mvscanw 2020/02/07 19:56:51 1.3
+++ src/tests/lib/libcurses/tests/mvscanw 2020/06/20 07:50:16 1.4
@@ -1,11 +1,12 @@ @@ -1,11 +1,12 @@
 1# XXX For this test, only one string or 32bit integer are supported as
 2# conversion specifiers at the moment.
1include start 3include start
2input "testing 1 2 3\n" 4input "testing 1 2 3\n"
3call2 OK "testing" mvscanw 3 5 "%s" 5call2 OK "testing" mvscanw 3 5 "%s"
4input "testing 1 2 3\n" 6input "testing 1 2 3\n"
5call2 OK "test" mvscanw 3 5 "%4s" 7call2 OK "test" mvscanw 3 5 "%4s"
6# 50 will translate into number 2 in ascii 
7input "50 12\n" 8input "50 12\n"
8call2 OK "2" mvscanw 3 5 "%d" 9call2 OK "50" mvscanw 3 5 "%d"
9input "aa bb 50 12\n" 10input "aa bb 50 12\n"
10# expect ERR because input has alpha and scanw wants integer 11# expect ERR because input has alpha and scanw wants integer
11call2 ERR "2" mvscanw 3 5 "%d" 12call2 ERR "50" mvscanw 3 5 "%d"