Skip to content

Commit

Permalink
Merge PR #3841: plugins: fix escape() warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
davidebeatrici committed Oct 12, 2019
2 parents b54351c + 243ece3 commit 9621bb1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion plugins/bf1/bf1.cpp
Expand Up @@ -107,7 +107,7 @@ static int fetch(float *avatar_pos, float *avatar_front, float *avatar_top, floa
oidentity << "{";

// Team
escape(team, sizeof(server_name));
escape(team, sizeof(team));
if (strcmp(team, "") != 0) {
oidentity << std::endl << "\"Team\": \"" << team << "\","; // Set team name in identity.
}
Expand Down
48 changes: 23 additions & 25 deletions plugins/mumble_plugin_utils.h
Expand Up @@ -30,31 +30,29 @@ static inline std::string utf16ToUtf8(const std::wstring &wstr) {
// string is NUL-terminated by always
// setting the last byte of the input
// string to the value 0.
static void escape(char *str, size_t size) {
// Ensure the input string is properly NUL-terminated.
str[size-1] = 0;
char *c = str;

while (*c != '\0') {
// For JSON compatibility, the string
// can't contain double quotes.
// If a double quote is found, replace
// it with an ASCII space.
if (*c == '"') {
*c = ' ';
}

// Ensure the string is within printable
// ASCII. If not, replace the offending
// byte with an ASCII space.
if (*c < 32) {
*c = ' ';
} else if (*c > 126) {
*c = ' ';
}

c += 1;
}
static inline void escape(char *str, const size_t &size) {
// Ensure the input string is properly NUL-terminated.
str[size - 1] = 0;
char *c = str;

while (*c != '\0') {
// For JSON compatibility, the string
// can't contain double quotes.
// If a double quote is found, replace
// it with an ASCII space.
if (*c == '"') {
*c = ' ';
}

// Ensure the string is within printable
// ASCII. If not, replace the offending
// byte with an ASCII space.
if (*c < 32 || *c > 126) {
*c = ' ';
}

c += 1;
}
}

#endif

0 comments on commit 9621bb1

Please sign in to comment.