catools: Fix off-by-one bug in caput

An internal buffer was allocated one char too short, when caput was used
with the '-S' (send string as array of chars) option.

Reported by J. Lewis Muir (tech-talk on 17-Aug-2012)
This commit is contained in:
Ralph Lange
2012-09-03 21:25:44 +02:00
parent 169b30081a
commit 709b6ef2f3

View File

@@ -492,12 +492,12 @@ int main (int argc, char *argv[])
if (charArrAsStr) {
count = len;
dbrType = DBR_CHAR;
ebuf = calloc(strlen(cbuf), sizeof(char));
ebuf = calloc(strlen(cbuf)+1, sizeof(char));
if(!ebuf) {
fprintf(stderr, "Memory allocation failed\n");
return 1;
}
epicsStrnRawFromEscaped(ebuf, strlen(cbuf), cbuf, strlen(cbuf));
epicsStrnRawFromEscaped(ebuf, strlen(cbuf)+1, cbuf, strlen(cbuf));
} else {
for (i = 0; i < count; ++i) {
epicsStrnRawFromEscaped(sbuf[i], sizeof(EpicsStr), *(argv+optind+i), sizeof(EpicsStr));