From 7cc8a552a3efa25cf38ad81067a47ea5da970dfb Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Wed, 11 Jan 2012 16:47:37 -0600 Subject: [PATCH] db: Allow single-char accesses as long strings Clients try to use long string support to fetch DBF_STRING fields use DBF_CTRL_CHAR with a 1-element array, but the IOC was rejecting that. This permits it, and also ensures that the resulting strings are zero-terminated. Fixes lp:907761 --- documentation/RELEASE_NOTES.html | 12 ++++++++++++ src/db/dbAccess.c | 12 ++++++------ src/db/dbConvert.c | 14 ++++++++++++++ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/documentation/RELEASE_NOTES.html b/documentation/RELEASE_NOTES.html index 91a84f214..93d3045c8 100644 --- a/documentation/RELEASE_NOTES.html +++ b/documentation/RELEASE_NOTES.html @@ -13,6 +13,18 @@ +

Launchpad Bugs Resolved

+ +

The following are links to bugs in the Launchpad bug tracker that have been +fixed in this release:

+ + +

Comments in iocsh scripts

The IOC shell was very particular about comments in previous versions of diff --git a/src/db/dbAccess.c b/src/db/dbAccess.c index a358270f3..22f4e20e7 100644 --- a/src/db/dbAccess.c +++ b/src/db/dbAccess.c @@ -969,7 +969,7 @@ long epicsShareAPI dbGetField(DBADDR *paddr,short dbrType, case DBR_CHAR: case DBR_UCHAR: - if (nRequest && *nRequest > 1) { + if (nRequest && *nRequest > 0) { maxlen = *nRequest - 1; break; } @@ -984,8 +984,8 @@ long epicsShareAPI dbGetField(DBADDR *paddr,short dbrType, if (!status) status = dbFindField(&dbEntry, pfldDes->name); if (!status) { rtnString = dbGetString(&dbEntry); - strncpy(pbuf, rtnString, maxlen - 1); - pbuf[maxlen - 1] = 0; + strncpy(pbuf, rtnString, maxlen); + pbuf[maxlen] = 0; } dbFinishEntry(&dbEntry); } else { @@ -1028,7 +1028,7 @@ long epicsShareAPI dbGet(DBADDR *paddr, short dbrType, case DBR_CHAR: case DBR_UCHAR: - if (nRequest && *nRequest > 1) { + if (nRequest && *nRequest > 0) { maxlen = *nRequest - 1; break; } @@ -1037,8 +1037,8 @@ long epicsShareAPI dbGet(DBADDR *paddr, short dbrType, return S_db_badDbrtype; } - strncpy(pbuf, (char *)paddr->pfield, maxlen - 1); - pbuf[maxlen - 1] = 0; + strncpy(pbuf, (char *)paddr->pfield, maxlen); + pbuf[maxlen] = 0; return 0; } diff --git a/src/db/dbConvert.c b/src/db/dbConvert.c index f370e0aa2..4b7ad7da1 100644 --- a/src/db/dbConvert.c +++ b/src/db/dbConvert.c @@ -416,6 +416,13 @@ static long getCharChar( char *pbuffer = (char *)pto; char *psrc=(char *)(paddr->pfield); + if (paddr->pfldDes->field_type == DBF_STRING) { + /* This is a DBF_STRING field being read as a long string. + * The buffer we return must be zero-terminated. + */ + pbuffer[--nRequest] = 0; + if (nRequest == 0) return(0); + } if(nRequest==1 && offset==0) { *pbuffer = *psrc; return(0); @@ -436,6 +443,13 @@ static long getCharUchar( unsigned char *pbuffer = (unsigned char *)pto; char *psrc=(char *)(paddr->pfield); + if (paddr->pfldDes->field_type == DBF_STRING) { + /* This is a DBF_STRING field being read as a long string. + * The buffer we return must be zero-terminated. + */ + pbuffer[--nRequest] = 0; + if (nRequest == 0) return(0); + } if(nRequest==1 && offset==0) { *pbuffer = *psrc; return(0);