aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2018-05-29 15:51:42 +0200
committerPierre Ossman <ossman@cendio.se>2018-05-29 15:51:42 +0200
commitb8b3cbfc5bfd97e2a9a98f4b28f325518ecce254 (patch)
tree68aa444bc4b1b99ee86e321ec01981236bff1fbb
parent2a85489a191c14efab813115dd900faa0130a198 (diff)
downloadtigervnc-b8b3cbfc5bfd97e2a9a98f4b28f325518ecce254.tar.gz
tigervnc-b8b3cbfc5bfd97e2a9a98f4b28f325518ecce254.zip
Stop treating "\\\\" as a special case
Make the code simpler by handling it just like any escaped character.
-rw-r--r--vncviewer/parameters.cxx55
1 files changed, 20 insertions, 35 deletions
diff --git a/vncviewer/parameters.cxx b/vncviewer/parameters.cxx
index 448a2434..16de6e37 100644
--- a/vncviewer/parameters.cxx
+++ b/vncviewer/parameters.cxx
@@ -190,44 +190,35 @@ static struct {
const char first;
const char second;
} replaceMap[] = { { '\n', 'n' },
- { '\r', 'r' } };
+ { '\r', 'r' },
+ { '\\', '\\' } };
static bool encodeValue(const char* val, char* dest, size_t destSize) {
- bool normalCharacter = true;
size_t pos = 0;
for (size_t i = 0; (val[i] != '\0') && (i < (destSize - 1)); i++) {
+ bool normalCharacter;
// Check for sequences which will need encoding
- if (val[i] == '\\') {
-
- strncpy(dest+pos, "\\\\", 2);
- pos++;
- if (pos >= destSize)
- return false;
-
- } else {
+ normalCharacter = true;
+ for (size_t j = 0; j < sizeof(replaceMap)/sizeof(replaceMap[0]); j++) {
- for (size_t j = 0; j < sizeof(replaceMap)/sizeof(replaceMap[0]); j++) {
-
- if (val[i] == replaceMap[j].first) {
- dest[pos] = '\\';
- pos++;
- if (pos >= destSize)
- return false;
+ if (val[i] == replaceMap[j].first) {
+ dest[pos] = '\\';
+ pos++;
+ if (pos >= destSize)
+ return false;
- dest[pos] = replaceMap[j].second;
- normalCharacter = false;
- break;
- }
+ dest[pos] = replaceMap[j].second;
+ normalCharacter = false;
+ break;
+ }
- if (normalCharacter) {
- dest[pos] = val[i];
- }
+ if (normalCharacter) {
+ dest[pos] = val[i];
}
}
- normalCharacter = true; // Reset for next loop
pos++;
if (pos >= destSize)
@@ -242,13 +233,14 @@ static bool encodeValue(const char* val, char* dest, size_t destSize) {
static bool decodeValue(const char* val, char* dest, size_t destSize) {
size_t pos = 0;
- bool escapedCharacter = false;
for (size_t i = 0; (val[i] != '\0') && (i < (destSize - 1)); i++) {
// Check for escape sequences
if (val[i] == '\\') {
+ bool escapedCharacter;
+ escapedCharacter = false;
for (size_t j = 0; j < sizeof(replaceMap)/sizeof(replaceMap[0]); j++) {
if (val[i+1] == replaceMap[j].second) {
dest[pos] = replaceMap[j].first;
@@ -258,20 +250,13 @@ static bool decodeValue(const char* val, char* dest, size_t destSize) {
}
}
- if (!escapedCharacter) {
- if (val[i+1] == '\\') {
- dest[pos] = val[i];
- i++;
- } else {
- return false;
- }
- }
+ if (!escapedCharacter)
+ return false;
} else {
dest[pos] = val[i];
}
- escapedCharacter = false; // Reset for next loop
pos++;
if (pos >= destSize) {
return false;