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
This commit is contained in:
Andrew Johnson
2012-01-11 16:47:37 -06:00
parent afaebfbeb1
commit 7cc8a552a3
3 changed files with 32 additions and 6 deletions

View File

@@ -13,6 +13,18 @@
<!-- Insert new items immediately below here ... -->
<h4>Launchpad Bugs Resolved</h4>
<p>The following are links to bugs in the Launchpad bug tracker that have been
fixed in this release:</p>
<ul>
<li>907761
<a href="https://launchpad.net/bugs/907761">
reading only 1st char of link in "long string" ($) syntax fails in read
error</a></li>
</ul>
<h4>Comments in iocsh scripts</h4>
<p>The IOC shell was very particular about comments in previous versions of

View File

@@ -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;
}

View File

@@ -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);