lkml.org 
[lkml]   [2010]   [Dec]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH -tip 2/4] [BUGFIX]perf: Fix strlist__parse_list to handle const string
    Em Fri, Dec 17, 2010 at 10:12:06PM +0900, Masami Hiramatsu escreveu:
    > Fix strlist__parse_list to handle const string. Without this patch,
    > strlist__parse_list() causes SEGV when caller passes a constant
    > string.

    > +++ b/tools/perf/util/strlist.c
    > @@ -136,13 +136,19 @@ static int strlist__parse_list_entry(struct strlist *self, const char *s)
    >
    > int strlist__parse_list(struct strlist *self, const char *s)
    > {
    > - char *sep;
    > + char *sep, *tmp;
    > int err;
    >
    > + /* This method requires strdup, because this changes given string */
    > + if (!self->dupstr)
    > + return -EINVAL;
    > +

    Why is the above check needed if you solved the problem by strnduping at
    each separator?

    Wouldn't be better to just stop changing the string by passing the
    length to strlist__parse_list_entry, etc?

    > while ((sep = strchr(s, ',')) != NULL) {
    > - *sep = '\0';
    > - err = strlist__parse_list_entry(self, s);
    > - *sep = ',';
    > + tmp = strndup(s, sep - s);
    > + if (tmp == NULL)
    > + return -ENOMEM;
    > + err = strlist__parse_list_entry(self, tmp);
    > + free(tmp);
    > if (err != 0)
    > return err;
    > s = sep + 1;


    \
     
     \ /
      Last update: 2010-12-21 19:25    [W:0.026 / U:0.560 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site