epics-modules / autosave

APS BCDA synApps module: autosave
https://epics-modules.github.io/autosave/
Other
8 stars 31 forks source link

Fix problem with newlines in string values #29

Closed smarsching closed 2 years ago

smarsching commented 4 years ago

There was a bug that caused an invalid save file to be written when a string value contained a newline character. The newline character was written unescaped and thus the value written to the save file would be split across several lines, which would cause problems when restoring the file (because the code loading the file expects one line per PV).

This PR fixes this problem by escaping such characters when saving and unescaping them when restoring a save file.

anjohnson commented 4 years ago

Please use the string escape functions that have been in epicsString.h since R3.14.11 (2009) instead of adding new ones:

int epicsStrnRawFromEscaped(char *outbuf, size_t outsize, const char *inbuf, size_t inlen);
int epicsStrnEscapedFromRaw(char *outbuf, size_t outsize, const char *inbuf, size_t inlen);
size_t epicsStrnEscapedFromRawSize(const char *buf, size_t len);
int epicsStrPrintEscaped(FILE *fp, const char *s, size_t n);
smarsching commented 4 years ago

@anjohnson Thanks for pointing me to these functions, I was not aware of them. I have now changed the code to use these functions instead.