From 0212ec4075fec5ea52c4468efba9e9fa8f2fb0fe Mon Sep 17 00:00:00 2001 From: zimoch Date: Fri, 23 Dec 2011 10:50:59 +0000 Subject: [PATCH] bugfix: char array access (using $ syntax) to links and attributes returned to few bytes and faild when 1 byte was requested. --- char_arrary_access.patch | 61 ++++++++++++++++++++++++++++++++++++++++ src/db/dbAccess.c | 16 +++++------ 2 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 char_arrary_access.patch diff --git a/char_arrary_access.patch b/char_arrary_access.patch new file mode 100644 index 000000000..975d39d6d --- /dev/null +++ b/char_arrary_access.patch @@ -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; + } + diff --git a/src/db/dbAccess.c b/src/db/dbAccess.c index b4baecc8b..0c5e2973e 100644 --- a/src/db/dbAccess.c +++ b/src/db/dbAccess.c @@ -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; }