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

61
char_arrary_access.patch Normal file
View File

@@ -0,0 +1,61 @@
Index: src/db/dbAccess.c
===================================================================
RCS file: /cvs/G/EPICS/base-3.14.12/src/db/dbAccess.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 dbAccess.c
--- src/db/dbAccess.c 29 Nov 2010 10:38:07 -0000 1.1.1.1
+++ src/db/dbAccess.c 23 Dec 2011 10:25:26 -0000
@@ -964,13 +964,14 @@
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 @@
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 @@
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 @@
return S_db_badDbrtype;
}
- strncpy(pbuf, (char *)paddr->pfield, maxlen - 1);
- pbuf[maxlen - 1] = 0;
+ strncpy(pbuf, (char *)paddr->pfield, maxlen);
return 0;
}

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