diff options
author | Ted Kremenek <kremenek@apple.com> | 2012-04-26 20:54:27 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2012-04-26 20:54:27 +0000 |
commit | 06e950ecb21514b0d09f942c108ad346102278f1 (patch) | |
tree | 12aea3ee95f18bda4b66c61270fc847d29ea3b2c /runtime | |
parent | 9da7892fbe1c9e7c592c5928e36724a0e190a777 (diff) | |
download | external_llvm-06e950ecb21514b0d09f942c108ad346102278f1.zip external_llvm-06e950ecb21514b0d09f942c108ad346102278f1.tar.gz external_llvm-06e950ecb21514b0d09f942c108ad346102278f1.tar.bz2 |
Defensively guard against calling malloc() with a size of zero.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@155661 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/libprofile/CommonProfiling.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/runtime/libprofile/CommonProfiling.c b/runtime/libprofile/CommonProfiling.c index d55f51c..13e3eb9 100644 --- a/runtime/libprofile/CommonProfiling.c +++ b/runtime/libprofile/CommonProfiling.c @@ -65,6 +65,15 @@ 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]); |