mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-17 20:23:47 -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.
|
||||
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;
|
||||
// If the number of bytes is large, we will need to allocate a
|
||||
// temporary buffer from the heap. Otherwise, we can get away with
|
||||
// allocating it on the stack, via alloca().
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user