Hi,

The grep-2.5.4-20090122 snapshot on alpha.gnu.org exhibits the following 
warnings,
when compiled with CPPFLAGS=-Wall on a Linux/x86 system.

$ ./configure CPPFLAGS=-Wall
$ make
...
savedir.c: In function ‘isdir1’:
savedir.c:91: warning: implicit declaration of function ‘isdir’

Suggestion: Add a declaration of the isdir function.

...
grep.c: In function ‘parse_grep_colors’:
grep.c:1709: warning: suggest explicit braces to avoid ambiguous ‘else’

Suggestion: Add braces.

...
In file included from ../lib/regex.h:2,
                 from search.c:37:
../lib/posix/regex.h:536:1: warning: "__restrict_arr" redefined
In file included from /usr/include/features.h:330,
                 from /usr/include/sys/types.h:27,
                 from search.c:25:
/usr/include/sys/cdefs.h:334:1: warning: this is the location of the previous 
definition

Suggestion: Use the same logic for restrict and restrict_arr as in 
gnulib/lib/regex.h.

...
search.c: In function ‘check_multibyte_string’:
search.c:169: warning: passing argument 1 of ‘wcrtomb’ discards qualifiers from 
pointer target type

Suggestion: Fix that code. It is completely broken: It assumes that for a pair
of upper-case and lower-case wide characters, the multibyte representation of 
the
two characters has the same length. This is not true in Turkish tr_TR.UTF-8 
locales
for the characters 'İ' and 'i'.

...
kwset.c: In function ‘kwsalloc’:
kwset.c:96: warning: call to function ‘xmalloc’ without a real prototype
kwset.c:40: note: ‘xmalloc’ was declared here

Suggestion: Change kwset.c:40 to
  #include "xalloc.h"

...
dfa.c: In function ‘update_mb_len_index’:
dfa.c:430: warning: pointer targets in passing argument 1 of ‘mbrlen’ differ in 
signedness
dfa.c: In function ‘lex’:
dfa.c:774: warning: pointer targets in passing argument 1 of 
‘update_mb_len_index’ differ in signedness
dfa.c:922: warning: pointer targets in passing argument 1 of 
‘update_mb_len_index’ differ in signedness
dfa.c:928: warning: pointer targets in passing argument 1 of 
‘update_mb_len_index’ differ in signedness
dfa.c:938: warning: pointer targets in passing argument 1 of 
‘update_mb_len_index’ differ in signedness
dfa.c:946: warning: pointer targets in passing argument 1 of 
‘update_mb_len_index’ differ in signedness
dfa.c:961: warning: pointer targets in passing argument 1 of 
‘update_mb_len_index’ differ in signedness
dfa.c:1049: warning: pointer targets in passing argument 1 of 
‘update_mb_len_index’ differ in signedness
dfa.c:1052: warning: pointer targets in passing argument 1 of 
‘update_mb_len_index’ differ in signedness
dfa.c:1076: warning: pointer targets in passing argument 1 of 
‘update_mb_len_index’ differ in signedness
dfa.c:1080: warning: pointer targets in passing argument 1 of 
‘update_mb_len_index’ differ in signedness
dfa.c:1081: warning: pointer targets in passing argument 1 of 
‘update_mb_len_index’ differ in signedness
dfa.c:1084: warning: pointer targets in passing argument 1 of 
‘update_mb_len_index’ differ in signedness
dfa.c:1096: warning: pointer targets in passing argument 1 of 
‘update_mb_len_index’ differ in signedness
dfa.c:1097: warning: pointer targets in passing argument 1 of 
‘update_mb_len_index’ differ in signedness

Suggestion: Change the first argument type of update_mb_len_index to 'char 
const *'.

dfa.c: In function ‘match_mb_charset’:
dfa.c:2561: warning: pointer targets in passing argument 2 of 
‘__builtin_strncpy’ differ in signedness

Suggestion: Change the second argument of strncpy, adding a cast.

dfa.c:2568: warning: pointer targets in passing argument 2 of 
‘__builtin_strncpy’ differ in signedness

Likewise.

dfa.c:2581: warning: pointer targets in passing argument 2 of 
‘__builtin_strncpy’ differ in signedness

Likewise.

dfa.c: In function ‘dfaexec’:
dfa.c:2834: warning: pointer targets in assignment differ in signedness
...

Suggestion: add a cast.


Find attached a patch that solves all the warnings except for the broken
check_multibyte_string.

Bruno

2009-01-23  Bruno Haible  <[email protected]>

	* lib/posix/regex.h (__restrict, __restrict_arr): Remove macros.
	(_Restrict_, _Restrict_arr_): New macros. From gnulib/lib/regex.h.
	(regcomp, regexec): Update declarations to use them.

	* lib/savedir.c (isdir): New declaration.

	* src/dfa.c (update_mb_len_index): Change argument type to
	'char const *'.
	(match_mb_charset): Cast argument to strncpy.
	(dfaexec): Add pointer cast.

	* src/grep.c (parse_grep_colors): Add braces for disambiguation.

	* src/kwset.c: Include xalloc.h instead of declaring xmalloc manually.

diff -r -c3 grep-2.5.4-20090122.bak/lib/posix/regex.h grep-2.5.4-20090122/lib/posix/regex.h
*** grep-2.5.4-20090122.bak/lib/posix/regex.h	2007-06-28 21:10:45.000000000 +0200
--- grep-2.5.4-20090122/lib/posix/regex.h	2009-01-23 11:38:42.000000000 +0100
***************
*** 1,6 ****
  /* Definitions for data structures and routines for the regular
     expression library, version 0.12.
!    Copyright (C) 1985,1989-1993,1995-1998, 2000 Free Software Foundation, Inc.
  
     This file is part of the GNU C Library.  Its master source is NOT part of
     the C library, however.  The master source lives in /gd/gnu/lib.
--- 1,7 ----
  /* Definitions for data structures and routines for the regular
     expression library, version 0.12.
!    Copyright (C) 1985,1989-1993,1995-1998, 2000, 2006, 2007, 2009
!    Free Software Foundation, Inc.
  
     This file is part of the GNU C Library.  Its master source is NOT part of
     the C library, however.  The master source lives in /gd/gnu/lib.
***************
*** 520,548 ****
  #endif
  
  /* GCC 2.95 and later have "__restrict"; C99 compilers have
!    "restrict", and "configure" may have defined "restrict".  */
! #ifndef __restrict
! # if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__))
! #  if defined restrict || 199901L <= __STDC_VERSION__
! #   define __restrict restrict
! #  else
! #   define __restrict
! #  endif
  # endif
  #endif
- /* For now unconditionally define __restrict_arr to expand to nothing.
-    Ideally we would have a test for the compiler which allows defining
-    it to restrict.  */
- #define __restrict_arr
  
  /* POSIX compatibility.  */
! extern int regcomp _RE_ARGS ((regex_t *__restrict __preg,
! 			      const char *__restrict __pattern,
  			      int __cflags));
  
! extern int regexec _RE_ARGS ((const regex_t *__restrict __preg,
! 			      const char *__restrict __string, size_t __nmatch,
! 			      regmatch_t __pmatch[__restrict_arr],
  			      int __eflags));
  
  extern size_t regerror _RE_ARGS ((int __errcode, const regex_t *__preg,
--- 521,561 ----
  #endif
  
  /* GCC 2.95 and later have "__restrict"; C99 compilers have
!    "restrict", and "configure" may have defined "restrict".
!    Other compilers use __restrict, __restrict__, and _Restrict, and
!    'configure' might #define 'restrict' to those words, so pick a
!    different name.  */
! #ifndef _Restrict_
! # if 199901L <= __STDC_VERSION__
! #  define _Restrict_ restrict
! # elif 2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)
! #  define _Restrict_ __restrict
! # else
! #  define _Restrict_
! # endif
! #endif
! /* gcc 3.1 and up support the [restrict] syntax.  Don't trust
!    sys/cdefs.h's definition of __restrict_arr, though, as it
!    mishandles gcc -ansi -pedantic.  */
! #ifndef _Restrict_arr_
! # if ((199901L <= __STDC_VERSION__					\
!        || ((3 < __GNUC__ || (3 == __GNUC__ && 1 <= __GNUC_MINOR__))	\
! 	   && !__STRICT_ANSI__))					\
!       && !defined __GNUG__)
! #  define _Restrict_arr_ _Restrict_
! # else
! #  define _Restrict_arr_
  # endif
  #endif
  
  /* POSIX compatibility.  */
! extern int regcomp _RE_ARGS ((regex_t *_Restrict_ __preg,
! 			      const char *_Restrict_ __pattern,
  			      int __cflags));
  
! extern int regexec _RE_ARGS ((const regex_t *_Restrict_ __preg,
! 			      const char *_Restrict_ __string, size_t __nmatch,
! 			      regmatch_t __pmatch[_Restrict_arr_],
  			      int __eflags));
  
  extern size_t regerror _RE_ARGS ((int __errcode, const regex_t *__preg,
diff -r -c3 grep-2.5.4-20090122.bak/lib/savedir.c grep-2.5.4-20090122/lib/savedir.c
*** grep-2.5.4-20090122.bak/lib/savedir.c	2007-06-28 21:10:45.000000000 +0200
--- grep-2.5.4-20090122/lib/savedir.c	2009-01-23 11:28:49.000000000 +0100
***************
*** 1,5 ****
  /* savedir.c -- save the list of files in a directory in a string
!    Copyright (C) 1990, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
  
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
--- 1,5 ----
  /* savedir.c -- save the list of files in a directory in a string
!    Copyright (C) 1990, 1997, 1998, 1999, 2000, 2001, 2009 Free Software Foundation, Inc.
  
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
***************
*** 69,74 ****
--- 69,76 ----
  #include <fnmatch.h>
  #include "savedir.h"
  
+ extern int isdir (const char *path);
+ 
  char *path;
  size_t pathlen;
  
diff -r -c3 grep-2.5.4-20090122.bak/src/dfa.c grep-2.5.4-20090122/src/dfa.c
*** grep-2.5.4-20090122.bak/src/dfa.c	2008-02-10 04:16:10.000000000 +0100
--- grep-2.5.4-20090122/src/dfa.c	2009-01-23 11:35:22.000000000 +0100
***************
*** 1,5 ****
  /* dfa.c - deterministic extended regexp routines for GNU
!    Copyright 1988, 1998, 2000, 2002, 2004, 2008
     Free Software Foundation, Inc.
  
     This program is free software; you can redistribute it and/or modify
--- 1,5 ----
  /* dfa.c - deterministic extended regexp routines for GNU
!    Copyright 1988, 1998, 2000, 2002, 2004, 2008, 2009
     Free Software Foundation, Inc.
  
     This program is free software; you can redistribute it and/or modify
***************
*** 414,420 ****
  /* This function update cur_mb_len, and cur_mb_index.
     p points current lexptr, len is the remaining buffer length.  */
  static void
! update_mb_len_index (unsigned char const *p, int len)
  {
    /* If last character is a part of a multibyte character,
       we update cur_mb_index.  */
--- 414,420 ----
  /* This function update cur_mb_len, and cur_mb_index.
     p points current lexptr, len is the remaining buffer length.  */
  static void
! update_mb_len_index (char const *p, int len)
  {
    /* If last character is a part of a multibyte character,
       we update cur_mb_index.  */
***************
*** 2558,2571 ****
  	goto charset_matched;
      }
  
!   strncpy(buffer, buf_begin + index, match_len);
    buffer[match_len] = '\0';
  
    /* match with an equivalent class?  */
    for (i = 0; i<work_mbc->nequivs; i++)
      {
        op_len = strlen(work_mbc->equivs[i]);
!       strncpy(buffer, buf_begin + index, op_len);
        buffer[op_len] = '\0';
        if (strcoll(work_mbc->equivs[i], buffer) == 0)
  	{
--- 2558,2571 ----
  	goto charset_matched;
      }
  
!   strncpy(buffer, (char const *) (buf_begin + index), match_len);
    buffer[match_len] = '\0';
  
    /* match with an equivalent class?  */
    for (i = 0; i<work_mbc->nequivs; i++)
      {
        op_len = strlen(work_mbc->equivs[i]);
!       strncpy(buffer, (char const *) (buf_begin + index), op_len);
        buffer[op_len] = '\0';
        if (strcoll(work_mbc->equivs[i], buffer) == 0)
  	{
***************
*** 2578,2584 ****
    for (i = 0; i<work_mbc->ncoll_elems; i++)
      {
        op_len = strlen(work_mbc->coll_elems[i]);
!       strncpy(buffer, buf_begin + index, op_len);
        buffer[op_len] = '\0';
  
        if (strcoll(work_mbc->coll_elems[i], buffer) == 0)
--- 2578,2584 ----
    for (i = 0; i<work_mbc->ncoll_elems; i++)
      {
        op_len = strlen(work_mbc->coll_elems[i]);
!       strncpy(buffer, (char const *) (buf_begin + index), op_len);
        buffer[op_len] = '\0';
  
        if (strcoll(work_mbc->coll_elems[i], buffer) == 0)
***************
*** 2831,2837 ****
    if (MB_CUR_MAX > 1)
      {
        int remain_bytes, i;
!       buf_begin = begin;
        buf_end = end;
  
        /* initialize mblen_buf, and inputwcs.  */
--- 2831,2837 ----
    if (MB_CUR_MAX > 1)
      {
        int remain_bytes, i;
!       buf_begin = (unsigned char const *) begin;
        buf_end = end;
  
        /* initialize mblen_buf, and inputwcs.  */
diff -r -c3 grep-2.5.4-20090122.bak/src/grep.c grep-2.5.4-20090122/src/grep.c
*** grep-2.5.4-20090122.bak/src/grep.c	2009-01-21 04:06:27.000000000 +0100
--- grep-2.5.4-20090122/src/grep.c	2009-01-23 11:30:05.000000000 +0100
***************
*** 1707,1724 ****
  	    break;
  	/* If name unknown, go on for forward compatibility.  */
  	if (cap->name)
! 	  if (cap->var)
! 	    {
! 	      if (val)
! 		*(cap->var) = val;
! 	      else
! 		error(0, 0, _("In GREP_COLORS=\"%s\", the \"%s\" capacity "
! 			      "needs a value (\"=...\"); skipped."), p, name);
! 	    }
! 	  else if (val)
! 	    error(0, 0, _("In GREP_COLORS=\"%s\", the \"%s\" capacity "
! 			  "is boolean and cannot take a value (\"=%s\"); "
! 			  "skipped."), p, name, val);
  	if (cap->fct)
  	  {
  	    const char *err_str = cap->fct();
--- 1707,1727 ----
  	    break;
  	/* If name unknown, go on for forward compatibility.  */
  	if (cap->name)
! 	  {
! 	    if (cap->var)
! 	      {
! 		if (val)
! 		  *(cap->var) = val;
! 		else
! 		  error(0, 0, _("In GREP_COLORS=\"%s\", the \"%s\" capacity "
! 				"needs a value (\"=...\"); skipped."),
! 			p, name);
! 	      }
! 	    else if (val)
! 	      error(0, 0, _("In GREP_COLORS=\"%s\", the \"%s\" capacity "
! 			    "is boolean and cannot take a value (\"=%s\"); "
! 			    "skipped."), p, name, val);
! 	  }
  	if (cap->fct)
  	  {
  	    const char *err_str = cap->fct();
diff -r -c3 grep-2.5.4-20090122.bak/src/kwset.c grep-2.5.4-20090122/src/kwset.c
*** grep-2.5.4-20090122.bak/src/kwset.c	2007-06-28 21:10:46.000000000 +0200
--- grep-2.5.4-20090122/src/kwset.c	2009-01-23 11:33:03.000000000 +0100
***************
*** 1,5 ****
  /* kwset.c - search for any of a set of keywords.
!    Copyright 1989, 1998, 2000, 2005 Free Software Foundation, Inc.
  
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
--- 1,5 ----
  /* kwset.c - search for any of a set of keywords.
!    Copyright 1989, 1998, 2000, 2005, 2009 Free Software Foundation, Inc.
  
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
***************
*** 37,43 ****
  #include "obstack.h"
  
  #ifdef GREP
! extern char *xmalloc();
  # undef malloc
  # define malloc xmalloc
  #endif
--- 37,43 ----
  #include "obstack.h"
  
  #ifdef GREP
! # include "xalloc.h"
  # undef malloc
  # define malloc xmalloc
  #endif

Reply via email to