From 43134f01d3bcf7d5abe6c84c297faf1372e38bda Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 6 Oct 2022 14:33:30 +0300 Subject: uint8_t is far more kosher than char considering binary buffers --- src/mir_app/src/netlib_http.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/mir_app') diff --git a/src/mir_app/src/netlib_http.cpp b/src/mir_app/src/netlib_http.cpp index a93caf7116..7c94db57ca 100644 --- a/src/mir_app/src/netlib_http.cpp +++ b/src/mir_app/src/netlib_http.cpp @@ -777,7 +777,7 @@ MIR_APP_DLL(NETLIBHTTPREQUEST*) Netlib_RecvHttpHeaders(HNETLIBCONN hConnection, nlhr->headers = (NETLIBHTTPHEADER*)mir_calloc(sizeof(NETLIBHTTPHEADER) * headersCount); headersCount = 0; - for (char *pbuffer = buf.data();; headersCount++) { + for (char *pbuffer = (char*)buf.data();; headersCount++) { char *peol = strchr(pbuffer, '\n'); if (peol == nullptr || peol == pbuffer || (peol == (pbuffer+1) && *pbuffer == '\r')) break; @@ -970,22 +970,23 @@ static int NetlibHttpRecvChunkHeader(NetlibConnection *nlc, bool first, uint32_t buf.append(data, recvResult); // add chunk - const char *peol1 = (const char*)memchr(buf.data(), '\n', buf.length()); + auto *peol1 = (const char*)memchr(buf.data(), '\n', buf.length()); if (peol1 == nullptr) continue; - int cbRest = int(peol1 - buf.data()) + 1; + auto *pStart = (const char *)buf.data(); + int cbRest = int(peol1 - pStart) + 1; const char *peol2 = first ? peol1 : (const char*)memchr(peol1 + 1, '\n', buf.length() - cbRest); if (peol2 == nullptr) continue; - int sz = peol2 - buf.data() + 1; - int r = strtol(first ? buf.data() : peol1 + 1, nullptr, 16); + int sz = peol2 - pStart + 1; + int r = strtol(first ? pStart : peol1 + 1, nullptr, 16); if (r == 0) { const char *peol3 = strchr(peol2 + 1, '\n'); if (peol3 == nullptr) continue; - sz = peol3 - buf.data() + 1; + sz = peol3 - pStart + 1; } buf.remove(sz); // remove all our data from buffer nlc->foreBuf.appendBefore(buf.data(), buf.length()); -- cgit v1.2.3