drop custom new overloads
parent
3a7970706a
commit
5f3ceea7bf
|
@ -331,7 +331,11 @@ struct iqm : skelloader<iqm>
|
|||
lilswap(&hdr.version, (sizeof(hdr) - sizeof(hdr.magic))/sizeof(uint));
|
||||
if(hdr.version != 2) goto error;
|
||||
if(hdr.filesize > (16<<20)) goto error; // sanity check... don't load files bigger than 16 MB
|
||||
buf = new (false) uchar[hdr.filesize];
|
||||
try {
|
||||
buf = new uchar[hdr.filesize];
|
||||
} catch (...) {
|
||||
goto error;
|
||||
}
|
||||
if(!buf || f->read(buf + sizeof(hdr), hdr.filesize - sizeof(hdr)) != hdr.filesize - sizeof(hdr)) goto error;
|
||||
|
||||
if(doloadmesh && !loadiqmmeshes(filename, hdr, buf)) goto error;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "octaedit.hh"
|
||||
|
||||
#include <new>
|
||||
|
||||
#include <shared/command.hh>
|
||||
#include <shared/glemu.hh>
|
||||
#include <shared/igame.hh>
|
||||
|
@ -671,9 +673,12 @@ static block3 *blockcopy(const block3 &s, int rgrid)
|
|||
{
|
||||
int bsize = sizeof(block3)+sizeof(cube)*s.size();
|
||||
if(bsize <= 0 || bsize > (100<<20)) return nullptr;
|
||||
block3 *b = (block3 *)new (false) uchar[bsize];
|
||||
if(b) blockcopy(s, rgrid, b);
|
||||
return b;
|
||||
try {
|
||||
auto *b = (block3 *)new uchar[bsize];
|
||||
blockcopy(s, rgrid, b);
|
||||
return b;
|
||||
} catch (...) {}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void freeblock(block3 *b, bool alloced = true)
|
||||
|
@ -789,8 +794,12 @@ static undoblock *newundocube(const selinfo &s)
|
|||
selgridsize = ssize,
|
||||
blocksize = sizeof(block3)+ssize*sizeof(cube);
|
||||
if(blocksize <= 0 || blocksize > (undomegs<<20)) return nullptr;
|
||||
undoblock *u = (undoblock *)new (false) uchar[sizeof(undoblock) + blocksize + selgridsize];
|
||||
if(!u) return nullptr;
|
||||
undoblock *u = nullptr;
|
||||
try {
|
||||
u = (undoblock *)new uchar[sizeof(undoblock) + blocksize + selgridsize];
|
||||
} catch (...) {
|
||||
return nullptr;
|
||||
}
|
||||
u->numents = 0;
|
||||
block3 *b = u->block();
|
||||
blockcopy(s, -s.grid, b);
|
||||
|
@ -995,8 +1004,11 @@ static bool unpackblock(block3 *&b, B &buf)
|
|||
lilswap(&hdr.grid, 1);
|
||||
lilswap(&hdr.orient, 1);
|
||||
if(hdr.size() > (1<<20) || hdr.grid <= 0 || hdr.grid > (1<<12)) return false;
|
||||
b = (block3 *)new (false) uchar[sizeof(block3)+hdr.size()*sizeof(cube)];
|
||||
if(!b) return false;
|
||||
try {
|
||||
b = (block3 *)new uchar[sizeof(block3)+hdr.size()*sizeof(cube)];
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
*b = hdr;
|
||||
cube *c = b->c();
|
||||
memset(c, 0, b->size()*sizeof(cube));
|
||||
|
@ -1052,8 +1064,12 @@ static bool compresseditinfo(const uchar *inbuf, int inlen, uchar *&outbuf, int
|
|||
{
|
||||
uLongf len = compressBound(inlen);
|
||||
if(len > (1<<20)) return false;
|
||||
outbuf = new (false) uchar[len];
|
||||
if(!outbuf || compress2((Bytef *)outbuf, &len, (const Bytef *)inbuf, inlen, Z_BEST_COMPRESSION) != Z_OK || len > (1<<16))
|
||||
try {
|
||||
outbuf = new uchar[len];
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
if(compress2((Bytef *)outbuf, &len, (const Bytef *)inbuf, inlen, Z_BEST_COMPRESSION) != Z_OK || len > (1<<16))
|
||||
{
|
||||
delete[] outbuf;
|
||||
outbuf = nullptr;
|
||||
|
@ -1067,8 +1083,12 @@ static bool uncompresseditinfo(const uchar *inbuf, int inlen, uchar *&outbuf, in
|
|||
{
|
||||
if(compressBound(outlen) > (1<<20)) return false;
|
||||
uLongf len = outlen;
|
||||
outbuf = new (false) uchar[len];
|
||||
if(!outbuf || uncompress((Bytef *)outbuf, &len, (const Bytef *)inbuf, inlen) != Z_OK)
|
||||
try {
|
||||
outbuf = new uchar[len];
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
if(uncompress((Bytef *)outbuf, &len, (const Bytef *)inbuf, inlen) != Z_OK)
|
||||
{
|
||||
delete[] outbuf;
|
||||
outbuf = nullptr;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "rendermodel.hh"
|
||||
|
||||
#include <new>
|
||||
|
||||
#include <shared/command.hh>
|
||||
#include <shared/glemu.hh>
|
||||
#include <shared/igame.hh>
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "worldio.hh"
|
||||
|
||||
#include <new>
|
||||
|
||||
#include <shared/command.hh>
|
||||
#include <shared/igame.hh>
|
||||
|
||||
|
@ -500,8 +502,12 @@ static void loadvslot(stream *f, VSlot &vs, int changed)
|
|||
|
||||
static void loadvslots(stream *f, int numvslots)
|
||||
{
|
||||
int *prev = new (false) int[numvslots];
|
||||
if(!prev) return;
|
||||
int *prev;
|
||||
try {
|
||||
prev = new int[numvslots];
|
||||
} catch (...) {
|
||||
return;
|
||||
}
|
||||
memset(prev, -1, numvslots*sizeof(int));
|
||||
while(numvslots > 0)
|
||||
{
|
||||
|
|
|
@ -4,38 +4,6 @@
|
|||
|
||||
#include <ctime>
|
||||
|
||||
void *operator new(size_t size)
|
||||
{
|
||||
void *p = malloc(size);
|
||||
if(!p) abort();
|
||||
return p;
|
||||
}
|
||||
|
||||
void *operator new[](size_t size)
|
||||
{
|
||||
void *p = malloc(size);
|
||||
if(!p) abort();
|
||||
return p;
|
||||
}
|
||||
|
||||
void operator delete(void *p) { if(p) free(p); }
|
||||
|
||||
void operator delete[](void *p) { if(p) free(p); }
|
||||
|
||||
void *operator new(size_t size, bool err)
|
||||
{
|
||||
void *p = malloc(size);
|
||||
if(!p && err) abort();
|
||||
return p;
|
||||
}
|
||||
|
||||
void *operator new[](size_t size, bool err)
|
||||
{
|
||||
void *p = malloc(size);
|
||||
if(!p && err) abort();
|
||||
return p;
|
||||
}
|
||||
|
||||
////////////////////////// strings ////////////////////////////////////////
|
||||
|
||||
static string tmpstr[4];
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include <cstring>
|
||||
#include <cmath>
|
||||
|
||||
#include <new>
|
||||
|
||||
#include <SDL.h>
|
||||
#include <zlib.h>
|
||||
|
||||
|
@ -36,13 +38,6 @@ typedef unsigned long long int ullong;
|
|||
#define UNUSED
|
||||
#endif
|
||||
|
||||
void *operator new(size_t, bool);
|
||||
void *operator new[](size_t, bool);
|
||||
inline void *operator new(size_t, void *p) { return p; }
|
||||
inline void *operator new[](size_t, void *p) { return p; }
|
||||
inline void operator delete(void *, void *) {}
|
||||
inline void operator delete[](void *, void *) {}
|
||||
|
||||
#ifdef swap
|
||||
#undef swap
|
||||
#endif
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#include <new>
|
||||
|
||||
#include "command.hh"
|
||||
|
||||
#include <engine/console.hh> /* conoutf */
|
||||
|
@ -1220,8 +1222,13 @@ char *loadfile(const char *fn, size_t *size, bool utf8)
|
|||
stream::offset fsize = f->size();
|
||||
if(fsize <= 0) { delete f; return nullptr; }
|
||||
size_t len = fsize;
|
||||
char *buf = new (false) char[len+1];
|
||||
if(!buf) { delete f; return nullptr; }
|
||||
char *buf;
|
||||
try {
|
||||
buf = new char[len + 1];
|
||||
} catch (...) {
|
||||
delete f;
|
||||
return nullptr;
|
||||
}
|
||||
size_t offset = 0;
|
||||
if(utf8 && len >= 3)
|
||||
{
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#include <new>
|
||||
|
||||
#include "command.hh"
|
||||
|
||||
#include <engine/console.hh> /* conoutf */
|
||||
|
@ -117,7 +119,11 @@ VAR(dbgzip, 0, 0, 1);
|
|||
|
||||
static bool readzipdirectory(const char *archname, FILE *f, int entries, int offset, uint size, vector<zipfile> &files)
|
||||
{
|
||||
uchar *buf = new (false) uchar[size], *src = buf;
|
||||
uchar *buf = nullptr;
|
||||
try {
|
||||
buf = new uchar[size];
|
||||
} catch (...) {}
|
||||
uchar *src = buf;
|
||||
if(!buf || fseek(f, offset, SEEK_SET) < 0 || fread(buf, 1, size, f) != size) { delete[] buf; return false; }
|
||||
loopi(entries)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue