Date: Tue, 27 Nov 2007 18:20:04 +0100 From: Hans Petter Selasky <hselasky@freebsd.org> To: Alfred Perlstein <alfred@freebsd.org> Cc: Perforce Change Reviews <perforce@freebsd.org> Subject: Re: PERFORCE change 129580 for review Message-ID: <200711271820.05134.hselasky@freebsd.org> In-Reply-To: <20071127073825.GV71382@elvis.mu.org> References: <200711262025.lAQKPO3b036323@repoman.freebsd.org> <20071127073825.GV71382@elvis.mu.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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@FreeBSD.org> [071126 12:25] wrote: > > http://perforce.freebsd.org/chv.cgi?CH=129580 > > > > Change 129580 by hselasky@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().
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200711271820.05134.hselasky>