delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2012/03/27/03:38:25

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,TW_YM
X-Spam-Check-By: sourceware.org
MIME-Version: 1.0
In-Reply-To: <CAD+0NRCaKSvkoyuKgOdy6GUn98Y5Qmc++FAdyCtt41viVrS-Rw@mail.gmail.com>
References: <CAD+0NRCaKSvkoyuKgOdy6GUn98Y5Qmc++FAdyCtt41viVrS-Rw AT mail DOT gmail DOT com>
Date: Tue, 27 Mar 2012 09:37:54 +0200
Message-ID: <CAEhDDbApcdd7szQgjVmyCoKJkujTgAM7ytP-a0iyL1uJWnkN9g@mail.gmail.com>
Subject: Re: rcs 5.8-1 checks out wrong version of file when using similar mark symbols
From: Csaba Raduly <rcsaba AT gmail DOT com>
To: cygwin AT cygwin DOT com
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id q2R7cMUt010195

On Mon, Mar 26, 2012 at 9:29 PM, Richard Gribble  wrote:
> Using rcs 5.8-1:
>
> Synopsis:
>    Given two mark symbols, abc (version 1.1) and abcd (version 1.2),
>    executing "co -rabc <file>" will check out version 1.2, when it
>    should check out version 1.1.
>
> I set the mark symbols as follows:
>    rcs -nabc:1.1 -nabcd:1.2 <file>
>
>
> I dug into it, and found the following (rcsrev.c):
>
> 01:  static char const *
> 02:  rev_from_symbol (struct cbuf const *id)
> 03:  /* Look up "id" in the list of symbolic names starting with pointer
> 04:     "GROK (symbols)", and return a pointer to the corresponding
> 05:     revision number.  Return NULL if not present.  */
> 06:  {
> 07:    for (struct link *ls = GROK (symbols); ls; ls = ls->next)
> 08:      {
> 09:        struct symdef const *d = ls->entry;
> 10:
> 11:        if (!strncmp (d->meaningful, id->string, id->size))
> 12:          return d->underlying;
> 13:      }
> 14:    return NULL;
> 15:  }
>
> Note that line 11 tests the name of the requested mark symbol
> (id->string) against each element of a linked-list (ls) containing all
> the mark symbols for the file.  The problem is that it will only test
> the first 'id->size' characters - so R25 (from the command line) matches
> R25a (from the list) because the first three characters match and it
> won't test any more than that (strncmp).
>
> I recommend modifying line 11 as follows:
>    if ((strlen(d->meaningful) == strlen(id->size)) && !strncmp
> (d->meaningful, id->string, id->size))

I think strlen(id->size) is overkill :)

If both strings (d->meaningful and id->string) are NULL-terminated ,
then a simple call to strlen would do the job:

if (!strcmp(d->meaningful, id->string))

It would do the right thing w.r.t. different lengths.

> Of course, since you now know that the two strings are the same size,
> you could use strcmp - but that assumes that the && short-circuits, and
> I don't know if that's guaranteed.

Yes, it required by the C standard.

Csaba
-- 
GCS a+ e++ d- C++ ULS$ L+$ !E- W++ P+++$ w++$ tv+ b++ DI D++ 5++
The Tao of math: The numbers you can count are not the real numbers.
Life is complex, with real and imaginary parts.
"Ok, it boots. Which means it must be bug-free and perfect. " -- Linus Torvalds
"People disagree with me. I just ignore them." -- Linus Torvalds

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019