From 721c201bd55ffb73cb2ba8d39e0570fa38c44e15 Mon Sep 17 00:00:00 2001 From: dim Date: Wed, 15 Aug 2012 19:34:23 +0000 Subject: Vendor import of llvm trunk r161861: http://llvm.org/svn/llvm-project/llvm/trunk@161861 --- runtime/libprofile/CommonProfiling.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'runtime/libprofile/CommonProfiling.c') diff --git a/runtime/libprofile/CommonProfiling.c b/runtime/libprofile/CommonProfiling.c index d55f51c..acc17ce 100644 --- a/runtime/libprofile/CommonProfiling.c +++ b/runtime/libprofile/CommonProfiling.c @@ -65,6 +65,16 @@ int save_arguments(int argc, const char **argv) { for (Length = 0, i = 0; i != (unsigned)argc; ++i) Length += strlen(argv[i])+1; + /* Defensively check for a zero length, even though this is unlikely + * to happen in practice. This avoids calling malloc() below with a + * size of 0. + */ + if (Length == 0) { + SavedArgs = 0; + SavedArgsLength = 0; + return argc; + } + SavedArgs = (char*)malloc(Length); for (Length = 0, i = 0; i != (unsigned)argc; ++i) { unsigned Len = strlen(argv[i]); -- cgit v1.1