[Top][All Lists]

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

Re: fix the sscanf usage in etags

From: Jan Djärv
Subject: Re: fix the sscanf usage in etags
Date: Wed, 09 Aug 2006 08:57:15 +0200
User-agent: Thunderbird (X11/20060614)

Kevin Ryde skrev:
Masatake YAMATO <address@hidden> writes:
-         if (sscanf (lbp->buffer, "#line %d \"%n", &lno, &start) == 1)
+         if (sscanf (lbp->buffer, "#line %d \"%n", &lno, &start) == 2)

I think that's wrong, I believe %n is not included in the return
count.  Eg. in the current glibc, and in the posix spec (under "n"),


The man page on GNU/Linux says:
              The C standard says: "Execution of  a  %n  directive
              does  not increment the assignment count returned at the comple-
              tion of execution" but the Corrigendum seems to contradict this.
              Probably it is wise not to make any assumptions on the effect of
              %n conversions on the return value.

So I guess we safely can test for >= 1 instead for those implementations that do return 2. I've checked in that change.

It does look like there's a problem with degenerate input having
"start" used uninitialized though.  Eg. say

        #line 00000000000000000000000000000

We can switch places between \" and %n and check for ":

          if (sscanf (lbp->buffer, "#line %d %n\"", &lno, &start) >= 1
              && lbp->buffer[start] == '"')
              char *endp = lbp->buffer + ++start;

        Jan D.

reply via email to

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