diff options
| -rw-r--r-- | libcutils/socket_local_server.c | 4 | ||||
| -rw-r--r-- | libutils/String8.cpp | 13 |
2 files changed, 14 insertions, 3 deletions
diff --git a/libcutils/socket_local_server.c b/libcutils/socket_local_server.c index 4971b1b..7628fe4 100644 --- a/libcutils/socket_local_server.c +++ b/libcutils/socket_local_server.c @@ -43,6 +43,8 @@ int socket_local_server(const char *name, int namespaceId, int type) #define LISTEN_BACKLOG 4 +/* Only the bottom bits are really the socket type; there are flags too. */ +#define SOCK_TYPE_MASK 0xf /** * Binds a pre-created socket(AF_LOCAL) 's' to 'name' @@ -107,7 +109,7 @@ int socket_local_server(const char *name, int namespace, int type) return -1; } - if (type == SOCK_STREAM) { + if ((type & SOCK_TYPE_MASK) == SOCK_STREAM) { int ret; ret = listen(s, LISTEN_BACKLOG); diff --git a/libutils/String8.cpp b/libutils/String8.cpp index e852d77..8acb4d4 100644 --- a/libutils/String8.cpp +++ b/libutils/String8.cpp @@ -323,8 +323,17 @@ status_t String8::appendFormat(const char* fmt, ...) status_t String8::appendFormatV(const char* fmt, va_list args) { - int result = NO_ERROR; - int n = vsnprintf(NULL, 0, fmt, args); + int n, result = NO_ERROR; + va_list tmp_args; + + /* args is undefined after vsnprintf. + * So we need a copy here to avoid the + * second vsnprintf access undefined args. + */ + va_copy(tmp_args, args); + n = vsnprintf(NULL, 0, fmt, tmp_args); + va_end(tmp_args); + if (n != 0) { size_t oldLength = length(); char* buf = lockBuffer(oldLength + n); |
