[llvm-commits] [llvm] r42871 - /llvm/trunk/lib/ExecutionEngine/Interpreter/Execution.cpp
Gabor Greif
ggreif at gmail.com
Thu Oct 11 12:40:38 PDT 2007
Author: ggreif
Date: Thu Oct 11 14:40:35 2007
New Revision: 42871
URL: http://llvm.org/viewvc/llvm-project?rev=42871&view=rev
Log:
Fix an assertion abort on sparc. malloc(0) is allowed to
return NULL.
Modified:
llvm/trunk/lib/ExecutionEngine/Interpreter/Execution.cpp
Modified: llvm/trunk/lib/ExecutionEngine/Interpreter/Execution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Interpreter/Execution.cpp?rev=42871&r1=42870&r2=42871&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Interpreter/Execution.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Interpreter/Execution.cpp Thu Oct 11 14:40:35 2007
@@ -24,6 +24,7 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/MathExtras.h"
#include <cmath>
+#include <algorithm>
using namespace llvm;
STATISTIC(NumDynamicInsts, "Number of dynamic instructions executed");
@@ -747,7 +748,8 @@
unsigned TypeSize = (size_t)TD.getTypeSize(Ty);
- unsigned MemToAlloc = NumElements * TypeSize;
+ // Avoid malloc-ing zero bytes, use max()...
+ unsigned MemToAlloc = std::max(1U, NumElements * TypeSize);
// Allocate enough memory to hold the type...
void *Memory = malloc(MemToAlloc);
More information about the llvm-commits
mailing list