From 0dc034962ccae79fd7fdcfddead52496c837014a Mon Sep 17 00:00:00 2001 From: "W. Eric Norum" Date: Tue, 12 Oct 2004 17:45:31 +0000 Subject: [PATCH] Use epicsScanFloat/epicsScanDouble rather than sscanf. This allows proper handling of Nan/Inf on all architectures. --- src/ca/caConnTestMain.cpp | 4 ++-- src/catools/caget.c | 4 ++-- src/catools/cainfo.c | 4 ++-- src/catools/camonitor.c | 4 ++-- src/catools/caput.c | 2 +- src/db/dbConvert.c | 26 +++++++++++++------------- src/db/dbFastLinkConv.c | 8 ++++---- src/db/dbScan.c | 4 ++-- src/db/dbTest.c | 6 +++--- src/db/db_test.c | 6 +++--- src/db/recGbl.c | 6 +++--- src/dbStatic/dbLexRoutines.c | 4 ++-- src/gdd/aitConvert.cc | 6 +++--- src/libCom/calc/postfix.c | 4 ++-- src/libCom/env/envSubr.c | 4 ++-- src/libCom/misc/epicsScanReal.c | 4 ++-- src/libCom/misc/epicsStdlib.h | 4 ++-- src/util/ca_test.c | 5 +++-- 18 files changed, 53 insertions(+), 52 deletions(-) diff --git a/src/ca/caConnTestMain.cpp b/src/ca/caConnTestMain.cpp index 45e24dd48..f3985801a 100644 --- a/src/ca/caConnTestMain.cpp +++ b/src/ca/caConnTestMain.cpp @@ -9,7 +9,7 @@ \*************************************************************************/ #include -#include +#include #include "caDiagnostics.h" @@ -32,7 +32,7 @@ int main ( int argc, char **argv ) } if ( argc >= 4 ) { - int nConverted = sscanf ( argv[3], "%lf", &delay ); + int nConverted = epicsScanDouble( argv[3], &delay ); if ( nConverted != 1 ) { printf ( "conversion failed, changing delay arg \"%s\" to %f\n", argv[2], delay ); diff --git a/src/catools/caget.c b/src/catools/caget.c index a99a0503f..2b7f1116c 100644 --- a/src/catools/caget.c +++ b/src/catools/caget.c @@ -17,7 +17,7 @@ */ #include -#include +#include #include #include @@ -358,7 +358,7 @@ int main (int argc, char *argv[]) enumAsNr=1; break; case 'w': /* Set CA timeout value */ - if(sscanf(optarg,"%lf", &caTimeout) != 1) + if(epicsScanDouble(optarg, &caTimeout) != 1) { fprintf(stderr, "'%s' is not a valid timeout value " "- ignored. ('caget -h' for help.)\n", optarg); diff --git a/src/catools/cainfo.c b/src/catools/cainfo.c index 95ccf5091..3fb6fa822 100644 --- a/src/catools/cainfo.c +++ b/src/catools/cainfo.c @@ -17,7 +17,7 @@ */ #include -#include +#include #include #include @@ -136,7 +136,7 @@ int main (int argc, char *argv[]) usage(); return 0; case 'w': /* Set CA timeout value */ - if(sscanf(optarg,"%lf", &caTimeout) != 1) + if(epicsScanDouble(optarg, &caTimeout) != 1) { fprintf(stderr, "'%s' is not a valid timeout value " "- ignored. ('caget -h' for help.)\n", optarg); diff --git a/src/catools/camonitor.c b/src/catools/camonitor.c index b068915e6..cd6ee7137 100644 --- a/src/catools/camonitor.c +++ b/src/catools/camonitor.c @@ -17,7 +17,7 @@ */ #include -#include +#include #include #include @@ -205,7 +205,7 @@ int main (int argc, char *argv[]) tsType = incrementalByChan; break; case 'w': /* Set CA timeout value */ - if(sscanf(optarg,"%lf", &caTimeout) != 1) + if(epicsScanDouble(optarg, &caTimeout) != 1) { fprintf(stderr, "'%s' is not a valid timeout value " "- ignored. ('caget -h' for help.)\n", optarg); diff --git a/src/catools/caput.c b/src/catools/caput.c index e4eed9598..17223a19e 100644 --- a/src/catools/caput.c +++ b/src/catools/caput.c @@ -230,7 +230,7 @@ int main (int argc, char *argv[]) isArray = 1; break; case 'w': /* Set CA timeout value */ - if(sscanf(optarg,"%lf", &caTimeout) != 1) + if(epicsScanDouble(optarg, &caTimeout) != 1) { fprintf(stderr, "'%s' is not a valid timeout value " "- ignored. ('caput -h' for help.)\n", optarg); diff --git a/src/db/dbConvert.c b/src/db/dbConvert.c index 99170dad8..ef0e23715 100644 --- a/src/db/dbConvert.c +++ b/src/db/dbConvert.c @@ -15,7 +15,7 @@ */ #include -#include +#include #include #include #include @@ -266,7 +266,7 @@ static long getStringUlong( /*Convert to double first so that numbers like 1.0e3 convert properly*/ /*Problem was old database access said to get unsigned long as double*/ if(nRequest==1 && offset==0) { - if(sscanf(psrc,"%lf",&value) == 1) { + if(epicsScanDouble(psrc, &value) == 1) { *pbuffer = (epicsUInt32)value; return(0); } else if(strlen(psrc) == 0) { @@ -278,7 +278,7 @@ static long getStringUlong( } psrc += MAX_STRING_SIZE*offset; while (nRequest) { - if(sscanf(psrc,"%lf",&value) == 1) { + if(epicsScanDouble(psrc, &value) == 1) { *pbuffer = (epicsUInt32)value; } else if(strlen(psrc) == 0) { *pbuffer = 0; @@ -303,7 +303,7 @@ static long getStringFloat( float value; if(nRequest==1 && offset==0) { - if(sscanf(psrc,"%f",&value) == 1) { + if(epicsScanFloat(psrc, &value) == 1) { *pbuffer = value; return(0); } else if(strlen(psrc) == 0) { @@ -315,7 +315,7 @@ static long getStringFloat( } psrc += MAX_STRING_SIZE*offset; while (nRequest) { - if(sscanf(psrc,"%f",&value) == 1) { + if(epicsScanFloat(psrc, &value) == 1) { *pbuffer = value; } else if(strlen(psrc) == 0) { *pbuffer = 0.0; @@ -340,7 +340,7 @@ static long getStringDouble( double value; if(nRequest==1 && offset==0) { - if(sscanf(psrc,"%lf",&value) == 1) { + if(epicsScanDouble(psrc, &value) == 1) { *pbuffer = value; return(0); } else if(strlen(psrc) == 0) { @@ -352,7 +352,7 @@ static long getStringDouble( } psrc += MAX_STRING_SIZE*offset; while (nRequest) { - if(sscanf(psrc,"%lf",&value) == 1) { + if(epicsScanDouble(psrc, &value) == 1) { *pbuffer = value; } else if(strlen(psrc) == 0) { *pbuffer = 0.0; @@ -2368,7 +2368,7 @@ static long putStringUlong( /*Convert to double first so that numbers like 1.0e3 convert properly*/ /*Problem was old database access said to get unsigned long as double*/ if(nRequest==1 && offset==0) { - if(sscanf(pbuffer,"%lf",&value) == 1) { + if(epicsScanDouble(pbuffer, &value) == 1) { *pdest = (unsigned long)value; return(0); } @@ -2376,7 +2376,7 @@ static long putStringUlong( } pdest += offset; while (nRequest) { - if(sscanf(pbuffer,"%lf",&value) == 1) { + if(epicsScanDouble(pbuffer, &value) == 1) { *pdest = (unsigned long)value; } else { return(-1); @@ -2399,7 +2399,7 @@ static long putStringFloat( float value; if(nRequest==1 && offset==0) { - if(sscanf(pbuffer,"%f",&value) == 1) { + if(epicsScanFloat(pbuffer, &value) == 1) { *pdest = value; return(0); } else { @@ -2408,7 +2408,7 @@ static long putStringFloat( } pdest += offset; while (nRequest) { - if(sscanf(pbuffer,"%f",&value) == 1) { + if(epicsScanFloat(pbuffer, &value) == 1) { *pdest = value; } else { return(-1); @@ -2431,7 +2431,7 @@ static long putStringDouble( double value; if(nRequest==1 && offset==0) { - if(sscanf(pbuffer,"%lf",&value) == 1) { + if(epicsScanDouble(pbuffer, &value) == 1) { *pdest = value; return(0); } else { @@ -2440,7 +2440,7 @@ static long putStringDouble( } pdest += offset; while (nRequest) { - if(sscanf(pbuffer,"%lf",&value) == 1) { + if(epicsScanDouble(pbuffer, &value) == 1) { *pdest = value; } else { return(-1); diff --git a/src/db/dbFastLinkConv.c b/src/db/dbFastLinkConv.c index adf312d1e..bfe65e59d 100644 --- a/src/db/dbFastLinkConv.c +++ b/src/db/dbFastLinkConv.c @@ -14,7 +14,7 @@ * Date: 12-9-93 */ #include -#include +#include #include #include #include @@ -196,7 +196,7 @@ static long cvt_st_ul( /*Convert to double first so that numbers like 1.0e3 convert properly*/ /*Problem was old database access said to get unsigned long as double*/ - if (sscanf(from, "%lf", &value) == 1) { + if (epicsScanDouble(from, &value) == 1) { *to = (epicsUInt32)value; return(0); } @@ -216,7 +216,7 @@ static long cvt_st_f( { float value; - if (sscanf(from, "%f", &value) == 1) { + if (epicsScanFloat(from, &value) == 1) { *to = value; return(0); } @@ -236,7 +236,7 @@ static long cvt_st_d( { double value; - if (sscanf(from, "%lf", &value) == 1) { + if (epicsScanDouble(from, &value) == 1) { *to = value; return(0); } diff --git a/src/db/dbScan.c b/src/db/dbScan.c index ed2818801..f1efb36f4 100644 --- a/src/db/dbScan.c +++ b/src/db/dbScan.c @@ -15,7 +15,7 @@ * Date: 07/18/91 */ -#include +#include #include #include #include @@ -515,7 +515,7 @@ static void initPeriodic() papPeriodic[i] = psl; psl->lock = epicsMutexMustCreate(); ellInit(&psl->list); - sscanf(pmenu->papChoiceValue[i+SCAN_1ST_PERIODIC],"%lf",&temp); + epicsScanDouble(pmenu->papChoiceValue[i+SCAN_1ST_PERIODIC], &temp); psl->period = temp; } } diff --git a/src/db/dbTest.c b/src/db/dbTest.c index 0976bdb4e..536a06b0b 100644 --- a/src/db/dbTest.c +++ b/src/db/dbTest.c @@ -11,7 +11,7 @@ /* base/src/db $Id$ */ /* database access test subroutines */ -#include +#include #include #include #include @@ -577,7 +577,7 @@ long epicsShareAPI dbtpf(const char *pname,const char *pvalue) } } else printf("sscanf failed for DBR_ULONG\n"); /* DBR_FLOAT */ - if(validNumber && sscanf(pvalue,"%e",&fvalue)==1) { + if(validNumber && epicsScanFloat(pvalue, &fvalue)==1) { status=dbPutField(&addr,DBR_FLOAT,&fvalue,1L); if(status!=0) errMessage(status,"DBR_FLOAT failed"); else { @@ -590,7 +590,7 @@ long epicsShareAPI dbtpf(const char *pname,const char *pvalue) } } else printf("sscanf failed for DBR_FLOAT\n"); /* DBR_DOUBLE */ - if(validNumber && sscanf(pvalue,"%le",&dvalue)==1) { + if(validNumber && epicsScanDouble(pvalue, &dvalue)==1) { status=dbPutField(&addr,DBR_DOUBLE,&dvalue,1L); if(status!=0) errMessage(status,"DBR_DOUBLE failed"); else { diff --git a/src/db/db_test.c b/src/db/db_test.c index 14cf06247..0ad5ad2e2 100644 --- a/src/db/db_test.c +++ b/src/db/db_test.c @@ -14,7 +14,7 @@ * Date: 4/15/88 */ #include -#include +#include #include #include @@ -130,14 +130,14 @@ int epicsShareAPI pft(char *pname,char *pvalue) printf("\n\t LONG GET failed"); else ca_dump_dbr(DBR_LONG,1,buffer); } - if(sscanf(pvalue,"%f",&floatvalue)==1) { + if(epicsScanFloat(pvalue, &floatvalue)==1) { if (db_put_field(paddr,DBR_FLOAT,&floatvalue,1) < 0) printf("\n\t FLOAT failed "); if (db_get_field(paddr,DBR_FLOAT,buffer,1,NULL) < 0) printf("\n\t FLOAT GET failed"); else ca_dump_dbr(DBR_FLOAT,1,buffer); } - if(sscanf(pvalue,"%f",&floatvalue)==1) { + if(epicsScanFloat(pvalue, &floatvalue)==1) { doublevalue=floatvalue; if (db_put_field(paddr,DBR_DOUBLE,&doublevalue,1) < 0) printf("\n\t DOUBLE failed "); diff --git a/src/db/recGbl.c b/src/db/recGbl.c index 609ce1682..175df5df9 100644 --- a/src/db/recGbl.c +++ b/src/db/recGbl.c @@ -16,7 +16,7 @@ */ #include -#include +#include #include #include #include @@ -228,10 +228,10 @@ int epicsShareAPI recGblInitConstantLink( sscanf(plink->value.constantStr,"%lu",(unsigned long *)pdest); break; case DBF_FLOAT : - sscanf(plink->value.constantStr,"%f",(float *)pdest); + epicsScanFloat(plink->value.constantStr, (float *)pdest); break; case DBF_DOUBLE : - sscanf(plink->value.constantStr,"%lf",(double *)pdest); + epicsScanDouble(plink->value.constantStr, (double *)pdest); break; default: epicsPrintf("Error in recGblInitConstantLink: Illegal DBF type\n"); diff --git a/src/dbStatic/dbLexRoutines.c b/src/dbStatic/dbLexRoutines.c index 69ead0bb6..190264a4b 100644 --- a/src/dbStatic/dbLexRoutines.c +++ b/src/dbStatic/dbLexRoutines.c @@ -12,7 +12,7 @@ /*The routines in this module are serially reusable NOT reentrant*/ -#include +#include #include #include #include @@ -847,7 +847,7 @@ static void dbBreakBody(void) praw = (char *)popFirstTemp(); peng = (char *)popFirstTemp(); - if((sscanf(praw,"%lf",&raw)!=1) || (sscanf(peng,"%lf",&eng)!=1) ) { + if((epicsScanDouble(praw, &raw)!=1) || (sscanf(peng,"%lf",&eng)!=1) ) { yyerrorAbort("dbbrkTable: Illegal table value"); } free((void *)praw); diff --git a/src/gdd/aitConvert.cc b/src/gdd/aitConvert.cc index b627343d7..4ea0d0273 100644 --- a/src/gdd/aitConvert.cc +++ b/src/gdd/aitConvert.cc @@ -1,4 +1,4 @@ -/*************************************************************************\ +epicsS*************************************************************************\ * Copyright (c) 2002 The University of Chicago, as Operator of Argonne * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as @@ -16,7 +16,7 @@ #define AIT_CONVERT_SOURCE 1 #include -#include +#include #include #include "epicsStdio.h" #define epicsExportSharedSymbols @@ -52,7 +52,7 @@ bool getStringAsDouble ( const char * pString, ftmp = itmp; } else { - int j = sscanf ( pString,"%lf", &ftmp ); + int j = epicsScanDouble( pString, &ftmp ); if ( j != 1 ) { j = sscanf ( pString,"%x", &itmp ); if ( j == 1 ) { diff --git a/src/libCom/calc/postfix.c b/src/libCom/calc/postfix.c index 8ff596d3d..37d6c2951 100644 --- a/src/libCom/calc/postfix.c +++ b/src/libCom/calc/postfix.c @@ -55,7 +55,7 @@ * FLASE expression element not found */ -#include +#include #include #include #include @@ -347,7 +347,7 @@ long epicsShareAPI postfix(const char *pin,char *ppostfix,short *perror) *ppostfix++ = '\0'; ppostfix = pposthold; - if ( sscanf(ppostfix,"%lg",&constant) != 1) { + if ( epicsScanDouble(ppostfix, &constant) != 1) { *ppostfix = '\0'; } else { memcpy(ppostfix,(void *)&constant,8); diff --git a/src/libCom/env/envSubr.c b/src/libCom/env/envSubr.c index 19c533c15..5d0016d01 100644 --- a/src/libCom/env/envSubr.c +++ b/src/libCom/env/envSubr.c @@ -37,7 +37,7 @@ *-***************************************************************************/ #include -#include +#include #include #include @@ -198,7 +198,7 @@ double *pDouble /* O pointer to place to store value */ ptext = envGetConfigParam(pParam, sizeof text, text); if (ptext != NULL) { - count = sscanf(text, "%lf", pDouble); + count = epicsScanDouble(text, pDouble); if (count == 1) { return 0; } diff --git a/src/libCom/misc/epicsScanReal.c b/src/libCom/misc/epicsScanReal.c index ff34fce30..b678b1b55 100644 --- a/src/libCom/misc/epicsScanReal.c +++ b/src/libCom/misc/epicsScanReal.c @@ -16,7 +16,7 @@ #include "epicsStdio.h" -epicsShareFunc int epicsShareAPI epicsStrScanDouble(const char *str, double *dest) +epicsShareFunc int epicsShareAPI epicsScanDouble(const char *str, double *dest) { char *endp; double dtmp; @@ -28,7 +28,7 @@ epicsShareFunc int epicsShareAPI epicsStrScanDouble(const char *str, double *des return 1; } -epicsShareFunc int epicsShareAPI epicsStrScanFloat(const char *str, float *dest) +epicsShareFunc int epicsShareAPI epicsScanFloat(const char *str, float *dest) { char *endp; double dtmp; diff --git a/src/libCom/misc/epicsStdlib.h b/src/libCom/misc/epicsStdlib.h index f7cd7a246..29f642d07 100644 --- a/src/libCom/misc/epicsStdlib.h +++ b/src/libCom/misc/epicsStdlib.h @@ -16,8 +16,8 @@ extern "C" { #endif -epicsShareFunc int epicsShareAPI epicsStrScanDouble(const char *str, double *dest); -epicsShareFunc int epicsShareAPI epicsStrScanFloat(const char *str, float *dest); +epicsShareFunc int epicsShareAPI epicsScanDouble(const char *str, double *dest); +epicsShareFunc int epicsShareAPI epicsScanFloat(const char *str, float *dest); #include #include diff --git a/src/util/ca_test.c b/src/util/ca_test.c index 0dfefc49f..e2c2d8699 100644 --- a/src/util/ca_test.c +++ b/src/util/ca_test.c @@ -20,6 +20,7 @@ */ #include #include +#include #ifndef LOCAL #define LOCAL static @@ -258,7 +259,7 @@ char *pvalue SEVCHK(status, NULL); verify_value(chan_id, DBR_LONG); } - if(sscanf(pvalue,"%f",&floatvalue)==1) { + if(epicsScanFloat(pvalue, &floatvalue)==1) { /* * single precision float ca_put */ @@ -269,7 +270,7 @@ char *pvalue SEVCHK(status, NULL); verify_value(chan_id, DBR_FLOAT); } - if(sscanf(pvalue,"%lf",&doublevalue)==1) { + if(epicsScanDouble(pvalue, &doublevalue)==1) { /* * double precision float ca_put */