From 3714be4f16ef953a9fd26d1d2f8f477968f51d96 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Thu, 24 Sep 2015 13:04:49 -0400 Subject: [PATCH] fail zero length field names --- src/factory/FieldCreateFactory.cpp | 11 ++++++++--- testApp/pv/testPVData.cpp | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/factory/FieldCreateFactory.cpp b/src/factory/FieldCreateFactory.cpp index bcf7038..696b3a1 100644 --- a/src/factory/FieldCreateFactory.cpp +++ b/src/factory/FieldCreateFactory.cpp @@ -948,14 +948,19 @@ StructureConstPtr FieldCreate::createStructure () const } namespace { +bool xisalnum(char c) +{ + return (c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9'); +} + void validateFieldName(const std::string& n) { + if(n.size()==0) + throw std::invalid_argument("zero length field names not allowed"); for(size_t i=0, N=n.size(); i='a' && c<='z') {} - else if(c>='A' && c<='Z') {} - else if(c>='0' && c<='9') {} + if(xisalnum(c)) {} else { switch(c){ case '_': diff --git a/testApp/pv/testPVData.cpp b/testApp/pv/testPVData.cpp index 000d808..6d061e8 100644 --- a/testApp/pv/testPVData.cpp +++ b/testApp/pv/testPVData.cpp @@ -79,6 +79,7 @@ static void testCreatePVStructureWithInvalidName() fieldNames,pvFields); testFail("Creation of invalid field name '%s' was allowed", fieldNames[1].c_str()); } catch(std::invalid_argument& e) { + testDiag("Exception: \"%s\"", e.what()); testPass("Creation of invalid field name '%s' fails as expected", fieldNames[1].c_str()); } }