Subject: Re: bus.h style question
To: Matt Thomas <matt@3am-software.com>
From: Bill Studenmund <wrstuden@loki.stanford.edu>
List: tech-kern
Date: 08/14/1997 10:35:01
> 
> At 07:05 AM 8/14/97 +0200, Martin Husemann wrote:
> >I have two question on usage of the bus.h interface:
> >
> >My card is mapped into ISA memory. At one time it generates a zero terminated
> >string in this memory area, followed by a u_int32_t value. So what I do is:
> >
> >	int i;
> >	u_int32_t value;
> >	u_int8_t *p, buffer[MAX_BUF_SIZE];
> >	for (p = buffer, i = 0; *p && i < sizeof buffer; i++, p++)
> >		*p++ = bus_space_read_1(sc->sc_iot, sc->sc_ioh, MYOFF+i);
> 
> That can't be right.  buffer is not initialized yet.
> 
> 	u_int8_t *p, buffer[MAX_BUF_SIZE];
> 	*p = bus_space_read_1(sc->sc_iot, sc->sc_ioh, MYOFF);
> 	for (p = buffer, i = 0; *p && i < sizeof buffer - 1; i++)
> 		*++p = bus_space_read_1(sc->sc_iot, sc->sc_ioh, MYOFF + (i+1));

How about:

for (p=buffer-1, i=0; ...

Otherwise the first byte of the string goes into buffer[1].

Take care,

Bill