diff options
| author | Elliott Hughes <enh@google.com> | 2014-02-26 21:28:27 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-02-26 21:28:27 +0000 |
| commit | ecb5dd697ca72828079bf40f932abf9f9ee7b7db (patch) | |
| tree | 858a7f170efd4e51e228a909664fe23425b014a3 | |
| parent | 431735f005af79407e01a68995ac6dde7ff4b815 (diff) | |
| parent | fff9d11be528ad8f581cc7223b879c55009d7396 (diff) | |
| download | system_core-ecb5dd697ca72828079bf40f932abf9f9ee7b7db.zip system_core-ecb5dd697ca72828079bf40f932abf9f9ee7b7db.tar.gz system_core-ecb5dd697ca72828079bf40f932abf9f9ee7b7db.tar.bz2 | |
Merge "Fix undefined args access for x86_64."
| -rw-r--r-- | libutils/String8.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
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); |
