History

tccpp.c: In TOK_GET, add comment warning about illegal cast.

Also, in tok_str_add2, use memcpy instead of the illegal cast. Unfortunately, I can't see an easy way of fixing the bug.

Edmund Grimley Evans committed 11 years ago

Commit 24308fd1 parent 20f0c171 file · +11 −8Browse files

Unified · Split

tccpp.c+11−8
@@ -922,18 +922,20 @@ static void tok_str_add2(TokenString *s, int t, CValue *cv) · 921 unmodified lines
922922 case TOK_LSTR:
923923 {
924924 int nb_words;
925− CString *cstr;
925+ CString cstr;
926926
927927 nb_words = (sizeof(CString) + cv->cstr->size + 3) >> 2;
928928 while ((len + nb_words) > s->allocated_len)
929929 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);
937939 len += nb_words;
938940 }
939941 break;
@@ -1002,6 +1004,7 @@ static inline void TOK_GET(int *t, const int **pp, CValue *cv) · 62 unmodified lines
10021004 case TOK_LSTR:
10031005 case TOK_PPNUM:
10041006 case TOK_PPSTR:
1007+ /* XXX: Illegal cast: the pointer p may not be correctly aligned! */
10051008 cv->cstr = (CString *)p;
10061009 cv->cstr->data = (char *)p + sizeof(CString);
10071010 p += (sizeof(CString) + cv->cstr->size + 3) >> 2;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t