PERFORCE change 129580 for review
Hans Petter Selasky
hselasky at freebsd.org
Tue Nov 27 10:34:36 PST 2007
Hi,
I will make a wrapper function that uses "strlen()". This is not time critical
code.
--HPS
On Tuesday 27 November 2007, Alfred Perlstein wrote:
> * Hans Petter Selasky <hselasky at FreeBSD.org> [071126 12:25] wrote:
> > http://perforce.freebsd.org/chv.cgi?CH=129580
> >
> > Change 129580 by hselasky at hselasky_laptop001 on 2007/11/26 20:24:39
> >
> >
> > Bugfix.
> >
> > Affected files ...
> >
> > .. //depot/projects/usb/src/sys/dev/usb/ulpt.c#29 edit
> >
> > Differences ...
> >
> > ==== //depot/projects/usb/src/sys/dev/usb/ulpt.c#29 (text+ko) ====
> >
> > @@ -707,7 +707,7 @@
> > for (p = str - 1; p; p = strchr(p, ';')) {
> > p++; /* skip ';' */
> > if (strncmp(p, "MFG:", 4) == 0 ||
> > - strncmp(p, "MANUFACTURER:", 14) == 0 ||
> > + strncmp(p, "MANUFACTURER:", 13) == 0 ||
> > strncmp(p, "MDL:", 4) == 0 ||
> > strncmp(p, "MODEL:", 6) == 0) {
> > q = strchr(p, ';');
>
> This can be done with the following macro to avoid bugs:
>
> /* used as so: CONSTSTRCMP(p, "MFG:") */
> #define CONSTSTRCMP(str, cstr) strncmp(str, cstr, sizeof(cstr))
>
> (you may need a -1 after the sizeof, I forget at this hour.)
>
> of course this fails, badly if one doesn't use a const string as
> the second arg.
>
> For non time critical code one could replace the sizeof() with
> strlen().
More information about the p4-projects
mailing list