Mercurial > MadButterfly
diff src/shape_path.c @ 11:128af06c876c
Fix the bug that data of a path end with white spaces would make system down
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sat, 26 Jul 2008 06:34:15 +0800 |
parents | 7cfecdce94cc |
children | 79e9edf4c00a |
line wrap: on
line diff
--- a/src/shape_path.c Sat Jul 26 05:32:31 2008 +0800 +++ b/src/shape_path.c Sat Jul 26 06:34:15 2008 +0800 @@ -21,12 +21,13 @@ #define RESERVED_AIXS sizeof(co_aix[2]) #define ASSERT(x) -#define SKIP_SPACE(x) while(*(x) && isspace(*(x))) { (x)++; } +#define SKIP_SPACE(x) while(*(x) && (isspace(*(x)) || *(x) == ',')) { (x)++; } #define SKIP_NUM(x) \ while(*(x) && \ (isdigit(*(x)) || \ *(x) == '-' || \ - *(x) == '+')) { \ + *(x) == '+' || \ + *(x) == '.')) { \ (x)++; \ } #define OK 0 @@ -47,9 +48,8 @@ cmd_cnt = arg_cnt = 0; p = data; + SKIP_SPACE(p); while(*p) { - SKIP_SPACE(p); - switch(*p++) { case 'c': case 'C': @@ -175,6 +175,7 @@ return ERR; } cmd_cnt++; + SKIP_SPACE(p); } *cmd_cntp = cmd_cnt; @@ -193,9 +194,8 @@ cmds = path->user_data; args = (co_aix *)(cmds + path->cmd_len); p = data; + SKIP_SPACE(p); while(*p) { - SKIP_SPACE(p); - /* Transform all relative to absolute, */ *cmds++ = toupper(*p); switch((cmd = *p++)) { @@ -327,6 +327,7 @@ default: return ERR; } + SKIP_SPACE(p); } return OK; @@ -593,6 +594,15 @@ sh_path_free((shape_t *)path); } +void test_spaces_head_tail(void) { + sh_path_t *path; + + path = (sh_path_t *) + sh_path_new(" M 33 25l33 55C 33 87 44 22 55 99L33 77z "); + CU_ASSERT(path != NULL); + sh_path_free((shape_t *)path); +} + CU_pSuite get_shape_path_suite(void) { CU_pSuite suite;