[Nut-upsdev] gcc4 compiler warnings

Peter Selinger selinger at mathstat.dal.ca
Fri Feb 10 14:02:41 UTC 2006


Gentlemen,

I believe the functions that cause the most compiler warnings are
functions such as:

int ser_send_buf(int fd, const char *buf, size_t buflen);
int ser_get_char(int fd, char *ch, long d_sec, long d_usec);
int ser_get_line(int fd, char *buf, size_t buflen, char endchar,
   const char *ignset, long d_sec, long d_usec);
int ser_get_buf_len(int fd, char *buf, size_t buflen, long d_sec, long d_usec);

etc. in drivers/serial.h.

Changing the prototypes of these functions to use "unsigned char *buf"
instead of "char *buf" will have _no effect whatsoever_ on the drivers
that call there functions. These functions do not perform any actual
operations on characters, the only fill buffers with bytes.  For
example, my driver contains code such as:

{
  unsigned char buf[MAXMSGSIZE];
  ...
  r = ser_send_buf(upsfd, buf, 6); 
  ...
}

Somebody else's driver might contain

{
  char buf[MAXMSGSIZE];
  ...
  r = ser_send_buf(upsfd, buf, 6);
  ...
}

The behavior is completely unaffected by what ser_send_buf thinks the
type of this pointer is; the only difference is in the compiler warnings. 
In this case, the second driver could turn off the warnings by doing:

  r = ser_send_buf(upsfd, (unsigned char *)buf, 6);

-- Peter


Charles Lepple wrote:
> 
> On 2/10/06, Arjen de Korte <nut+devel at de-korte.org> wrote:
> [...]
> > > Speaking of which, are there any cases where UTF-8 would cause
> > > problems? In most cases where string comparisons are being used, the
> > > UPS should be sending 7-bit values, so this may not be an issue.
> >
> > Indeed, it probably wouldn't be much an issue. String operations have no
> > notion of UTF-8 and are only guaranteed to work on ASCII characters
> > (0x00-0x7F) anyway.
> 
> Ah, I didn't notice that strcmp compares characters, while strcoll
> (which isn't used in NUT) takes the locale into consideration.
> 
> > So if your UPS speaks UTF-8, you'd better leave the
> > string functions out, or you may be in for some real unpleasant surprizes
> > sooner or later.
> 
> I was worried more that an UPS which sends bytes > 128 would have
> those bytes misinterpreted as part of a UTF-8 string, given a certain
> locale configuration. Never mind.
> 
> --
> - Charles Lepple
> 
> _______________________________________________
> Nut-upsdev mailing list
> Nut-upsdev at lists.alioth.debian.org
> http://lists.alioth.debian.org/mailman/listinfo/nut-upsdev
> 




More information about the Nut-upsdev mailing list