summaryrefslogtreecommitdiffstats
path: root/llvm/runtime/libprofile/CommonProfiling.c
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2012-04-26 20:54:27 +0000
committerTed Kremenek <kremenek@apple.com>2012-04-26 20:54:27 +0000
commitb62cf212b241724d5096ba13de2d688f7e4cf43f (patch)
tree48dbc98e157a4b4d0cac8df5a2f640164a445bc3 /llvm/runtime/libprofile/CommonProfiling.c
parent822944c97deb7a9a3bb242a2b7a944edf01647d7 (diff)
downloadbcm5719-llvm-b62cf212b241724d5096ba13de2d688f7e4cf43f.tar.gz
bcm5719-llvm-b62cf212b241724d5096ba13de2d688f7e4cf43f.zip
Defensively guard against calling malloc() with a size of zero.
llvm-svn: 155661
Diffstat (limited to 'llvm/runtime/libprofile/CommonProfiling.c')
-rw-r--r--llvm/runtime/libprofile/CommonProfiling.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/runtime/libprofile/CommonProfiling.c b/llvm/runtime/libprofile/CommonProfiling.c
index d55f51c5b44..13e3eb9cf7b 100644
--- a/llvm/runtime/libprofile/CommonProfiling.c
+++ b/llvm/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]);
OpenPOWER on IntegriCloud