Unified · Split
| @@ -1150,7 +1150,8 @@ TokenSym *tok_alloc(const char *str, int len) · 1149 unmodified lines | ||
| 1150 | 1150 | ts->sym_identifier = NULL; |
| 1151 | 1151 | ts->len = len; |
| 1152 | 1152 | ts->hash_next = NULL; |
| 1153 | − memcpy(ts->str, str, len + 1); | |
| 1153 | + memcpy(ts->str, str, len); | |
| 1154 | + ts->str[len] = '\0'; | |
| 1154 | 1155 | *pts = ts; |
| 1155 | 1156 | return ts; |
| 1156 | 1157 | } |
| @@ -7557,24 +7558,35 @@ static int tcc_compile(TCCState *s1) · 6400 unmodified lines | ||
| 7557 | 7558 | return s1->nb_errors != 0 ? -1 : 0; |
| 7558 | 7559 | } |
| 7559 | 7560 | |
| 7561 | +#ifdef LIBTCC | |
| 7560 | 7562 | int tcc_compile_string(TCCState *s, const char *str) |
| 7561 | 7563 | { |
| 7562 | 7564 | BufferedFile bf1, *bf = &bf1; |
| 7563 | − int ret; | |
| 7565 | + int ret, len; | |
| 7566 | + char *buf; | |
| 7564 | 7567 | |
| 7565 | 7568 | /* init file structure */ |
| 7566 | 7569 | bf->fd = -1; |
| 7567 | − bf->buf_ptr = (char *)str; | |
| 7568 | − bf->buf_end = (char *)str + strlen(bf->buffer); | |
| 7570 | + /* XXX: avoid copying */ | |
| 7571 | + len = strlen(str); | |
| 7572 | + buf = tcc_malloc(len + 1); | |
| 7573 | + if (!buf) | |
| 7574 | + return -1; | |
| 7575 | + buf[len] = CH_EOB; | |
| 7576 | + bf->buf_ptr = buf; | |
| 7577 | + bf->buf_end = buf + len; | |
| 7569 | 7578 | pstrcpy(bf->filename, sizeof(bf->filename), "<string>"); |
| 7570 | 7579 | bf->line_num = 1; |
| 7571 | 7580 | file = bf; |
| 7572 | 7581 | |
| 7573 | 7582 | ret = tcc_compile(s); |
| 7574 | 7583 | |
| 7584 | + tcc_free(buf); | |
| 7585 | + | |
| 7575 | 7586 | /* currently, no need to close */ |
| 7576 | 7587 | return ret; |
| 7577 | 7588 | } |
| 7589 | +#endif | |
| 7578 | 7590 | |
| 7579 | 7591 | /* define a preprocessor symbol. A value can also be provided with the '=' operator */ |
| 7580 | 7592 | void tcc_define_symbol(TCCState *s1, const char *sym, const char *value) |