diff options
-rw-r--r-- | tools/lib/traceevent/event-parse.c | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c index 7815b8d2eabd..768fab5fbcb7 100644 --- a/tools/lib/traceevent/event-parse.c +++ b/tools/lib/traceevent/event-parse.c | |||
@@ -781,6 +781,25 @@ int pevent_peek_char(void) | |||
781 | return __peek_char(); | 781 | return __peek_char(); |
782 | } | 782 | } |
783 | 783 | ||
784 | static int extend_token(char **tok, char *buf, int size) | ||
785 | { | ||
786 | char *newtok = realloc(*tok, size); | ||
787 | |||
788 | if (!newtok) { | ||
789 | free(*tok); | ||
790 | *tok = NULL; | ||
791 | return -1; | ||
792 | } | ||
793 | |||
794 | if (!*tok) | ||
795 | strcpy(newtok, buf); | ||
796 | else | ||
797 | strcat(newtok, buf); | ||
798 | *tok = newtok; | ||
799 | |||
800 | return 0; | ||
801 | } | ||
802 | |||
784 | static enum event_type force_token(const char *str, char **tok); | 803 | static enum event_type force_token(const char *str, char **tok); |
785 | 804 | ||
786 | static enum event_type __read_token(char **tok) | 805 | static enum event_type __read_token(char **tok) |
@@ -865,17 +884,10 @@ static enum event_type __read_token(char **tok) | |||
865 | do { | 884 | do { |
866 | if (i == (BUFSIZ - 1)) { | 885 | if (i == (BUFSIZ - 1)) { |
867 | buf[i] = 0; | 886 | buf[i] = 0; |
868 | if (*tok) { | 887 | tok_size += BUFSIZ; |
869 | *tok = realloc(*tok, tok_size + BUFSIZ); | ||
870 | if (!*tok) | ||
871 | return EVENT_NONE; | ||
872 | strcat(*tok, buf); | ||
873 | } else | ||
874 | *tok = strdup(buf); | ||
875 | 888 | ||
876 | if (!*tok) | 889 | if (extend_token(tok, buf, tok_size) < 0) |
877 | return EVENT_NONE; | 890 | return EVENT_NONE; |
878 | tok_size += BUFSIZ; | ||
879 | i = 0; | 891 | i = 0; |
880 | } | 892 | } |
881 | last_ch = ch; | 893 | last_ch = ch; |
@@ -914,17 +926,10 @@ static enum event_type __read_token(char **tok) | |||
914 | while (get_type(__peek_char()) == type) { | 926 | while (get_type(__peek_char()) == type) { |
915 | if (i == (BUFSIZ - 1)) { | 927 | if (i == (BUFSIZ - 1)) { |
916 | buf[i] = 0; | 928 | buf[i] = 0; |
917 | if (*tok) { | 929 | tok_size += BUFSIZ; |
918 | *tok = realloc(*tok, tok_size + BUFSIZ); | ||
919 | if (!*tok) | ||
920 | return EVENT_NONE; | ||
921 | strcat(*tok, buf); | ||
922 | } else | ||
923 | *tok = strdup(buf); | ||
924 | 930 | ||
925 | if (!*tok) | 931 | if (extend_token(tok, buf, tok_size) < 0) |
926 | return EVENT_NONE; | 932 | return EVENT_NONE; |
927 | tok_size += BUFSIZ; | ||
928 | i = 0; | 933 | i = 0; |
929 | } | 934 | } |
930 | ch = __read_char(); | 935 | ch = __read_char(); |
@@ -933,14 +938,7 @@ static enum event_type __read_token(char **tok) | |||
933 | 938 | ||
934 | out: | 939 | out: |
935 | buf[i] = 0; | 940 | buf[i] = 0; |
936 | if (*tok) { | 941 | if (extend_token(tok, buf, tok_size + i + 1) < 0) |
937 | *tok = realloc(*tok, tok_size + i); | ||
938 | if (!*tok) | ||
939 | return EVENT_NONE; | ||
940 | strcat(*tok, buf); | ||
941 | } else | ||
942 | *tok = strdup(buf); | ||
943 | if (!*tok) | ||
944 | return EVENT_NONE; | 942 | return EVENT_NONE; |
945 | 943 | ||
946 | if (type == EVENT_ITEM) { | 944 | if (type == EVENT_ITEM) { |