GNU Binutils with patches for OS216
Revisión | 683f7a0d02c16dfc6e8be024ac6b41bbae7a0c36 (tree) |
---|---|
Tiempo | 2019-06-05 07:30:02 |
Autor | Pedro Alves <palves@redh...> |
Commiter | Pedro Alves |
boolean/auto-boolean commands, make "o" ambiguous
We currently accept "o" with boolean/auto-boolean commands, taking it
to mean "on". But "o" is ambiguous, between "on" and "off". I can't
imagine why assuming the user wanted to type "on" is a good idea, it
might have been a typo.
This commit makes gdb error out. We now get:
gdb/ChangeLog:
yyyy-mm-dd Pedro Alves <palves@redhat.com>
* cli/cli-setshow.c (parse_auto_binary_operation)
(parse_cli_boolean_value): Don't allow "o".
gdb/testsuite/ChangeLog:
yyyy-mm-dd Pedro Alves <palves@redhat.com>
* gdb.base/settings.exp (test-boolean, test-auto-boolean): Check
that "o" is ambiguous.
@@ -54,18 +54,21 @@ parse_auto_binary_operation (const char *arg) | ||
54 | 54 | |
55 | 55 | while (isspace (arg[length - 1]) && length > 0) |
56 | 56 | length--; |
57 | - if (strncmp (arg, "on", length) == 0 | |
57 | + | |
58 | + /* Note that "o" is ambiguous. */ | |
59 | + | |
60 | + if ((length == 2 && strncmp (arg, "on", length) == 0) | |
58 | 61 | || strncmp (arg, "1", length) == 0 |
59 | 62 | || strncmp (arg, "yes", length) == 0 |
60 | 63 | || strncmp (arg, "enable", length) == 0) |
61 | 64 | return AUTO_BOOLEAN_TRUE; |
62 | - else if (strncmp (arg, "off", length) == 0 | |
65 | + else if ((length >= 2 && strncmp (arg, "off", length) == 0) | |
63 | 66 | || strncmp (arg, "0", length) == 0 |
64 | 67 | || strncmp (arg, "no", length) == 0 |
65 | 68 | || strncmp (arg, "disable", length) == 0) |
66 | 69 | return AUTO_BOOLEAN_FALSE; |
67 | 70 | else if (strncmp (arg, "auto", length) == 0 |
68 | - || (strncmp (arg, "-1", length) == 0 && length > 1)) | |
71 | + || (length > 1 && strncmp (arg, "-1", length) == 0)) | |
69 | 72 | return AUTO_BOOLEAN_AUTO; |
70 | 73 | } |
71 | 74 | error (_("\"on\", \"off\" or \"auto\" expected.")); |
@@ -87,12 +90,14 @@ parse_cli_boolean_value (const char *arg) | ||
87 | 90 | while (arg[length - 1] == ' ' || arg[length - 1] == '\t') |
88 | 91 | length--; |
89 | 92 | |
90 | - if (strncmp (arg, "on", length) == 0 | |
93 | + /* Note that "o" is ambiguous. */ | |
94 | + | |
95 | + if ((length == 2 && strncmp (arg, "on", length) == 0) | |
91 | 96 | || strncmp (arg, "1", length) == 0 |
92 | 97 | || strncmp (arg, "yes", length) == 0 |
93 | 98 | || strncmp (arg, "enable", length) == 0) |
94 | 99 | return 1; |
95 | - else if (strncmp (arg, "off", length) == 0 | |
100 | + else if ((length >= 2 && strncmp (arg, "off", length) == 0) | |
96 | 101 | || strncmp (arg, "0", length) == 0 |
97 | 102 | || strncmp (arg, "no", length) == 0 |
98 | 103 | || strncmp (arg, "disable", length) == 0) |
@@ -194,13 +194,16 @@ proc_with_prefix test-boolean {} { | ||
194 | 194 | gdb_test "$set_cmd auto" \ |
195 | 195 | "\"on\" or \"off\" expected\\." |
196 | 196 | |
197 | + # "o" is ambiguous. | |
198 | + gdb_test "$set_cmd o" \ | |
199 | + "\"on\" or \"off\" expected\\." | |
200 | + | |
197 | 201 | # Various valid values. Test both full value names and |
198 | 202 | # abbreviations. |
199 | 203 | |
200 | 204 | # Note that unlike with auto-bool, empty value implies "on". |
201 | 205 | foreach_with_prefix value { |
202 | 206 | "" |
203 | - "o" | |
204 | 207 | "on" |
205 | 208 | "1" |
206 | 209 | "y" |
@@ -278,11 +281,14 @@ proc_with_prefix test-auto-boolean {} { | ||
278 | 281 | gdb_test "$set_cmd on 1" \ |
279 | 282 | "\"on\", \"off\" or \"auto\" expected\\." |
280 | 283 | |
284 | + # "o" is ambiguous. | |
285 | + gdb_test "$set_cmd o" \ | |
286 | + "\"on\", \"off\" or \"auto\" expected\\." | |
287 | + | |
281 | 288 | # Various valid values. Test both full value names and |
282 | 289 | # abbreviations. |
283 | 290 | |
284 | 291 | foreach_with_prefix value { |
285 | - "o" | |
286 | 292 | "on" |
287 | 293 | "1" |
288 | 294 | "y" |