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.
This commit is contained in:
Edmund Grimley Evans 2015-11-04 20:27:54 +00:00
parent 20f0c179da
commit 24308fd292

19
tccpp.c
View File

@ -922,18 +922,20 @@ static void tok_str_add2(TokenString *s, int t, CValue *cv)
case TOK_LSTR: case TOK_LSTR:
{ {
int nb_words; int nb_words;
CString *cstr; CString cstr;
nb_words = (sizeof(CString) + cv->cstr->size + 3) >> 2; nb_words = (sizeof(CString) + cv->cstr->size + 3) >> 2;
while ((len + nb_words) > s->allocated_len) while ((len + nb_words) > s->allocated_len)
str = tok_str_realloc(s); str = tok_str_realloc(s);
cstr = (CString *)(str + len); /* XXX: Insert the CString into the int array.
cstr->data = NULL; It may end up incorrectly aligned. */
cstr->size = cv->cstr->size; cstr.data = 0;
cstr->data_allocated = NULL; cstr.size = cv->cstr->size;
cstr->size_allocated = cstr->size; cstr.data_allocated = 0;
memcpy((char *)cstr + sizeof(CString), cstr.size_allocated = cstr.size;
cv->cstr->data, cstr->size); memcpy(str + len, &cstr, sizeof(CString));
memcpy((char *)(str + len) + sizeof(CString),
cv->cstr->data, cstr.size);
len += nb_words; len += nb_words;
} }
break; break;
@ -1002,6 +1004,7 @@ static inline void TOK_GET(int *t, const int **pp, CValue *cv)
case TOK_LSTR: case TOK_LSTR:
case TOK_PPNUM: case TOK_PPNUM:
case TOK_PPSTR: case TOK_PPSTR:
/* XXX: Illegal cast: the pointer p may not be correctly aligned! */
cv->cstr = (CString *)p; cv->cstr = (CString *)p;
cv->cstr->data = (char *)p + sizeof(CString); cv->cstr->data = (char *)p + sizeof(CString);
p += (sizeof(CString) + cv->cstr->size + 3) >> 2; p += (sizeof(CString) + cv->cstr->size + 3) >> 2;