diff --git a/src/ioc/db/dbExtractArray.c b/src/ioc/db/dbExtractArray.c index 95eca4bfa..29d532530 100644 --- a/src/ioc/db/dbExtractArray.c +++ b/src/ioc/db/dbExtractArray.c @@ -36,21 +36,21 @@ void dbExtractArrayFromRec(const dbAddr *paddr, void *pto, char isString = (paddr->field_type == DBF_STRING); if (nRequest > no_elements) nRequest = no_elements; - if (isString && dstSize >= MAX_STRING_SIZE) dstSize = MAX_STRING_SIZE - 1; + if (isString && srcSize > MAX_STRING_SIZE) dstSize = MAX_STRING_SIZE; - if (increment == 1) { + if (increment == 1 && dstSize == srcSize) { nUpperPart = nRequest < no_elements - offset ? nRequest : no_elements - offset; memcpy(pdst, &psrc[offset * srcSize], dstSize * nUpperPart); if (nRequest > nUpperPart) memcpy(&pdst[dstSize * nUpperPart], psrc, dstSize * (nRequest - nUpperPart)); if (isString) for (i = 1; i <= nRequest; i++) - pdst[dstSize*i] = '\0'; + pdst[dstSize*i-1] = '\0'; } else { - for (; nRequest > 0; nRequest--, pdst += srcSize, offset += increment) { + for (; nRequest > 0; nRequest--, pdst += dstSize, offset += increment) { offset %= no_elements; memcpy(pdst, &psrc[offset*srcSize], dstSize); - if (isString) pdst[dstSize] = '\0'; + if (isString) pdst[dstSize-1] = '\0'; } } }