EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

2002  2003  2004  2005  2006  2007  2008  2009  <20102011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 2002  2003  2004  2005  2006  2007  2008  2009  <20102011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: RE: Bug in macLib
From: "Mark Rivers" <[email protected]>
To: "Eric Norum" <[email protected]>, "Andrew Johnson" <[email protected]>
Cc: Core-Talk <[email protected]>
Date: Wed, 31 Mar 2010 08:43:19 -0500
Hi Eric,

I may be missing something, but this code actually looks OK to me.  Note
that valend is a pointer, not a counter.  So if valend actually points
to the last character in the buffer then the statement

            if ( v <= valend ) *v   = '\0';

should be OK, right?

But it's certainly possible that valend has not been set correctly, and
that it is pointing to one character past the end of the buffer.  I have
not looked into that.

Mark

-----Original Message-----
From: Eric Norum [mailto:[email protected]] 
Sent: Tuesday, March 30, 2010 6:46 PM
To: Andrew Johnson
Cc: Mark Rivers; Core-Talk
Subject: Re: Bug in macLib

Hmm.....
Check the last 'if' statement in mcaCore.c: trans....

static void trans( MAC_HANDLE *handle, MAC_ENTRY *entry, int level,
                   const char *term, const char **rawval, char **value,
                   char *valend )
{
    char quote;
    const char *r;
    char *v;
    int discard;
    int macRef;

    /* return immediately if raw value is NULL */
    if ( *rawval == NULL ) return;

    /* discard quotes and escapes if level is > 0 (i.e. if these aren't
       the user's quotes and escapes) */
    discard = ( level > 0 );

    /* debug output */
    if ( handle->debug & 2 )
        printf( "trans-> entry = %p, level = %d, maxlen = %u, discard =
%s, "
        "rawval = %s\n", entry, level, (unsigned int)(valend - *value),
discard ? "T" : "F", *rawval );

    /* initially not in quotes */
    quote = 0;

    /* scan characters until hit terminator or end of string */
    for ( r = *rawval, v = *value; strchr( term, *r ) == NULL; r++ ) {

        /* handle quoted characters (quotes are discarded if in name) */
        if ( quote ) {
            if ( *r == quote ) {
                quote = 0;
                if ( discard ) continue;
            }
        }
        else if ( *r == '"' || *r == '\'' ) {
            quote = *r;
            if ( discard ) continue;
        }

        /* macro reference if '$' followed by '(' or '{' */
        macRef = ( *r == '$' &&
                   *( r + 1 ) != '\0' &&
                   strchr( "({", *( r + 1 ) ) != NULL );

        /* macros are not expanded in single quotes */
        if ( macRef && quote != '\'' ) {
            /* Handle macro reference */
            refer ( handle, entry, level, &r, &v, valend );
        }

        else {
            /* handle escaped characters (escape is discarded if in
name) */
            if ( *r == '\\' && *( r + 1 ) != '\0' ) {
                if ( v < valend && !discard ) *v++ = '\\';
                if ( v < valend ) *v++ = *++r;
            }

            /* copy character to output */
            else {
                if ( v < valend ) *v++ = *r;
            }

            /* ensure string remains properly terminated */
            if ( v <= valend ) *v   = '\0';
        }
    }


-- 
Eric Norum
[email protected]






Replies:
Re: Bug in macLib Eric Norum
Re: Bug in macLib Eric Norum
References:
Bug in macLib Mark Rivers
Re: Bug in macLib Andrew Johnson
Re: Bug in macLib Eric Norum

Navigate by Date:
Prev: Re: Bug in macLib Eric Norum
Next: Re: Bug in macLib Eric Norum
Index: 2002  2003  2004  2005  2006  2007  2008  2009  <20102011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: Bug in macLib Eric Norum
Next: Re: Bug in macLib Eric Norum
Index: 2002  2003  2004  2005  2006  2007  2008  2009  <20102011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 02 Feb 2012 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·