db: Fix db_get_field() on an empty array field.
This fixes a bug introduced with the dynamic-array branch. The new version of db_get_field() was using the dbr_size_n() macro to calculate the offset to the start of the buffer area to be zeroed, but when nRequest is zero this gives the wrong result; the dbr_ structures always contain at least one value element, and dbr_size_n() thus has to include that in its size calculation.
This commit is contained in:
@@ -152,12 +152,16 @@ int epicsShareAPI db_get_field(struct dbAddr *paddr,
|
||||
long nRequest = no_elements;
|
||||
int result = db_get_field_and_count(
|
||||
paddr, buffer_type, pbuffer, &nRequest, pfl);
|
||||
if (nRequest < no_elements)
|
||||
/* If the database request returned fewer elements than requested then
|
||||
* fill out the remainder of the array with zeros. */
|
||||
memset(
|
||||
(char *)pbuffer + dbr_size_n(buffer_type, nRequest), 0,
|
||||
(no_elements - nRequest) * dbr_value_size[buffer_type]);
|
||||
if (nRequest < no_elements) {
|
||||
/* The database request returned fewer elements than requested, so
|
||||
* fill the remainder of the buffer with zeros.
|
||||
*/
|
||||
int val_size = dbr_value_size[buffer_type];
|
||||
int offset = dbr_size[buffer_type] + (nRequest - 1) * val_size;
|
||||
int nbytes = (no_elements - nRequest) * val_size;
|
||||
|
||||
memset((char *)pbuffer + offset, 0, nbytes);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user