Commit bf2470ce authored by Christian Beier's avatar Christian Beier

Check rfbGetScreen() return value everywhere.

This fixes a segfault when a server is invoked with the
'-help' commandline argument.
parent 6b60690a
...@@ -121,6 +121,8 @@ static rfbBool malloc_frame_buffer(rfbClient* cl) ...@@ -121,6 +121,8 @@ static rfbBool malloc_frame_buffer(rfbClient* cl)
res->client->frameBuffer=malloc(w*4*h); res->client->frameBuffer=malloc(w*4*h);
res->server=rfbGetScreen(NULL,NULL,w,h,8,3,4); res->server=rfbGetScreen(NULL,NULL,w,h,8,3,4);
if(!res->server)
return FALSE;
res->server->screenData=res; res->server->screenData=res;
res->server->port=res->listen_port; res->server->port=res->listen_port;
res->server->frameBuffer=res->client->frameBuffer; res->server->frameBuffer=res->client->frameBuffer;
......
...@@ -107,6 +107,8 @@ int main(int argc,char** argv) ...@@ -107,6 +107,8 @@ int main(int argc,char** argv)
rfbRegisterProtocolExtension(&backChannelExtension); rfbRegisterProtocolExtension(&backChannelExtension);
server=rfbGetScreen(&argc,argv,400,300,8,3,4); server=rfbGetScreen(&argc,argv,400,300,8,3,4);
if(!server)
return 0;
server->frameBuffer=(char*)malloc(400*300*4); server->frameBuffer=(char*)malloc(400*300*4);
rfbInitServer(server); rfbInitServer(server);
rfbRunEventLoop(server,-1,FALSE); rfbRunEventLoop(server,-1,FALSE);
......
...@@ -133,6 +133,8 @@ int main(int argc,char** argv) ...@@ -133,6 +133,8 @@ int main(int argc,char** argv)
long usec; long usec;
rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,WIDTH,HEIGHT,8,3,BPP); rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,WIDTH,HEIGHT,8,3,BPP);
if(!server)
return 0;
server->desktopName = "Live Video Feed Example"; server->desktopName = "Live Video Feed Example";
server->frameBuffer=(char*)malloc(WIDTH*HEIGHT*BPP); server->frameBuffer=(char*)malloc(WIDTH*HEIGHT*BPP);
server->alwaysShared=(1==1); server->alwaysShared=(1==1);
......
...@@ -7,7 +7,8 @@ int main(int argc,char** argv) ...@@ -7,7 +7,8 @@ int main(int argc,char** argv)
uint8_t bytes[256*3]; uint8_t bytes[256*3];
rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,256,256,8,1,1); rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,256,256,8,1,1);
if(!server)
return 0;
server->serverFormat.trueColour=FALSE; server->serverFormat.trueColour=FALSE;
server->colourMap.count=256; server->colourMap.count=256;
server->colourMap.is16=FALSE; server->colourMap.is16=FALSE;
......
...@@ -279,8 +279,9 @@ static void MakeRichCursor(rfbScreenInfoPtr rfbScreen) ...@@ -279,8 +279,9 @@ static void MakeRichCursor(rfbScreenInfoPtr rfbScreen)
int main(int argc,char** argv) int main(int argc,char** argv)
{ {
rfbScreenInfoPtr rfbScreen = rfbScreenInfoPtr rfbScreen = rfbGetScreen(&argc,argv,maxx,maxy,8,3,bpp);
rfbGetScreen(&argc,argv,maxx,maxy,8,3,bpp); if(!rfbScreen)
return 0;
rfbScreen->desktopName = "LibVNCServer Example"; rfbScreen->desktopName = "LibVNCServer Example";
rfbScreen->frameBuffer = (char*)malloc(maxx*maxy*bpp); rfbScreen->frameBuffer = (char*)malloc(maxx*maxy*bpp);
rfbScreen->alwaysShared = TRUE; rfbScreen->alwaysShared = TRUE;
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
int main(int argc,char** argv) int main(int argc,char** argv)
{ {
rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,400,300,8,3,4); rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,400,300,8,3,4);
if(!server)
return 0;
server->frameBuffer=(char*)malloc(400*300*4); server->frameBuffer=(char*)malloc(400*300*4);
rfbRegisterTightVNCFileTransferExtension(); rfbRegisterTightVNCFileTransferExtension();
rfbInitServer(server); rfbInitServer(server);
......
...@@ -41,6 +41,9 @@ int main(int argc,char** argv) ...@@ -41,6 +41,9 @@ int main(int argc,char** argv)
rfbScreenInfoPtr s=rfbGetScreen(&argc,argv,640,480,8,3,3); rfbScreenInfoPtr s=rfbGetScreen(&argc,argv,640,480,8,3,3);
int i,j; int i,j;
if(!s)
return 0;
s->frameBuffer=(char*)malloc(640*480*3); s->frameBuffer=(char*)malloc(640*480*3);
rfbInitServer(s); rfbInitServer(s);
......
...@@ -455,6 +455,8 @@ ScreenInit(int argc, char**argv) ...@@ -455,6 +455,8 @@ ScreenInit(int argc, char**argv)
CGDisplayPixelsHigh(kCGDirectMainDisplay), CGDisplayPixelsHigh(kCGDirectMainDisplay),
bitsPerSample, bitsPerSample,
CGDisplaySamplesPerPixel(kCGDirectMainDisplay),4); CGDisplaySamplesPerPixel(kCGDirectMainDisplay),4);
if(!rfbScreen)
exit(0);
rfbScreen->serverFormat.redShift = bitsPerSample*2; rfbScreen->serverFormat.redShift = bitsPerSample*2;
rfbScreen->serverFormat.greenShift = bitsPerSample*1; rfbScreen->serverFormat.greenShift = bitsPerSample*1;
rfbScreen->serverFormat.blueShift = 0; rfbScreen->serverFormat.blueShift = 0;
......
...@@ -65,6 +65,8 @@ int main(int argc,char** argv) ...@@ -65,6 +65,8 @@ int main(int argc,char** argv)
/* initialize data for vnc server */ /* initialize data for vnc server */
rfbScreen = rfbGetScreen(&argc,argv,paddedWidth,height,8,(bitsPerPixelInFile+7)/8,bytesPerPixel); rfbScreen = rfbGetScreen(&argc,argv,paddedWidth,height,8,(bitsPerPixelInFile+7)/8,bytesPerPixel);
if(!rfbScreen)
return 0;
if(argc>1) if(argc>1)
rfbScreen->desktopName = argv[1]; rfbScreen->desktopName = argv[1];
else else
......
...@@ -60,6 +60,8 @@ int main(int argc,char** argv) ...@@ -60,6 +60,8 @@ int main(int argc,char** argv)
/* initialize data for vnc server */ /* initialize data for vnc server */
rfbScreen = rfbGetScreen(&argc,argv,paddedWidth,height,8,3,3); rfbScreen = rfbGetScreen(&argc,argv,paddedWidth,height,8,3,3);
if(!rfbScreen)
return 0;
if(argc>1) if(argc>1)
rfbScreen->desktopName = argv[1]; rfbScreen->desktopName = argv[1];
else else
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
int main(int argc,char** argv) int main(int argc,char** argv)
{ {
rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,400,300,8,3,4); rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,400,300,8,3,4);
if(!server)
return 0;
server->frameBuffer=(char*)malloc(400*300*4); server->frameBuffer=(char*)malloc(400*300*4);
rfbInitServer(server); rfbInitServer(server);
rfbRunEventLoop(server,-1,FALSE); rfbRunEventLoop(server,-1,FALSE);
......
...@@ -9,7 +9,8 @@ int main(int argc,char** argv) ...@@ -9,7 +9,8 @@ int main(int argc,char** argv)
uint16_t* f; uint16_t* f;
rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,400,300,5,3,2); rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,400,300,5,3,2);
if(!server)
return 0;
server->frameBuffer=(char*)malloc(400*300*2); server->frameBuffer=(char*)malloc(400*300*2);
f=(uint16_t*)server->frameBuffer; f=(uint16_t*)server->frameBuffer;
for(j=0;j<300;j++) for(j=0;j<300;j++)
......
...@@ -112,6 +112,8 @@ static enum rfbNewClientAction newclient(rfbClientPtr cl) ...@@ -112,6 +112,8 @@ static enum rfbNewClientAction newclient(rfbClientPtr cl)
int main(int argc,char** argv) int main(int argc,char** argv)
{ {
rfbScreenInfoPtr s=rfbGetScreen(&argc,argv,width,height,8,1,1); rfbScreenInfoPtr s=rfbGetScreen(&argc,argv,width,height,8,1,1);
if(!s)
return 0;
s->colourMap.is16=FALSE; s->colourMap.is16=FALSE;
s->colourMap.count=2; s->colourMap.count=2;
s->colourMap.data.bytes=(unsigned char*)"\xd0\xd0\xd0\x30\x01\xe0"; s->colourMap.data.bytes=(unsigned char*)"\xd0\xd0\xd0\x30\x01\xe0";
......
...@@ -27,6 +27,8 @@ int main (int argc, char **argv) ...@@ -27,6 +27,8 @@ int main (int argc, char **argv)
return 1; return 1;
server = rfbGetScreen (&argc, argv, maxx, maxy, 8, 3, bpp); server = rfbGetScreen (&argc, argv, maxx, maxy, 8, 3, bpp);
if(!server)
return 0;
server->desktopName = "Zippy das wundersquirrel\'s VNC server"; server->desktopName = "Zippy das wundersquirrel\'s VNC server";
server->frameBuffer = (char*)malloc(maxx*maxy*bpp); server->frameBuffer = (char*)malloc(maxx*maxy*bpp);
server->alwaysShared = TRUE; server->alwaysShared = TRUE;
......
...@@ -10,6 +10,9 @@ int main(int argc,char** argv) ...@@ -10,6 +10,9 @@ int main(int argc,char** argv)
rfbBool ret=0; rfbBool ret=0;
screen = rfbGetScreen(&fake_argc,fake_argv,1024,768,8,3,1); screen = rfbGetScreen(&fake_argc,fake_argv,1024,768,8,3,1);
if(!screen)
return 0;
#define CHECK(a,b) if(screen->a!=b) { fprintf(stderr,#a " is %d (should be " #b ")\n",screen->a); ret=1; } #define CHECK(a,b) if(screen->a!=b) { fprintf(stderr,#a " is %d (should be " #b ")\n",screen->a); ret=1; }
CHECK(width,1024); CHECK(width,1024);
CHECK(height,768); CHECK(height,768);
......
...@@ -22,6 +22,8 @@ int main(int argc,char** argv) ...@@ -22,6 +22,8 @@ int main(int argc,char** argv)
double r,phi=0; double r,phi=0;
rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,width,height,8,3,4); rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,width,height,8,3,4);
if(!server)
return 0;
server->frameBuffer=(char*)malloc(width*height*4); server->frameBuffer=(char*)malloc(width*height*4);
initBackground(server); initBackground(server);
server->deferUpdateTime=0; server->deferUpdateTime=0;
......
...@@ -322,8 +322,10 @@ static void doptr(int buttonMask,int x,int y,rfbClientPtr cl) ...@@ -322,8 +322,10 @@ static void doptr(int buttonMask,int x,int y,rfbClientPtr cl)
int main(int argc,char** argv) int main(int argc,char** argv)
{ {
rfbScreenInfoPtr rfbScreen = rfbScreenInfoPtr rfbScreen = rfbGetScreen(&argc,argv,maxx,maxy,8,3,bpp);
rfbGetScreen(&argc,argv,maxx,maxy,8,3,bpp); if(!rfbScreen)
return 0;
rfbScreen->desktopName = "Cursor Test"; rfbScreen->desktopName = "Cursor Test";
rfbScreen->frameBuffer = (char*)malloc(maxx*maxy*bpp); rfbScreen->frameBuffer = (char*)malloc(maxx*maxy*bpp);
rfbScreen->ptrAddEvent = doptr; rfbScreen->ptrAddEvent = doptr;
......
...@@ -298,6 +298,8 @@ int main(int argc,char** argv) ...@@ -298,6 +298,8 @@ int main(int argc,char** argv)
/* Initialize server */ /* Initialize server */
server=rfbGetScreen(&argc,argv,width,height,8,3,4); server=rfbGetScreen(&argc,argv,width,height,8,3,4);
if(!server)
return 0;
server->frameBuffer=malloc(400*300*4); server->frameBuffer=malloc(400*300*4);
server->cursor=NULL; server->cursor=NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment