bug-grep
[Top][All Lists]
Advanced

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

Re: [bug-grep] PARAMS, gnulib update and const


From: Paul Eggert
Subject: Re: [bug-grep] PARAMS, gnulib update and const
Date: Mon, 21 Mar 2005 23:58:34 -0800
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux)

Claudio Fontana <address@hidden> writes:

> Sorry, forgot to cc bug-grep.
> Here are my 2c again (Sorry Paul for the redundancy).
>
>> Can you give some sample violations in the GNU
>> grep source code?
>
> grep.c:552: warning: assignment discards qualifiers
>>From pointer target type
> search.c:178: warning: passing arg 1 of `wcrtomb'
> discards qualifiers from pointer target type

The first problem is easily fixed by adding "const" in a couple
of places, and using "buf" rather than "ibeg"; please see the
patch below.

The second problem is a symptom of a serious bug in search.c, that
could lead to a buffer overrun and undefined behavior.  The code
involved is pretty low-quality -- how did it end up in "grep"?

2005-03-21  Paul Eggert  <address@hidden>

        * src/grep.c (prline): Don't assign char const * to char *.

--- grep.c.~1.94.~      2005-02-26 07:20:00 -0800
+++ grep.c      2005-03-21 16:05:25 -0800
@@ -529,11 +529,11 @@ prline (char const *beg, char const *lim
       if(match_icase)
         {
           char *buf = (char*) xmalloc (lim - beg);
-         char *ibeg = buf;
-         char *ilim = ibeg + (lim - beg);
+         char const *ibeg = buf;
+         char const *ilim = ibeg + (lim - beg);
          int i;
          for (i = 0; i < lim - beg; i++)
-           ibeg[i] = tolower (beg[i]);
+           buf[i] = tolower (beg[i]);
 
          while ((match_offset = (*execute) (ibeg, lim - beg, &match_size, 1))
                 != (size_t) -1)




reply via email to

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