diff --git a/src/posix/client.cpp b/src/posix/client.cpp index 2961a62ec..5225a6e4b 100644 --- a/src/posix/client.cpp +++ b/src/posix/client.cpp @@ -161,6 +161,11 @@ exit: return ok; } +static bool IsSeparator(char aChar) +{ + return (aChar == ' ') || (aChar == '\t') || (aChar == '\r') || (aChar == '\n'); +} + int main(int argc, char *argv[]) { bool isInteractive = true; @@ -179,10 +184,15 @@ int main(int argc, char *argv[]) for (int i = 1; i < argc; i++) { - int rval = snprintf(&buffer[count], (sizeof(buffer) - count), "%s ", argv[i]); - - VerifyOrExit(rval > 0 && static_cast(rval) < (sizeof(buffer) - count), ret = OT_EXIT_FAILURE); - count += static_cast(rval); + for (const char *c = argv[i]; *c; ++c) + { + if (IsSeparator(*c)) + { + buffer[count++] = '\\'; + } + buffer[count++] = *c; + } + buffer[count++] = ' '; } // replace the trailing space with newline