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
922 case TOK_LSTR:922 case TOK_LSTR:
923 {923 {
924 int nb_words;924 int nb_words;
925 CString *cstr;925 CString cstr;
926 926
927 nb_words = (sizeof(CString) + cv->cstr->size + 3) >> 2;927 nb_words = (sizeof(CString) + cv->cstr->size + 3) >> 2;
928 while ((len + nb_words) > s->allocated_len)928 while ((len + nb_words) > s->allocated_len)
929 str = tok_str_realloc(s);929 str = tok_str_realloc(s);
930 cstr = (CString *)(str + len);930 /* XXX: Insert the CString into the int array.
931 cstr->data = NULL;931 It may end up incorrectly aligned. */
932 cstr->size = cv->cstr->size;932 cstr.data = 0;
933 cstr->data_allocated = NULL;933 cstr.size = cv->cstr->size;
934 cstr->size_allocated = cstr->size;934 cstr.data_allocated = 0;
935 memcpy((char *)cstr + sizeof(CString), 935 cstr.size_allocated = cstr.size;
936 cv->cstr->data, cstr->size);936 memcpy(str + len, &cstr, sizeof(CString));
937 memcpy((char *)(str + len) + sizeof(CString),
938 cv->cstr->data, cstr.size);
937 len += nb_words;939 len += nb_words;
938 }940 }
939 break;941 break;
@@ -1002,6 +1004,7 @@ static inline void TOK_GET(int *t, const int **pp, CValue *cv) · 62 unmodified lines
1002 case TOK_LSTR:1004 case TOK_LSTR:
1003 case TOK_PPNUM:1005 case TOK_PPNUM:
1004 case TOK_PPSTR:1006 case TOK_PPSTR:
1007 /* XXX: Illegal cast: the pointer p may not be correctly aligned! */
1005 cv->cstr = (CString *)p;1008 cv->cstr = (CString *)p;
1006 cv->cstr->data = (char *)p + sizeof(CString);1009 cv->cstr->data = (char *)p + sizeof(CString);
1007 p += (sizeof(CString) + cv->cstr->size + 3) >> 2;1010 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