llvm.org GIT mirror llvm / 06e950e
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 Ted Kremenek 8 years ago
1 changed file(s) with 9 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
6464 for (Length = 0, i = 0; i != (unsigned)argc; ++i)
6565 Length += strlen(argv[i])+1;
6666
67 // Defensively check for a zero length, even though this is unlikely
68 // to happen in practice. This avoids calling malloc() below with a
69 // size of 0.
70 if (Length == 0) {
71 SavedArgs = 0;
72 SavedArgsLength = 0;
73 return argc;
74 }
75
6776 SavedArgs = (char*)malloc(Length);
6877 for (Length = 0, i = 0; i != (unsigned)argc; ++i) {
6978 unsigned Len = strlen(argv[i]);