From: Matt Ranostay Date: Thu, 31 Oct 2019 13:59:00 +0000 (-0700) Subject: poi-yelp: don't use fixed buffer size X-Git-Tag: 8.99.1~2 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F64%2F22764%2F3;p=apps%2Fpoi-yelp.git poi-yelp: don't use fixed buffer size Use QByteArray over arbitrary buffer size for QNetworkReply Bug-AGL: SPEC-2880 Change-Id: I65f04603afc22ef2f8ae5cfe97f747dda85e692d Signed-off-by: Matt Ranostay --- diff --git a/MainApp.cpp b/MainApp.cpp index cbf6d57..bb2ffc6 100644 --- a/MainApp.cpp +++ b/MainApp.cpp @@ -24,7 +24,6 @@ #define URL_AUTOCOMPLETE "https://api.yelp.com/v3/autocomplete" #define URL_SEARCH "https://api.yelp.com/v3/businesses/search" -#define BIG_BUFFER_SIZE (1024*1024) #define LEFT_OFFSET 28 #define FONT_SIZE_LINEDIT 20 #define FONT_SIZE_LIST 18 @@ -629,8 +628,7 @@ void MainApp::DisplayInformation(bool display, bool RefreshDisplay) void MainApp::networkReplySearch(QNetworkReply* reply) { - char buf[BIG_BUFFER_SIZE]; - int buflen; + QByteArray buf; mutex.lock(); @@ -647,10 +645,9 @@ void MainApp::networkReplySearch(QNetworkReply* reply) return; } - buflen = reply->read(buf, BIG_BUFFER_SIZE-1); - buf[buflen] = '\0'; + buf = reply->readAll(); - if (buflen == 0) + if (buf.isEmpty()) { mutex.unlock(); return; @@ -660,7 +657,7 @@ void MainApp::networkReplySearch(QNetworkReply* reply) currentIndex = 0; Businesses.clear(); - ParseJsonBusinessList(buf, Businesses); + ParseJsonBusinessList(buf.data(), Businesses); DisplayResultList(true); FillResultList(Businesses); }