Paul Eggert | 1 Sep 2005 01:09
Favicon

Re: warning: comparison is always false due to limited range of data type

Jim Meyering <jim <at> meyering.net> writes:

> Is it really permitted to have sizeof (size_t) < sizeof (unsigned int)?

Yes, I'm afraid so.  The C Standard merely says that size_t is an
unsigned integer type; size_t is allowed to be narrower than unsigned int.
See, for example, Mark Brader's 10-year-old post on this subject in
<http://groups.google.com/group/comp.std.c/msg/70cbd32ec8543738>
(originally <news:1996Jun6.203847.26420 <at> sq.com>).

> Sounds pretty darn perverted, and I'll bet it would make lots of code break.

I agree.  I can't imagine it occuring on a general-purpose host.
Maybe some of the odder embedded hosts.  It's not worth worrying
about if it takes real work to make the code portable.

>> Also, I'd rather not penalize all compilers just because GCC is busted.
>
> I understand the point, but wonder if this `penalty'
> is even measurable, in practice.

Not here; but I am a bit worried about the precedent.  Checking for
size-arithmetic overflow can slow things down quite a bit in some
other cases.  (Perhaps I'm being overly influenced here by the regex
code, which I've been looking at for a bit, and which I'm afraid
contains many arithmetic-overflow bugs....)

> The offending warning breaks coreutils' `make distcheck' rule.

Would it make sense to rewrite coreutils 'make distcheck' to filter
(Continue reading)

Paul Eggert | 1 Sep 2005 01:38
Favicon

Re: const-correctness fixes for regex

Jim Meyering <jim <at> meyering.net> writes:

> A week or so ago, I stumbled across one interface that was missing a
> `const' attribute on a parameter, then dug up a few more.  Paul, let me
> know when you reach a point at which my checking this in won't interfere.

It's easier for me if I just get it off the plate and install it now.
I installed this into gnulib and filed glibc bug 1282.  Thanks.

I wish missing-const-detection could be done automatically.  I suppose
we could add const to all the pointers, and then remove each const
that causes a diagnostic, but that sounds pretty painful....

2005-08-31  Jim Meyering  <jim <at> meyering.net>

	* lib/regcomp.c (search_duplicated_node): Make first pointer arg
	a pointer-to-const.
	* lib/regex_internal.c (create_ci_newstate, create_cd_newstate):
	(register_state): Likewise.
	* lib/regexec.c (search_cur_bkref_entry, check_dst_limits):
	(check_dst_limits_calc_pos_1, check_dst_limits_calc_pos):
	(group_nodes_into_DFAstates): Likewise.
	* config/srclist.txt: Add glibc bug 1282.

--- lib/regcomp.c	31 Aug 2005 22:51:10 -0000	1.13
+++ lib/regcomp.c	31 Aug 2005 23:25:36 -0000
 <at>  <at>  -46,7 +46,7  <at>  <at>  static reg_errcode_t calc_first (void *e
 static reg_errcode_t calc_next (void *extra, bin_tree_t *node);
 static reg_errcode_t link_nfa_nodes (void *extra, bin_tree_t *node);
 static Idx duplicate_node (re_dfa_t *dfa, Idx org_idx, unsigned int constraint);
(Continue reading)

Paul Eggert | 1 Sep 2005 09:09
Favicon

improved regex sanity checks for large buffer sizes

I installed this and filed glibc bug 1284:

2005-08-31  Paul Eggert  <eggert <at> cs.ucla.edu>

	* lib/regex_internal.c (re_string_reconstruct): Don't assume buffer
	lengths fit in regoff_t; this isn't true if regoff_t is the same
	width as size_t.
	* lib/regex.c (re_search_internal): 5th arg is LAST_START
	(= START + RANGE) instead of RANGE.  This avoids overflow
	problems when regoff_t is the same width as size_t.
	All callers changed.
	(re_search_2_stub): Check for overflow when adding the
	sizes of the two strings.
	(re_search_stub): Check for overflow when adding START
	to RANGE; if it occurs, substitute the extreme value.
	* config/srclist.txt: Add glibc bug 1284.

--- lib/regex_internal.c	31 Aug 2005 23:36:43 -0000	1.11
+++ lib/regex_internal.c	1 Sep 2005 06:43:13 -0000
 <at>  <at>  -557,8 +557,11  <at>  <at>  static reg_errcode_t
 internal_function
 re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
 {
-  regoff_t offset = (regoff_t) idx - (regoff_t) pstr->raw_mbs_idx;
-  if (BE (offset < 0, 0))
+  Idx offset;
+
+  if (BE (pstr->raw_mbs_idx <= idx, 0))
+    offset = idx - pstr->raw_mbs_idx;
+  else
(Continue reading)

Jim Meyering | 1 Sep 2005 10:52
Gravatar

Re: warning: comparison is always false due to limited range of data type

Paul Eggert <eggert <at> CS.UCLA.EDU> wrote:
> Jim Meyering <jim <at> meyering.net> writes:
>> Is it really permitted to have sizeof (size_t) < sizeof (unsigned int)?
...
>> The offending warning breaks coreutils' `make distcheck' rule.
>
> Would it make sense to rewrite coreutils 'make distcheck' to filter
> out the bogus diagnostics?  That might be a simpler fix.

The failing rule uses $(MAKE) with gcc and CFLAGS containing -Werror.
I'd rather not grep for warnings or ignore all warnings in that file.

Here's the rule, from Makefile.maint:

# Detect format-string/arg-list mismatches that would normally be obscured
# by the use of _().  The --disable-nls effectively defines away that macro,
# and building with CFLAGS='-Wformat -Werror' causes any format warning to be
# treated as a failure.  Also, check for shadowing problems with -Wshadow.
# These CFLAGS are pretty strict.  If you build this target, you probably
# have to have a recent version of gcc and glibc headers.
TMPDIR ?= /tmp
t=$(TMPDIR)/$(PACKAGE)/test
my-distcheck: $(local-check)
	-rm -rf $(t)
	mkdir -p $(t)
	GZIP=$(GZIP_ENV) $(AMTAR) -C $(t) -zxf $(distdir).tar.gz
	cd $(t)/$(distdir)				\
	  && ./configure --disable-nls			\
	  && $(MAKE) CFLAGS='-Werror -Wall -Wformat -Wshadow' \
	      AM_MAKEFLAGS='$(null_AM_MAKEFLAGS)'	\
(Continue reading)

Albert Chin | 1 Sep 2005 11:43

Re: socklen_t

On Wed, Aug 31, 2005 at 04:18:20PM +0200, Simon Josefsson wrote:
> +AC_DEFUN([gl_SOCKLEN_T],
> +[
> +  AC_CHECK_HEADERS_ONCE(sys/types.h sys/socket.h netdb.h)
> +  AC_CHECK_TYPE([socklen_t],, [AC_DEFINE([socklen_t], [int],
> +                [Map `socklen_t' to `int' if it is missing.])], [
> +#ifdef HAVE_SYS_TYPES_H
> +# include <sys/types.h>
> +#endif
> +#ifdef HAVE_SYS_SOCKET_H
> +# include <sys/socket.h>
> +#endif
> +#ifdef HAVE_NETDB_H
> +# include <netdb.h>
> +#endif])
> +])

We created the following macro for curl. It's been tested on the
following systems:
  AIX 4.3.3, 5.1, 5.2, 5.3
  HP-UX 10.20, 11.00, 11i
  IRIX 6.5
  Redhat Linux 7.1, 9
  RHEL 2.1, 3, 4
  Solaris 2.5.1, 2.6, 7, 8, 9, 10/SPARC
  Tru64 UNIX 4.0D, 5.1

dnl Check for socklen_t: historically on BSD it is an int, and in
dnl POSIX 1g it is a type of its own, but some platforms use different
dnl types for the argument to getsockopt, getpeername, etc.  So we
(Continue reading)

Jim Meyering | 1 Sep 2005 10:55
Gravatar

Re: const-correctness fixes for regex

Paul Eggert <eggert <at> CS.UCLA.EDU> wrote:
> Jim Meyering <jim <at> meyering.net> writes:
>> A week or so ago, I stumbled across one interface that was missing a
>> `const' attribute on a parameter, then dug up a few more.  Paul, let me
>> know when you reach a point at which my checking this in won't interfere.
>
> It's easier for me if I just get it off the plate and install it now.
> I installed this into gnulib and filed glibc bug 1282.  Thanks.

Thanks for doing that!

> I wish missing-const-detection could be done automatically.

Same here.
Simon Josefsson | 1 Sep 2005 12:06

Re: socklen_t

Bruno Haible <bruno <at> clisp.org> writes:

> Normally <sys/types.h> and <sys/socket.h> should be sufficient to get
> socklen_t. Which are the systems where it needs <netdb.h>?

I don't know; POSIX says both sys/socket.h and netdb.h should declare
socklen_t, I was thinking of the case where a system doesn't have
sys/socket.h but has netdb.h.  Do you think we should only test for it
in sys/types.h + sys/socket.h?

There is a problem, of course, if it _is_ defined in netdb.h and the
application include that header file, but the test does not look
there.  Then there will be a type conflict.

Perhaps the M4 macro should create a socklen.h that include the proper
header files that is required to get the socklen_t type?  That would
be the most flexible, I think.  But it has the disadvantage that
applications need to include socklen.h, instead of simply using
socklen_t directly without worrying.

Thanks,
Simon
Simon Josefsson | 1 Sep 2005 12:15

Re: gnulib-tool changes

Bruno Haible <bruno <at> clisp.org> writes:

> Simon Josefsson wrote:
>> Yay!  I considered dropping use of gnulib in libgnutls yesterday,
>> because I wanted the error module for the tools, but that module need
>> a program_name variable.  When the library didn't provide one, there
>> were linker failures.  I added a dummy 'char *program_name = "gnutls"'
>> inside the library now, but it is not a clean solution.
>
> The solution that you can already apply today is to use two different
> invocations of gnulib-tool in different subdirectories of your package
> (so that they don't collide on the filesystem), with different
> configure.ac-s. With --macro-prefix you can cover both by the same
> configure.ac.

Yup, I'm using two configure.ac's in gsasl, but I don't want to change
gnutls to use the same scheme for only this reason.  And with your
work, I don't have to.

> The ChangeLogs can be disabled through --no-changelog. The backup files
> cannot be disabled. But you can remove them on your own afterwards.

Excellent!

>> > 1) Changed command-line invocation conventions:
>> >      "gnulib-tool --import abc"
>> >    followed by
>> >      "gnulib-tool --import def"
>> >    is equivalent to
>> >      "gnulib-tool --import abc def".
(Continue reading)

Bruno Haible | 1 Sep 2005 12:51

Re: socklen_t

Simon Josefsson wrote:
> POSIX says both sys/socket.h and netdb.h should declare
> socklen_t, I was thinking of the case where a system doesn't have
> sys/socket.h but has netdb.h.

Yes, this is the case that can cause trouble. Some very old systems fall in
this category.

> Do you think we should only test for it in sys/types.h + sys/socket.h?

Yes.

> There is a problem, of course, if it _is_ defined in netdb.h and the
> application include that header file, but the test does not look
> there.  Then there will be a type conflict.

We need to somehow avoid the type conflict in that case. The goal should
be that
  #include "config.h"
  #include <sys/types.h>
  #include <sys/socket.h>
defines socklen_t.

Like we do with EILSEQ: There are some systems which define it in <wchar.h>
but not in <errno.h>. So we needed to somehow transport the definition from
<wchar.h> to config.h, so that
  #include "config.h"
  #include <errno.h>
is sufficient to define EILSEQ.

(Continue reading)

Yoann Vandoorselaere | 1 Sep 2005 12:28
Favicon

wctype.h and wchar.h inclusion

Hi,

An OpenBSD Prelude user reported that GnuLib will fail to compile on
OpenBSD 3.7 due to the new dependencies of modules like strcase on
wctype.h and wchar.h headers. 

These headers are apparently not available on OpenBSD base system.
libutf8 provide these header, but they get installed in an 'utf8'
sub-directory and thus won't be found unless the user modify the
inclusion path. 

Would it be possible to revert to non multibyte module when these
headers are not available ?

Regards,

--

-- 
Yoann Vandoorselaere | Responsable R&D / CTO | PreludeIDS Technologies
Tel: +33 (0)8 70 70 21 58                  Fax: +33(0)4 78 42 21 58
http://www.prelude-ids.com

Gmane