diff options
| author | Edmund Grimley Evans <Edmund.Grimley.Evans@gmail.com> | 2015-11-04 20:27:54 +0000 |
|---|---|---|
| committer | Edmund Grimley Evans <Edmund.Grimley.Evans@gmail.com> | 2015-11-04 20:27:54 +0000 |
| commit | 24308fd29285eb507054d6182288c2feb275c6bd (patch) | |
| tree | 86f317c7e860e98c84adb8e527ad98f0f523fb30 /tccpp.c | |
| parent | 20f0c179daeaa191c1ec39ac8a9a93f1942c1673 (diff) | |
| download | tinycc-24308fd29285eb507054d6182288c2feb275c6bd.tar.gz tinycc-24308fd29285eb507054d6182288c2feb275c6bd.tar.bz2 | |
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.
Diffstat (limited to 'tccpp.c')
| -rw-r--r-- | tccpp.c | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -922,18 +922,20 @@ static void tok_str_add2(TokenString *s, int t, CValue *cv) case TOK_LSTR: { int nb_words; - CString *cstr; + CString cstr; nb_words = (sizeof(CString) + cv->cstr->size + 3) >> 2; while ((len + nb_words) > s->allocated_len) str = tok_str_realloc(s); - cstr = (CString *)(str + len); - cstr->data = NULL; - cstr->size = cv->cstr->size; - cstr->data_allocated = NULL; - cstr->size_allocated = cstr->size; - memcpy((char *)cstr + sizeof(CString), - cv->cstr->data, cstr->size); + /* XXX: Insert the CString into the int array. + It may end up incorrectly aligned. */ + cstr.data = 0; + cstr.size = cv->cstr->size; + cstr.data_allocated = 0; + cstr.size_allocated = cstr.size; + memcpy(str + len, &cstr, sizeof(CString)); + memcpy((char *)(str + len) + sizeof(CString), + cv->cstr->data, cstr.size); len += nb_words; } break; @@ -1002,6 +1004,7 @@ static inline void TOK_GET(int *t, const int **pp, CValue *cv) case TOK_LSTR: case TOK_PPNUM: case TOK_PPSTR: + /* XXX: Illegal cast: the pointer p may not be correctly aligned! */ cv->cstr = (CString *)p; cv->cstr->data = (char *)p + sizeof(CString); p += (sizeof(CString) + cv->cstr->size + 3) >> 2; |
