From 3252364e9f60b5b0ef65f03f61ea82c0c6d8ad7f Mon Sep 17 00:00:00 2001 From: Ralph Lange Date: Tue, 7 Dec 2021 18:18:55 +0100 Subject: [PATCH] Fix gdd string to double conversion This is an alternative fix for the issue described in https://github.com/epics-modules/pcas/issues/4 and https://github.com/epics-extensions/ca-gateway/issues/37 that keeps the call to epicsScanDouble() before trying sscanf() first with "%lf" (ignoring extra characters) then with "%x" (to catch hex numbers). (same commit as "upstream" commit 7c168f20 in base 3.15; fixes #4) --- src/gdd/aitConvert.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/gdd/aitConvert.cc b/src/gdd/aitConvert.cc index b2a4e42e3..eeb51ee32 100644 --- a/src/gdd/aitConvert.cc +++ b/src/gdd/aitConvert.cc @@ -50,14 +50,16 @@ bool getStringAsDouble ( const char * pString, ftmp = itmp; } else { - int j = epicsScanDouble( pString, &ftmp ); - if ( j != 1 ) { - j = sscanf ( pString,"%x", &itmp ); - if ( j == 1 ) { - ftmp = itmp; - } - else { - return false; + int j = epicsScanDouble ( pString, &ftmp ); + if ( j != 1 ) { + j = sscanf ( pString, "%lf", &ftmp ); + if ( j != 1 ) { + j = sscanf ( pString, "%x", &itmp ); + if ( j == 1 ) { + ftmp = itmp; + } else { + return false; + } } } }