Also, in tok_str_add2, use memcpy instead of the illegal cast. Unfortunately, I can't see an easy way of fixing the bug.
Unified · Split
| @@ -922,18 +922,20 @@ static void tok_str_add2(TokenString *s, int t, CValue *cv) · 921 unmodified lines | ||
| 922 | 922 | case TOK_LSTR: |
| 923 | 923 | { |
| 924 | 924 | int nb_words; |
| 925 | − CString *cstr; | |
| 925 | + CString cstr; | |
| 926 | 926 | |
| 927 | 927 | nb_words = (sizeof(CString) + cv->cstr->size + 3) >> 2; |
| 928 | 928 | while ((len + nb_words) > s->allocated_len) |
| 929 | 929 | str = tok_str_realloc(s); |
| 930 | − cstr = (CString *)(str + len); | |
| 931 | − cstr->data = NULL; | |
| 932 | − cstr->size = cv->cstr->size; | |
| 933 | − cstr->data_allocated = NULL; | |
| 934 | − cstr->size_allocated = cstr->size; | |
| 935 | − memcpy((char *)cstr + sizeof(CString), | |
| 936 | − cv->cstr->data, cstr->size); | |
| 930 | + /* XXX: Insert the CString into the int array. | |
| 931 | + It may end up incorrectly aligned. */ | |
| 932 | + cstr.data = 0; | |
| 933 | + cstr.size = cv->cstr->size; | |
| 934 | + cstr.data_allocated = 0; | |
| 935 | + cstr.size_allocated = cstr.size; | |
| 936 | + memcpy(str + len, &cstr, sizeof(CString)); | |
| 937 | + memcpy((char *)(str + len) + sizeof(CString), | |
| 938 | + cv->cstr->data, cstr.size); | |
| 937 | 939 | len += nb_words; |
| 938 | 940 | } |
| 939 | 941 | break; |
| @@ -1002,6 +1004,7 @@ static inline void TOK_GET(int *t, const int **pp, CValue *cv) · 62 unmodified lines | ||
| 1002 | 1004 | case TOK_LSTR: |
| 1003 | 1005 | case TOK_PPNUM: |
| 1004 | 1006 | case TOK_PPSTR: |
| 1007 | + /* XXX: Illegal cast: the pointer p may not be correctly aligned! */ | |
| 1005 | 1008 | cv->cstr = (CString *)p; |
| 1006 | 1009 | cv->cstr->data = (char *)p + sizeof(CString); |
| 1007 | 1010 | p += (sizeof(CString) + cv->cstr->size + 3) >> 2; |