On Thu, Nov 17, 2011 at 09:48:36PM +0800, Michael W. Bombardieri wrote: > Hi tech, > > I have a simple diff for ksh(1) which takes > care to not read past the end of the static > buffer 'holdbuf' where the length of 'pat' > is greater than the buffer. >
holdbuf is zero-terminated, so strcmp() won't go past the end of holdbuf, and seems more appropriate > Does anyone think this is worthwhile? If not, > should we remove the XXX comment altogether? > > - Michael > > > Index: vi.c > =================================================================== > RCS file: /usr/src/cvs/src/bin/ksh/vi.c,v > retrieving revision 1.26 > diff -u -r1.26 vi.c > --- vi.c 29 Jun 2009 22:50:19 -0000 1.26 > +++ vi.c 17 Nov 2011 13:35:25 -0000 > @@ -1675,8 +1675,8 @@ > anchored = *pat == '^' ? (++pat, 1) : 0; > if ((hist = findhist(start, fwd, pat, anchored)) < 0) { > /* if (start != 0 && fwd && match(holdbuf, pat) >= 0) { */ > - /* XXX should strcmp be strncmp? */ > - if (start != 0 && fwd && strcmp(holdbuf, pat) >= 0) { > + if (start != 0 && fwd && > + strncmp(holdbuf, pat, sizeof(holdbuf)) >= 0) { > restore_cbuf(); > return 0; > } else -- Alexandre