From fe55b04449645efeb25476ee8c56b033ee4b75e3 Mon Sep 17 00:00:00 2001 From: Marty Kraimer Date: Wed, 6 Aug 2003 17:52:50 +0000 Subject: [PATCH] macParseDefns did not check for handle==NULL. The documentation for macParseDefns was not correct. --- src/libCom/macCore.c | 4 ++-- src/libCom/macLib.h | 12 ++++++++++++ src/libCom/macLibREADME | 2 +- src/libCom/macUtil.c | 27 ++++++++++++++++----------- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/libCom/macCore.c b/src/libCom/macCore.c index 643057f6d..f1cc5a145 100644 --- a/src/libCom/macCore.c +++ b/src/libCom/macCore.c @@ -135,7 +135,7 @@ void epicsShareAPI macSuppressWarning( int falseTrue /*0 means issue, 1 means suppress*/ ) { - handle->suppressWarning = falseTrue; + if(handle) handle->suppressWarning = falseTrue; } /* @@ -753,7 +753,7 @@ static void trans( MAC_HANDLE *handle, MAC_ENTRY *entry, long level, /* * strdup() implementation (because it's not always available) */ -char *Strdup( char *string ) +static char *Strdup( char *string ) { char *copy = dbmfMalloc( strlen( string ) + 1 ); diff --git a/src/libCom/macLib.h b/src/libCom/macLib.h index fdf3ebec4..55cd8827a 100644 --- a/src/libCom/macLib.h +++ b/src/libCom/macLib.h @@ -14,6 +14,9 @@ * William Lupton, W. M. Keck Observatory */ +#ifndef INCmacLibH +#define INCmacLibH + /* * EPICS include files needed by this file */ @@ -22,6 +25,10 @@ #include "errMdef.h" #include "shareLib.h" +#ifdef __cplusplus +extern "C" { +#endif + /* * Standard FALSE and TRUE macros */ @@ -210,3 +217,8 @@ epicsShareAPI macInstallMacros( /* argument implies no macros */ ); +#ifdef __cplusplus +} +#endif + +#endif /*INCmacLibH*/ diff --git a/src/libCom/macLibREADME b/src/libCom/macLibREADME index ac0598539..ebd5ed5ec 100644 --- a/src/libCom/macLibREADME +++ b/src/libCom/macLibREADME @@ -191,7 +191,7 @@ h) Error handling These are convenience functions. If other useful functions emerge during implementation, the list may grow. -a) macParseDefns( char *defns, char **pairs[] ); +a) macParseDefns( MAC_HANDLE *handle, char *defns, char **pairs[] ); This takes a set of macro definitions in "a=xxx,b=yyy" format and converts them into an array of pointers to character strings which diff --git a/src/libCom/macUtil.c b/src/libCom/macUtil.c index 80b1b58e5..c8f3032d3 100644 --- a/src/libCom/macUtil.c +++ b/src/libCom/macUtil.c @@ -29,7 +29,7 @@ * and escapes are honored but only removed from macro names (not * values) * - * Doesn't yet use handle (so uses default special characters) + * Doesn't yet use special characters (so uses default special characters) */ long /* #defns encountered; <0 = ERROR */ epicsShareAPI macParseDefns( @@ -44,6 +44,8 @@ epicsShareAPI macParseDefns( /* value} pair strings; all storage is */ /* allocated contiguously */ { + static const size_t altNumMax = 4; + size_t numMax; long i; long num; long quote; @@ -57,14 +59,17 @@ epicsShareAPI macParseDefns( enum { preName, inName, preValue, inValue } state; /* debug output */ - if ( handle->debug & 1 ) + if ( handle && (handle->debug & 1) ) printf( "macParseDefns( %s )\n", defns ); /* allocate temporary pointer arrays; in worst case they need to have as many entries as the length of the defns string */ - ptr = ( char ** ) malloc( strlen( defns ) * sizeof( char * ) ); - end = ( char ** ) malloc( strlen( defns ) * sizeof( char * ) ); - del = ( long * ) malloc( strlen( defns ) * sizeof( long ) ); + numMax = strlen( defns ); + if ( numMax < altNumMax ) + numMax = altNumMax; + ptr = ( char ** ) malloc( numMax * sizeof( char * ) ); + end = ( char ** ) malloc( numMax * sizeof( char * ) ); + del = ( long * ) malloc( numMax * sizeof( long ) ); if ( ptr == NULL || end == NULL || del == NULL ) goto error; /* go through definitions, noting pointers to starts and ends of macro @@ -87,7 +92,7 @@ epicsShareAPI macParseDefns( switch ( state ) { case preName: - if ( !quote && !escape && ( isspace( *c ) || *c == ',' ) ) break; + if ( !quote && !escape && ( isspace( (int) *c ) || *c == ',' ) ) break; ptr[num] = c; state = inName; /* fall through (may be empty name) */ @@ -95,7 +100,7 @@ epicsShareAPI macParseDefns( case inName: if ( quote || escape || ( *c != '=' && *c != ',' ) ) break; end[num] = c; - while ( end[num] > ptr[num] && isspace( *( end[num] - 1 ) ) ) + while ( end[num] > ptr[num] && isspace( (int) *( end[num] - 1 ) ) ) end[num]--; num++; del[num] = FALSE; @@ -105,7 +110,7 @@ epicsShareAPI macParseDefns( /* fall through (','; will delete) */ case preValue: - if ( !quote && !escape && isspace( *c ) ) break; + if ( !quote && !escape && isspace( (int) *c ) ) break; ptr[num] = c; state = inValue; /* fall through (may be empty value) */ @@ -113,7 +118,7 @@ epicsShareAPI macParseDefns( case inValue: if ( quote || escape || *c != ',' ) break; end[num] = c; - while ( end[num] > ptr[num] && isspace( *( end[num] - 1 ) ) ) + while ( end[num] > ptr[num] && isspace( (int) *( end[num] - 1 ) ) ) end[num]--; num++; del[num] = FALSE; @@ -133,7 +138,7 @@ epicsShareAPI macParseDefns( break; case inName: end[num] = c; - while ( end[num] > ptr[num] && isspace( *( end[num] - 1 ) ) ) + while ( end[num] > ptr[num] && isspace( (int) *( end[num] - 1 ) ) ) end[num]--; num++; del[num] = TRUE; @@ -141,7 +146,7 @@ epicsShareAPI macParseDefns( ptr[num] = c; case inValue: end[num] = c; - while ( end[num] > ptr[num] && isspace( *( end[num] - 1 ) ) ) + while ( end[num] > ptr[num] && isspace( (int) *( end[num] - 1 ) ) ) end[num]--; num++; del[num] = FALSE;