MATRIX: Check format specifier on PRINT command.
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 18 Mar 2023 21:41:40 +0000 (14:41 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 18 Mar 2023 21:41:40 +0000 (14:41 -0700)
Thanks to Youngseok Choi for reporting the bug.

src/language/commands/matrix.c
tests/language/commands/matrix.at

index 9076476ed7a10379bedf3b5785f3b1ef1fd6501e..332678160c4211154d7214fcc0d914011bfdecbe 100644 (file)
@@ -5389,6 +5389,15 @@ matrix_print_parse (struct matrix_state *s)
           lex_match (s->lexer, T_EQUALS);
           if (!parse_format_specifier (s->lexer, &cmd->print.format))
             goto error;
+
+          char *error = fmt_check_output__ (cmd->print.format);
+          if (error)
+            {
+              lex_next_error (s->lexer, -1, -1, "%s", error);
+              free (error);
+              goto error;
+            }
+
           cmd->print.use_default_format = false;
         }
       else if (lex_match_id (s->lexer, "TITLE"))
index 9ebd23671f8939a1d826c9cc2817845a7780175d..5cc52b279203f8e7a52e644f8426d815f1e25859 100644 (file)
@@ -2856,6 +2856,58 @@ a. × 10**12
 ])
 AT_CLEANUP
 
+AT_SETUP([MATRIX - PRINT - negative])
+AT_DATA([matrix.sps], [dnl
+MATRIX.
+PRINT !.
+PRINT/FORMAT=!.
+PRINT/FORMAT=P52.
+PRINT/TITLE=!.
+PRINT/SPACE=0.
+PRINT/RNAMES=!.
+PRINT/CNAMES=!.
+PRINT/!.
+END MATRIX.
+])
+
+AT_CHECK([pspp matrix.sps], [1], [dnl
+matrix.sps:2.7: error: PRINT: Syntax error expecting matrix expression.
+    2 | PRINT !.
+      |       ^
+
+matrix.sps:3.14: error: PRINT: Syntax error expecting valid format specifier.
+    3 | PRINT/FORMAT=!.
+      |              ^
+
+matrix.sps:4.14-4.16: error: PRINT: Output format P52.0 specifies width 52, but
+P requires a width between 1 and 16.
+    4 | PRINT/FORMAT=P52.
+      |              ^~~
+
+matrix.sps:5.13: error: PRINT: Syntax error expecting string.
+    5 | PRINT/TITLE=!.
+      |             ^
+
+matrix.sps:6.13: error: PRINT: Syntax error expecting positive integer for
+SPACE.
+    6 | PRINT/SPACE=0.
+      |             ^
+
+matrix.sps:7.14: error: PRINT: Syntax error expecting matrix expression.
+    7 | PRINT/RNAMES=!.
+      |              ^
+
+matrix.sps:8.14: error: PRINT: Syntax error expecting matrix expression.
+    8 | PRINT/CNAMES=!.
+      |              ^
+
+matrix.sps:9.7: error: PRINT: Syntax error expecting FORMAT, TITLE, SPACE,
+RLABELS, CLABELS, RNAMES, or CNAMES.
+    9 | PRINT/!.
+      |       ^
+])
+AT_CLEANUP
+
 AT_SETUP([MATRIX - DO IF])
 AT_DATA([matrix.sps], [dnl
 MATRIX.