From: Of Jiri Benc
> Sent: 19 January 2017 14:22
> On Thu, 19 Jan 2017 16:17:48 +0200, Paul Blakey wrote:
> > +   while (token) {
> > +           if (!strncmp(token, "no", 2)) {
> > +                   no = true;
> > +                   token = strchr(token, '_') + 1;
> 
> This seems to still assume that "no" is followed by an underscore.
> What about a simple token += 2?

Actually it was rather worse than that and probably shows a
distinct lack of testing.
Consider what happened with "no", "nofubar" and "nofubar_baz",
all ought to be rejected.

Actually using strncmp() is also overkill.
Nothing wrong with:
        if (token[0] == 'n' && token[1] == 'o' && token[2]) {
                no = true;
                token += 2;
                if (token[0] == '_' && token[1])
                        token++;
                ...

or replace the last 3 lines with:
                token += 2 + (token[2] == '_' & token[3]);

        David

Reply via email to