Skip to content
Snippets Groups Projects
Commit 7e6e3806 authored by Ralph Lange's avatar Ralph Lange
Browse files

catools: Change behaviour of camonitor when printing array of chars as string

camonitor was using strlen() to find out the length of the array to print as %s string,
which led to printing old buffer contents when the array-string was not null terminated.
Now uses the minimum of strlen(), elements received, and elements requested.

Suggested by Mark Rivers on tech-talk (11 Sep 2012)
parent 709b6ef2
No related branches found
No related tags found
No related merge requests found
......@@ -445,10 +445,13 @@ char *dbr2str (const void *value, unsigned type)
\
if (charArrAsStr && dbr_type_is_CHAR(TYPE_ENUM) && (reqElems || pv->nElems > 1)) { \
dbr_char_t *s = (dbr_char_t*) dbr_value_ptr(pv->value, pv->dbrType); \
int dlen = epicsStrnEscapedFromRawSize((char*)s, strlen((char*)s)); \
size_t len = strlen((char*)s); \
unsigned long elems = reqElems && (reqElems < pv->nElems) ? reqElems : pv->nElems; \
if (len < elems) elems = len; \
int dlen = epicsStrnEscapedFromRawSize((char*)s, elems); \
char *d = calloc(dlen+1, sizeof(char)); \
if(d) { \
epicsStrnEscapedFromRaw(d, dlen+1, (char*)s, strlen((char*)s));\
epicsStrnEscapedFromRaw(d, dlen+1, (char*)s, elems); \
printf("%c%s", fieldSeparator, d); \
free(d); \
} else { \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment