<<< Date Index >>>     <<< Thread Index >>>

Re: [PATCH] warning cleared



On 2005-09-22 09:50:22 -0500, David Champion wrote:
> * On 2005.09.22, in <20050922075205.GU10503@xxxxxxxxxxxxx>,
> *     "Vincent Lefevre" <vincent@xxxxxxxxxx> wrote:
> > 
> > You need
> > 
> >   #include <stdlib.h>
> 
> No, you don't, because strtoul() doesn't exist, so no header file
> defines its interface.  Including a header doesn't make a symbol
> available at link time.  (At link time, it's either there or it isn't.)
> It just helps the compiler check grammar, and the grammer checked fine.

The #include is needed; see the C standard. The compiler can have
some internal mechanism to change how the code is compiled according
to whether the header is included or not (e.g. the symbol name
corresponding to the function call may be changed when the header is
included).

> > Moreover, perhaps linking
> > with some library, such as -lansi (as suggested on the web),
> > is needed.
> 
> There is no libansi on stock SunOS4.  There is no _strtoul in
> /usr/lib/lib*.a on stock SunOS4.

http://www.math.utah.edu/~beebe/sp-notes-1.0.1.html was suggesting
-lansi on SunOS 4.1.3 (at the end of the page).

But on SunOS, not all libraries are in /usr/lib. On this page,
-L/usr/lang/SC1.0/ansi_lib has been added (but this may be another
path on your machine).

After a look on Google, it seems that other users managed to get
and use this library on their SunOS4 machine. I don't think that
any software should be prevented from using some standard function
because a particular machine does not have a correct installation.

> Sure, but then you need either to fail configure and say "get yourself
> a strtoul() implementation", or you need a backup implementation
> encased within "#ifdef NEED_STRTOUL" or something.  Why add this extra
> weight when an alternate solution is just to use atoi() and while

atoi is not safe.

> (isdigit((foo)*p)) p++?  This basically is equivalent to inlining
> your specially-defined my_strtoul(), but additionally applying it to
> all platforms instead of just SunOS, meaning you don't need to have
> confidence in a strtoul check, you don't have extra code to maintain,
> and you don't do any harm.
> 
> I agree, using strtoul() is best if you're writing code for modern
> platforms. Mutt aims for portability to non-modern platforms, and I
> try to support that so that Steve doesn't need to file a bug report
> after commit. :)
> 
> I'll take Thomas Dickey's word that strtol() is reliably present -- I

According to <http://dora.eeap.cwru.edu/login/ssh_install_notes.html>:

  NOTE: had to change the strtoul fuunction call in pcretest.c to
  strtol because SunOS 4.1.3 doesn`t have a strtoul.

> wasn't sure how broadly-implemented it is, having seen strtoul() missing
> so often.  Every platform I've used has strtol(), as far as I recall,
> but I haven't seen everything.  So Vincent, if you want to submit a
> patch to use strtol(), I won't argue it.

Untested patch attached. I'm not sure what to do in case of error.
Here %0 is accepted, and %<n> is ignored if <n> is negative or too
large. % with no following number is equivalent to %0.

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / SPACES project at LORIA
Index: muttlib.c
===================================================================
RCS file: /home/roessler/cvs/mutt/muttlib.c,v
retrieving revision 3.38
diff -d -u -r3.38 muttlib.c
--- muttlib.c   20 Sep 2005 23:41:21 -0000      3.38
+++ muttlib.c   22 Sep 2005 23:35:04 -0000
@@ -1560,8 +1560,9 @@
 {
   static regmatch_t *pmatch = NULL;
   static int nmatch = 0;
-  int i, n, tlen;
-  char *p;
+  int i, tlen;
+  long n;
+  char *p, *end;
 
   if (!s)  return 0;
 
@@ -1587,11 +1588,13 @@
       {
        if (*p == '%')
        {
-         n = atoi(++p);                        /* find pmatch index */
-         while (isdigit((unsigned char)*p))
-           ++p;                                /* skip subst token */
-         for (i = pmatch[n].rm_so; (i < pmatch[n].rm_eo) && (tlen < x); i++)
-           text[tlen++] = s[i];
+         n = strtol(p+1, &end, 10);            /* find pmatch index */
+         p = end;
+         if (n >= 0 && n < nmatch)
+         {
+           for (i = pmatch[n].rm_so; (i < pmatch[n].rm_eo) && (tlen < x); i++)
+             text[tlen++] = s[i];
+         }
        }
        else
        {