bugfix: char array access (using $ syntax) to links and attributes returned to few bytes and faild when 1 byte was requested.

This commit is contained in:
zimoch
2011-12-23 10:50:59 +00:00
parent fa1abe85e8
commit 0212ec4075
2 changed files with 69 additions and 8 deletions

View File

@@ -964,13 +964,14 @@ long epicsShareAPI dbGetField(DBADDR *paddr,short dbrType,
switch (dbrType) {
case DBR_STRING:
maxlen = MAX_STRING_SIZE - 1;
pbuf[maxlen] = 0;
if (nRequest && *nRequest > 1) *nRequest = 1;
break;
case DBR_CHAR:
case DBR_UCHAR:
if (nRequest && *nRequest > 1) {
maxlen = *nRequest - 1;
if (nRequest && *nRequest > 0) {
maxlen = *nRequest;
break;
}
/* else fall through ... */
@@ -984,8 +985,7 @@ 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);
}
dbFinishEntry(&dbEntry);
} else {
@@ -1023,13 +1023,14 @@ long epicsShareAPI dbGet(DBADDR *paddr, short dbrType,
switch (dbrType) {
case DBR_STRING:
maxlen = MAX_STRING_SIZE - 1;
pbuf[maxlen] = 0;
if (nRequest && *nRequest > 1) *nRequest = 1;
break;
case DBR_CHAR:
case DBR_UCHAR:
if (nRequest && *nRequest > 1) {
maxlen = *nRequest - 1;
if (nRequest && *nRequest > 0) {
maxlen = *nRequest;
break;
}
/* else fall through ... */
@@ -1037,8 +1038,7 @@ 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);
return 0;
}