From 430b8f9fb4bf696ba2df6f079853c9c232ee6fb3 Mon Sep 17 00:00:00 2001 From: Mandar <01.mandar@gmail.com> Date: Fri, 10 Jun 2016 12:25:02 +0530 Subject: [PATCH] Fix for crash in listening process --- Client-C++/Worker.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Client-C++/Worker.cpp b/Client-C++/Worker.cpp index a2592d7..f8f6f00 100644 --- a/Client-C++/Worker.cpp +++ b/Client-C++/Worker.cpp @@ -10,12 +10,17 @@ void Worker::run() char len[4]; cin.read(len, 4); unsigned int ilen = *reinterpret_cast(len); - char *inMsg = new char[ilen]; - memset(inMsg,0,ilen+1); - cin.read(inMsg, ilen); - string inStr(inMsg); - delete[] inMsg; - QString sline(inStr.c_str()); - emit UpdateMessage(sline); + if(ilen<1024 && ilen>1) + { + char *inMsg = new char[ilen]; + memset(inMsg,0,ilen+1); + cin.read(inMsg, ilen); + string inStr(inMsg); + delete[] inMsg; + QString sline(inStr.c_str()); + emit UpdateMessage(sline); + }else{ + QThread::msleep(1000); + } }while(true); }