bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

shuf.c build failures -- trivial code issue


From: Bob Proulx
Subject: shuf.c build failures -- trivial code issue
Date: Wed, 9 Aug 2006 09:02:43 -0600
User-agent: Mutt/1.5.9i

The recently added shuf.c file fails to build for me on HP-UX using
the native C compiler due to a small code issue.  Here is the error.

  source='shuf.c' object='shuf.o' libtool=no \
          DEPDIR=.deps depmode=hp /bin/sh ../build-aux/depcomp \
          cc -DHAVE_CONFIG_H -I. -I. -I..  -I.. -I. -I../lib -I../lib   -Ae -O 
-c shuf.c
  cc: "shuf.c", line 196: error 1539: Cannot do arithmetic with pointers to 
objects of unknown size.
  cc: "shuf.c", line 203: error 1539: Cannot do arithmetic with pointers to 
objects of unknown size.

Here is the code:

  n_lines = 0;
  for (p = buf; p < lim; p = memchr (p, eolbyte, lim - p) + 1)
    n_lines++;
  ...
    line[i] = p = memchr (p, eolbyte, lim - p) + 1;

The problem is with the use of memchr().  It returns a void* which
cannot be combined with the "+ 1" at the same time.  The size of void*
is not known and cannot be incremented.

  p = memchr (p, eolbyte, lim - p) + 1;  /* error */

Trivially doing the +1 after it has been assigned to p, which has a
known type, solves the problem.  Here is a long form for clarity.
This works because the type of p is known.  (I dislike casts and so
would not suggest it but additionally adding a cast to the return of
memchr() would also work and would be a smaller code change.)

  p = memchr (p, eolbyte, lim - p);
  p = p + 1;

Sorry but I did not look at the code in enough detail to suggest a
real quality fix.

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]