SVF: insert space before '(' and after ')'
authorsimon qian <simonqian.openocd@gmail.com>
Sun, 17 Jan 2010 20:56:08 +0000 (04:56 +0800)
committerDavid Brownell <dbrownell@users.sourceforge.net>
Sat, 23 Jan 2010 22:24:10 +0000 (14:24 -0800)
See http://forum.sparkfun.com/viewtopic.php?p=90983#90983 for discussion;
basically, the SVF parser wrongly expects "TDI (123)" but the space is
optional and it should accept "TDI(123)" too.

In the same way, "TDI(123)TDO(456)" should work too.

Rather than update the command parsing, this just makes sure the expected
spaces are present.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
src/svf/svf.c

index 7cb220073f3d00ff246e9136dd352031cbacc386..275bced8eca39355ffd8fea07eee3302fada9894 100644 (file)
@@ -504,27 +504,49 @@ static int svf_read_command_from_file(int fd)
                default:
                        if (!comment)
                        {
-                               if (cmd_pos >= svf_command_buffer_size - 1)
+                               /* The parsing code currently expects a space
+                                * before parentheses -- "TDI (123)".  Also a
+                                * space afterwards -- "TDI (123) TDO(456)".
+                                * But such spaces are optional... instead of
+                                * parser updates, cope with that by adding the
+                                * spaces as needed.
+                                *
+                                * Ensure there are 3 bytes available, for:
+                                *  - current character
+                                *  - added space.
+                                *  - terminating NUL ('\0')
+                                */
+                               if ((cmd_pos + 2) >= svf_command_buffer_size)
                                {
-                                       tmp_buffer = (char*)malloc(svf_command_buffer_size + SVFP_CMD_INC_CNT);         // 1 more byte for '\0'
+                                       /* REVISIT use realloc(); simpler */
+                                       tmp_buffer = malloc(
+                                                       svf_command_buffer_size
+                                                       + SVFP_CMD_INC_CNT);
                                        if (NULL == tmp_buffer)
                                        {
                                                LOG_ERROR("not enough memory");
                                                return ERROR_FAIL;
                                        }
                                        if (svf_command_buffer_size > 0)
-                                       {
-                                               memcpy(tmp_buffer, svf_command_buffer, svf_command_buffer_size);
-                                       }
+                                               memcpy(tmp_buffer,
+                                                       svf_command_buffer,
+                                                       svf_command_buffer_size);
                                        if (svf_command_buffer != NULL)
-                                       {
                                                free(svf_command_buffer);
-                                       }
                                        svf_command_buffer = tmp_buffer;
                                        svf_command_buffer_size += SVFP_CMD_INC_CNT;
                                        tmp_buffer = NULL;
                                }
+
+                               /* insert a space before '(' */
+                               if ('(' == ch)
+                                       svf_command_buffer[cmd_pos++] = ' ';
+
                                svf_command_buffer[cmd_pos++] = (char)toupper(ch);
+
+                               /* insert a space after ')' */
+                               if (')' == ch)
+                                       svf_command_buffer[cmd_pos++] = ' ';
                        }
                        break;
                }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)