History

use CH_EOB

bellard committed 23 years ago

Commit 2f219d81 parent 63965fc1 file · +16 −4Browse files

Unified · Split

tcc.c+16−4
@@ -1150,7 +1150,8 @@ TokenSym *tok_alloc(const char *str, int len) · 1149 unmodified lines
11501150 ts->sym_identifier = NULL;
11511151 ts->len = len;
11521152 ts->hash_next = NULL;
1153− memcpy(ts->str, str, len + 1);
1153+ memcpy(ts->str, str, len);
1154+ ts->str[len] = '\0';
11541155 *pts = ts;
11551156 return ts;
11561157 }
@@ -7557,24 +7558,35 @@ static int tcc_compile(TCCState *s1) · 6400 unmodified lines
75577558 return s1->nb_errors != 0 ? -1 : 0;
75587559 }
75597560
7561+#ifdef LIBTCC
75607562 int tcc_compile_string(TCCState *s, const char *str)
75617563 {
75627564 BufferedFile bf1, *bf = &bf1;
7563− int ret;
7565+ int ret, len;
7566+ char *buf;
75647567
75657568 /* init file structure */
75667569 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;
75697578 pstrcpy(bf->filename, sizeof(bf->filename), "<string>");
75707579 bf->line_num = 1;
75717580 file = bf;
75727581
75737582 ret = tcc_compile(s);
75747583
7584+ tcc_free(buf);
7585+
75757586 /* currently, no need to close */
75767587 return ret;
75777588 }
7589+#endif
75787590
75797591 /* define a preprocessor symbol. A value can also be provided with the '=' operator */
75807592 void tcc_define_symbol(TCCState *s1, const char *sym, const char *value)

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