mirror of
https://github.com/glest/glest-source.git
synced 2025-08-21 07:31:21 +02:00
- updated code to protect against null pointers and uninitialized values and threading issues
This commit is contained in:
@@ -202,7 +202,7 @@ LOCAL int ftpCmdSyst(int sessionId, const char* args, int len)
|
||||
LOCAL int ftpCmdPort(int sessionId, const char* args, int len)
|
||||
{
|
||||
char clientIp[16];
|
||||
uint16_t clientPort;
|
||||
uint16_t clientPort=0;
|
||||
|
||||
int commaCnt = 0;
|
||||
int n;
|
||||
|
@@ -84,6 +84,9 @@ Pixmap2D* JPGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const
|
||||
if(bigEndianSystem == true) {
|
||||
Shared::PlatformByteOrder::fromEndianTypeArray<uint8>(buffer,(size_t)length);
|
||||
}
|
||||
if(length < 2) {
|
||||
throw megaglest_runtime_error("length < 2",true);
|
||||
}
|
||||
//Check buffer (weak jpeg check)
|
||||
//if (buffer[0] != 0x46 || buffer[1] != 0xA0) {
|
||||
// Proper header check found from: http://www.fastgraph.com/help/jpeg_header_format.html
|
||||
|
@@ -678,12 +678,14 @@ void PixmapIoJpg::write(uint8 *pixels) {
|
||||
if(components == 4) {
|
||||
int n = w * h;
|
||||
unsigned char *dst = tmpbytes = (unsigned char *) malloc(n*3);
|
||||
const unsigned char *src = pixels;
|
||||
for (int i = 0; i < n; i++) {
|
||||
*dst++ = *src++;
|
||||
*dst++ = *src++;
|
||||
*dst++ = *src++;
|
||||
src++;
|
||||
if(dst != NULL) {
|
||||
const unsigned char *src = pixels;
|
||||
for (int i = 0; i < n; i++) {
|
||||
*dst++ = *src++;
|
||||
*dst++ = *src++;
|
||||
*dst++ = *src++;
|
||||
src++;
|
||||
}
|
||||
}
|
||||
components = 3;
|
||||
}
|
||||
@@ -718,25 +720,29 @@ void PixmapIoJpg::write(uint8 *pixels) {
|
||||
// flip lines.
|
||||
uint8 *flip = (uint8 *)malloc(sizeof(uint8) * w * h * 3);
|
||||
|
||||
for (int y = 0;y < h; ++y) {
|
||||
for (int x = 0;x < w; ++x) {
|
||||
flip[(y * w + x) * 3] = pixels[((h - 1 - y) * w + x) * 3];
|
||||
flip[(y * w + x) * 3 + 1] = pixels[((h - 1 - y) * w + x) * 3 + 1];
|
||||
flip[(y * w + x) * 3 + 2] = pixels[((h - 1 - y) * w + x) * 3 + 2];
|
||||
if(pixels != NULL && flip != NULL) {
|
||||
for (int y = 0;y < h; ++y) {
|
||||
for (int x = 0;x < w; ++x) {
|
||||
flip[(y * w + x) * 3] = pixels[((h - 1 - y) * w + x) * 3];
|
||||
flip[(y * w + x) * 3 + 1] = pixels[((h - 1 - y) * w + x) * 3 + 1];
|
||||
flip[(y * w + x) * 3 + 2] = pixels[((h - 1 - y) * w + x) * 3 + 2];
|
||||
}
|
||||
}
|
||||
|
||||
/* like reading a file, this time write one row at a time */
|
||||
while( cinfo.next_scanline < cinfo.image_height ) {
|
||||
row_pointer[0] = &flip[ cinfo.next_scanline * cinfo.image_width * cinfo.input_components];
|
||||
jpeg_write_scanlines( &cinfo, row_pointer, 1 );
|
||||
}
|
||||
}
|
||||
|
||||
/* like reading a file, this time write one row at a time */
|
||||
while( cinfo.next_scanline < cinfo.image_height ) {
|
||||
row_pointer[0] = &flip[ cinfo.next_scanline * cinfo.image_width * cinfo.input_components];
|
||||
jpeg_write_scanlines( &cinfo, row_pointer, 1 );
|
||||
}
|
||||
if (tmpbytes) {
|
||||
free(tmpbytes);
|
||||
tmpbytes=NULL;
|
||||
}
|
||||
free(flip);
|
||||
flip=NULL;
|
||||
if(flip) {
|
||||
free(flip);
|
||||
flip=NULL;
|
||||
}
|
||||
|
||||
/* similar to read file, clean up after we're done compressing */
|
||||
jpeg_finish_compress( &cinfo );
|
||||
|
@@ -1413,7 +1413,12 @@ bool VideoPlayer::playFrame(bool swapBuffers) {
|
||||
}
|
||||
}
|
||||
|
||||
return ctxPtr->needToQuit;
|
||||
if(ctxPtr != NULL) {
|
||||
return ctxPtr->needToQuit;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void VideoPlayer::RestartVideo() {
|
||||
|
@@ -143,7 +143,8 @@ int connecthostport(const char * host, unsigned short port,
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_family = AF_UNSPEC; /* AF_INET, AF_INET6 or AF_UNSPEC */
|
||||
/* hints.ai_protocol = IPPROTO_TCP; */
|
||||
snprintf(port_str, sizeof(port_str), "%hu", port);
|
||||
snprintf(port_str, 7, "%hu", port);
|
||||
port_str[7] = '\0';
|
||||
if(host[0] == '[')
|
||||
{
|
||||
/* literal ip v6 address */
|
||||
|
@@ -2465,7 +2465,7 @@ int UPNP_Tools::upnp_init(void *param) {
|
||||
}
|
||||
|
||||
dev = devlist;
|
||||
while (dev) {
|
||||
while (dev && dev->st) {
|
||||
if (strstr(dev->st, "InternetGatewayDevice")) {
|
||||
break;
|
||||
}
|
||||
|
@@ -297,6 +297,9 @@ int glob( char const *pattern
|
||||
cbAlloc = new_cbAlloc;
|
||||
}
|
||||
|
||||
if(buffer == NULL) {
|
||||
throw exception("buffer == NULL");
|
||||
}
|
||||
(void)lstrcpynA(buffer + cbCurr, szRelative, 1 + (int)(file_part - effectivePattern));
|
||||
(void)lstrcatA(buffer + cbCurr, sFileName.c_str());
|
||||
cbCurr += cch + 1;
|
||||
|
@@ -52,8 +52,8 @@ P5 = 4.1381369442e-08f; /* 0x3331bb4c */
|
||||
Simple x;
|
||||
#endif
|
||||
{
|
||||
Simple y,hi,lo,c,t;
|
||||
int32_t k,xsb;
|
||||
Simple y,hi,lo=0,c,t;
|
||||
int32_t k=0,xsb=0;
|
||||
u_int32_t hx;
|
||||
|
||||
GET_FLOAT_WORD(hx,x);
|
||||
|
@@ -301,6 +301,8 @@ static Simple pS2[5] = {
|
||||
else if(ix>=0x40f71c58){p = pR5; q= pS5;}
|
||||
else if(ix>=0x4036db68){p = pR3; q= pS3;}
|
||||
else if(ix>=0x40000000){p = pR2; q= pS2;}
|
||||
//else throw std::exception("unknown state for pointers p and q!");
|
||||
else throw "unknown state for pointers p and q!";
|
||||
z = one/(x*x);
|
||||
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
|
||||
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
|
||||
@@ -437,6 +439,8 @@ static Simple qS2[6] = {
|
||||
else if(ix>=0x40f71c58){p = qR5; q= qS5;}
|
||||
else if(ix>=0x4036db68){p = qR3; q= qS3;}
|
||||
else if(ix>=0x40000000){p = qR2; q= qS2;}
|
||||
//else throw std::exception("unknown state for pointer p!");
|
||||
else throw "unknown state for pointers p and q!";
|
||||
z = one/(x*x);
|
||||
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
|
||||
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
|
||||
|
@@ -300,6 +300,8 @@ static Simple ps2[5] = {
|
||||
else if(ix>=0x40f71c58){p = pr5; q= ps5;}
|
||||
else if(ix>=0x4036db68){p = pr3; q= ps3;}
|
||||
else if(ix>=0x40000000){p = pr2; q= ps2;}
|
||||
//else throw std::exception("unknown state for pointer p!");
|
||||
else throw "unknown state for pointers p and q!";
|
||||
z = one/(x*x);
|
||||
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
|
||||
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
|
||||
@@ -437,6 +439,8 @@ static Simple qs2[6] = {
|
||||
else if(ix>=0x40f71c58){p = qr5; q= qs5;}
|
||||
else if(ix>=0x4036db68){p = qr3; q= qs3;}
|
||||
else if(ix>=0x40000000){p = qr2; q= qs2;}
|
||||
//else throw std::exception("unknown state for pointer p!");
|
||||
else throw "unknown state for pointers p and q!";
|
||||
z = one/(x*x);
|
||||
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
|
||||
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
|
||||
|
@@ -218,12 +218,14 @@ namespace Shared { namespace Util {
|
||||
|
||||
|
||||
void strrev(char *p) {
|
||||
char *q = p;
|
||||
while(q && *q) ++q;
|
||||
for(--q; p < q; ++p, --q)
|
||||
*p = *p ^ *q,
|
||||
*q = *p ^ *q,
|
||||
*p = *p ^ *q;
|
||||
if(p != NULL) {
|
||||
char *q = p;
|
||||
while(q && *q) ++q;
|
||||
for(--q; p < q; ++p, --q)
|
||||
*p = *p ^ *q,
|
||||
*q = *p ^ *q,
|
||||
*p = *p ^ *q;
|
||||
}
|
||||
}
|
||||
|
||||
#define SWP(x,y) (x^=y, y^=x, x^=y)
|
||||
|
Reference in New Issue
Block a user