mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-18 12:43:44 -04:00
alloca() fails with large buffers
This commit is contained in:
parent
51fb06511f
commit
bf43d9fb7d
@ -142,17 +142,37 @@ get_datagram(Datagram &data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now, read the datagram itself.
|
// Now, read the datagram itself.
|
||||||
char *buffer = (char *)alloca(num_bytes);
|
|
||||||
nassertr(buffer != (char *)NULL, false);
|
|
||||||
|
|
||||||
_in->read(buffer, num_bytes);
|
// If the number of bytes is large, we will need to allocate a
|
||||||
if (_in->fail() || _in->eof()) {
|
// temporary buffer from the heap. Otherwise, we can get away with
|
||||||
_error = true;
|
// allocating it on the stack, via alloca().
|
||||||
return false;
|
if (num_bytes > 65536) {
|
||||||
|
char *buffer = new char[num_bytes];
|
||||||
|
nassertr(buffer != (char *)NULL, false);
|
||||||
|
|
||||||
|
_in->read(buffer, num_bytes);
|
||||||
|
if (_in->fail() || _in->eof()) {
|
||||||
|
_error = true;
|
||||||
|
delete[] buffer;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
data = Datagram(buffer, num_bytes);
|
||||||
|
delete[] buffer;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
char *buffer = (char *)alloca(num_bytes);
|
||||||
|
nassertr(buffer != (char *)NULL, false);
|
||||||
|
|
||||||
|
_in->read(buffer, num_bytes);
|
||||||
|
if (_in->fail() || _in->eof()) {
|
||||||
|
_error = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
data = Datagram(buffer, num_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
data = Datagram(buffer, num_bytes);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user