Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 312336
b: refs/heads/master
c: deba3fb
h: refs/heads/master
v: v3
  • Loading branch information
Namhyung Kim authored and Namhyung Kim committed Jul 4, 2012
1 parent b95d219 commit fa38f07
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 0fc45ef5202a34b5862ca246740e6ab50bc3e3e1
refs/heads/master: deba3fb26fd1ed3235b00dccced9784a7f76ec3c
50 changes: 24 additions & 26 deletions trunk/tools/lib/traceevent/event-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,25 @@ int pevent_peek_char(void)
return __peek_char();
}

static int extend_token(char **tok, char *buf, int size)
{
char *newtok = realloc(*tok, size);

if (!newtok) {
free(*tok);
*tok = NULL;
return -1;
}

if (!*tok)
strcpy(newtok, buf);
else
strcat(newtok, buf);
*tok = newtok;

return 0;
}

static enum event_type force_token(const char *str, char **tok);

static enum event_type __read_token(char **tok)
Expand Down Expand Up @@ -865,17 +884,10 @@ static enum event_type __read_token(char **tok)
do {
if (i == (BUFSIZ - 1)) {
buf[i] = 0;
if (*tok) {
*tok = realloc(*tok, tok_size + BUFSIZ);
if (!*tok)
return EVENT_NONE;
strcat(*tok, buf);
} else
*tok = strdup(buf);
tok_size += BUFSIZ;

if (!*tok)
if (extend_token(tok, buf, tok_size) < 0)
return EVENT_NONE;
tok_size += BUFSIZ;
i = 0;
}
last_ch = ch;
Expand Down Expand Up @@ -914,17 +926,10 @@ static enum event_type __read_token(char **tok)
while (get_type(__peek_char()) == type) {
if (i == (BUFSIZ - 1)) {
buf[i] = 0;
if (*tok) {
*tok = realloc(*tok, tok_size + BUFSIZ);
if (!*tok)
return EVENT_NONE;
strcat(*tok, buf);
} else
*tok = strdup(buf);
tok_size += BUFSIZ;

if (!*tok)
if (extend_token(tok, buf, tok_size) < 0)
return EVENT_NONE;
tok_size += BUFSIZ;
i = 0;
}
ch = __read_char();
Expand All @@ -933,14 +938,7 @@ static enum event_type __read_token(char **tok)

out:
buf[i] = 0;
if (*tok) {
*tok = realloc(*tok, tok_size + i);
if (!*tok)
return EVENT_NONE;
strcat(*tok, buf);
} else
*tok = strdup(buf);
if (!*tok)
if (extend_token(tok, buf, tok_size + i + 1) < 0)
return EVENT_NONE;

if (type == EVENT_ITEM) {
Expand Down

0 comments on commit fa38f07

Please sign in to comment.