Fix all -Wconversion warnings

This commit is contained in:
Alex Hultman
2019-12-28 21:19:15 +01:00
parent 5d83b427f5
commit f274d63dca
11 changed files with 42 additions and 42 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
EXAMPLE_FILES := HelloWorld EchoServer BroadcastingEchoServer
THREADED_EXAMPLE_FILES := HelloWorldThreaded EchoServerThreaded
override CXXFLAGS += -lpthread -std=c++17 -Isrc -IuSockets/src
override CXXFLAGS += -lpthread -Wconversion -std=c++17 -Isrc -IuSockets/src
override LDFLAGS += uSockets/*.o -lz
# WITH_OPENSSL=1 enables OpenSSL 1.1+ support
+3 -3
View File
@@ -82,7 +82,7 @@ protected:
LoopData *loopData = getLoopData();
if (loopData->corkedSocket == this && loopData->corkOffset + size < LoopData::CORK_BUFFER_SIZE) {
char *sendBuffer = loopData->corkBuffer + loopData->corkOffset;
loopData->corkOffset += size;
loopData->corkOffset += (int) size;
return {sendBuffer, false};
} else {
/* Slow path for now, we want to always be corked if possible */
@@ -92,7 +92,7 @@ protected:
/* Returns the user space backpressure. */
int getBufferedAmount() {
return getAsyncSocketData()->buffer.size();
return (int) getAsyncSocketData()->buffer.size();
}
/* Returns the remote IP address or empty string on failure */
@@ -118,7 +118,7 @@ protected:
/* We are limited if we have a per-socket buffer */
if (asyncSocketData->buffer.length()) {
/* Write off as much as we can */
int written = us_socket_write(SSL, (us_socket_t *) this, asyncSocketData->buffer.data(), asyncSocketData->buffer.length(), /*nextLength != 0 | */length);
int written = us_socket_write(SSL, (us_socket_t *) this, asyncSocketData->buffer.data(), (int) asyncSocketData->buffer.length(), /*nextLength != 0 | */length);
/* On failure return, otherwise continue down the function */
if ((unsigned int) written < asyncSocketData->buffer.length()) {
+6 -6
View File
@@ -150,7 +150,7 @@ private:
if (*postPaddedBuffer == '\r') {
if ((postPaddedBuffer != end) & (postPaddedBuffer[1] == '\n') & (i > 0)) {
headers->key = std::string_view(nullptr, 0);
return (postPaddedBuffer + 2) - start;
return (unsigned int) ((postPaddedBuffer + 2) - start);
} else {
return 0;
}
@@ -182,11 +182,11 @@ private:
length -= consumed;
consumedTotal += consumed;
req->headers->value = std::string_view(req->headers->value.data(), std::max<int>(0, req->headers->value.length() - 9));
req->headers->value = std::string_view(req->headers->value.data(), std::max<int>(0, (int) req->headers->value.length() - 9));
/* Parse query */
const char *querySeparatorPtr = (const char *) memchr(req->headers->value.data(), '?', req->headers->value.length());
req->querySeparator = (querySeparatorPtr ? querySeparatorPtr : req->headers->value.data() + req->headers->value.length()) - req->headers->value.data();
req->querySeparator = (int) ((querySeparatorPtr ? querySeparatorPtr : req->headers->value.data() + req->headers->value.length()) - req->headers->value.data());
/* If returned socket is not what we put in we need
* to break here as we either have upgraded to
@@ -257,16 +257,16 @@ public:
}
} else if (fallback.length()) {
int had = fallback.length();
int had = (int) fallback.length();
int maxCopyDistance = std::min(MAX_FALLBACK_SIZE - fallback.length(), (size_t) length);
int maxCopyDistance = (int) std::min(MAX_FALLBACK_SIZE - fallback.length(), (size_t) length);
/* We don't want fallback to be short string optimized, since we want to move it */
fallback.reserve(fallback.length() + maxCopyDistance + std::max<int>(MINIMUM_HTTP_POST_PADDING, sizeof(std::string)));
fallback.append(data, maxCopyDistance);
// break here on break
std::pair<int, void *> consumed = fenceAndConsumePostPadded<true>(fallback.data(), fallback.length(), user, &req, requestHandler, dataHandler);
std::pair<int, void *> consumed = fenceAndConsumePostPadded<true>(fallback.data(), (int) fallback.length(), user, &req, requestHandler, dataHandler);
if (consumed.second != user) {
return consumed.second;
}
+11 -11
View File
@@ -88,7 +88,7 @@ private:
/* If no total size given then assume this chunk is everything */
if (!totalSize) {
totalSize = data.length();
totalSize = (int) data.length();
}
HttpResponseData<SSL> *httpResponseData = getHttpResponseData();
@@ -99,11 +99,11 @@ private:
/* Do not allow sending 0 chunk here */
if (data.length()) {
Super::write("\r\n", 2);
writeUnsignedHex(data.length());
writeUnsignedHex((unsigned int) data.length());
Super::write("\r\n", 2);
/* Ignoring optional for now */
Super::write(data.data(), data.length());
Super::write(data.data(), (int) data.length());
}
/* Terminating 0 chunk */
@@ -138,7 +138,7 @@ private:
* if it failed to drain any prior failed header writes */
/* Write as much as possible without causing backpressure */
auto [written, failed] = Super::write(data.data(), data.length(), optional);
auto [written, failed] = Super::write(data.data(), (int) data.length(), optional);
httpResponseData->offset += written;
/* Success is when we wrote the entire thing without any failures */
@@ -185,7 +185,7 @@ public:
httpResponseData->state |= HttpResponseData<SSL>::HTTP_STATUS_CALLED;
Super::write("HTTP/1.1 ", 9);
Super::write(status.data(), status.length());
Super::write(status.data(), (int) status.length());
Super::write("\r\n", 2);
return this;
}
@@ -194,16 +194,16 @@ public:
HttpResponse *writeHeader(std::string_view key, std::string_view value) {
writeStatus(HTTP_200_OK);
Super::write(key.data(), key.length());
Super::write(key.data(), (int) key.length());
Super::write(": ", 2);
Super::write(value.data(), value.length());
Super::write(value.data(), (int) value.length());
Super::write("\r\n", 2);
return this;
}
/* Write an HTTP header with unsigned int value */
HttpResponse *writeHeader(std::string_view key, unsigned int value) {
Super::write(key.data(), key.length());
Super::write(key.data(), (int) key.length());
Super::write(": ", 2);
writeUnsigned(value);
Super::write("\r\n", 2);
@@ -212,7 +212,7 @@ public:
/* End the response with an optional data chunk. Always starts a timeout. */
void end(std::string_view data = {}) {
internalEnd(data, data.length(), false);
internalEnd(data, (int) data.length(), false);
}
/* Try and end the response. Returns [true, true] on success.
@@ -242,10 +242,10 @@ public:
}
Super::write("\r\n", 2);
writeUnsignedHex(data.length());
writeUnsignedHex((unsigned int) data.length());
Super::write("\r\n", 2);
auto [written, failed] = Super::write(data.data(), data.length());
auto [written, failed] = Super::write(data.data(), (int) data.length());
if (failed) {
Super::timeout(HTTP_TIMEOUT_S);
}
+2 -2
View File
@@ -107,7 +107,7 @@ private:
/* Set URL for router. Will reset any URL cache */
inline void setUrl(std::string_view url) {
/* Remove / from input URL */
currentUrl = url.substr(std::min<unsigned int>(url.length(), 1));
currentUrl = url.substr(std::min<unsigned int>((unsigned int) url.length(), 1));
urlSegmentTop = -1;
}
@@ -230,7 +230,7 @@ public:
node = getNode(node, std::string(getUrlSegment(i)));
}
/* Insert handler in order sorted by priority (most significant 1 byte) */
node->handlers.insert(std::upper_bound(node->handlers.begin(), node->handlers.end(), priority | handlers.size()), priority | handlers.size());
node->handlers.insert(std::upper_bound(node->handlers.begin(), node->handlers.end(), (uint32_t) (priority | handlers.size())), (uint32_t) (priority | handlers.size()));
}
/* Alloate this handler */
+3 -3
View File
@@ -34,7 +34,7 @@ inline int u32toaHex(uint32_t value, char *dst) {
value /= 16;
} while (value > 0);
int ret = p - temp;
int ret = (int) (p - temp);
do {
*dst++ = *--p;
@@ -47,11 +47,11 @@ inline int u32toa(uint32_t value, char *dst) {
char temp[10];
char *p = temp;
do {
*p++ = (char) (value % 10) + '0';
*p++ = (char) ((value % 10) + '0');
value /= 10;
} while (value > 0);
int ret = p - temp;
int ret = (int) (p - temp);
do {
*dst++ = *--p;
+3 -3
View File
@@ -84,7 +84,7 @@ public:
auto[sendBuffer, requiresWrite] = Super::getSendBuffer(messageFrameSize);
protocol::formatMessage<isServer>(sendBuffer, message.data(), message.length(), opCode, message.length(), compress);
if (requiresWrite) {
auto[written, failed] = Super::write(sendBuffer, messageFrameSize);
auto[written, failed] = Super::write(sendBuffer, (int) messageFrameSize);
/* For now, we are slow here (fix!) */
free(sendBuffer);
@@ -110,9 +110,9 @@ public:
/* Format and send the close frame */
static const int MAX_CLOSE_PAYLOAD = 123;
int length = std::min<size_t>(MAX_CLOSE_PAYLOAD, message.length());
int length = (int) std::min<size_t>(MAX_CLOSE_PAYLOAD, message.length());
char closePayload[MAX_CLOSE_PAYLOAD + 2];
int closePayloadLength = protocol::formatClosePayload(closePayload, code, message.data(), length);
int closePayloadLength = (int) protocol::formatClosePayload(closePayload, (uint16_t) code, message.data(), length);
bool ok = send(std::string_view(closePayload, closePayloadLength), OpCode::CLOSE);
/* FIN if we are ok and not corked */
+1 -1
View File
@@ -179,7 +179,7 @@ private:
} else {
/* Here we never mind any size optimizations as we are in the worst possible path */
webSocketData->fragmentBuffer.append(data, length);
webSocketData->controlTipLength += length;
webSocketData->controlTipLength += (int) length;
if (!remainingBytes && fin) {
char *controlBuffer = (char *) webSocketData->fragmentBuffer.data() + webSocketData->fragmentBuffer.length() - webSocketData->controlTipLength;
+1 -1
View File
@@ -57,7 +57,7 @@ struct WebSocketContextData {
/* We rely on writing to regular asyncSockets */
auto *asyncSocket = (AsyncSocket<SSL> *) s->user;
auto [written, failed] = asyncSocket->write(data.data(), data.length());
auto [written, failed] = asyncSocket->write(data.data(), (int) data.length());
if (!failed) {
asyncSocket->timeout(this->idleTimeout);
} else {
+4 -4
View File
@@ -120,10 +120,10 @@ public:
for (int i = 0; i < 5; i++) {
uint32_t tmp = b_output[i];
char *bytes = (char *) &b_output[i];
bytes[3] = tmp & 0xff;
bytes[2] = (tmp >> 8) & 0xff;
bytes[1] = (tmp >> 16) & 0xff;
bytes[0] = (tmp >> 24) & 0xff;
bytes[3] = (char) (tmp & 0xff);
bytes[2] = (char) ((tmp >> 8) & 0xff);
bytes[1] = (char) ((tmp >> 16) & 0xff);
bytes[0] = (char) ((tmp >> 24) & 0xff);
}
base64((unsigned char *) b_output, output);
}
+7 -7
View File
@@ -189,23 +189,23 @@ static inline size_t formatMessage(char *dst, const char *src, size_t length, Op
size_t headerLength;
if (reportedLength < 126) {
headerLength = 2;
dst[1] = reportedLength;
dst[1] = (char) reportedLength;
} else if (reportedLength <= UINT16_MAX) {
headerLength = 4;
dst[1] = 126;
uint16_t tmp = cond_byte_swap<uint16_t>(reportedLength);
uint16_t tmp = cond_byte_swap<uint16_t>((uint16_t) reportedLength);
memcpy(&dst[2], &tmp, sizeof(uint16_t));
} else {
headerLength = 10;
dst[1] = 127;
uint64_t tmp = cond_byte_swap<uint64_t>(reportedLength);
uint64_t tmp = cond_byte_swap<uint64_t>((uint64_t) reportedLength);
memcpy(&dst[2], &tmp, sizeof(uint64_t));
}
int flags = 0;
dst[0] = (flags & SND_NO_FIN ? 0 : 128) | (compressed ? SND_COMPRESSED : 0);
dst[0] = (char) ((flags & SND_NO_FIN ? 0 : 128) | (compressed ? SND_COMPRESSED : 0));
if (!(flags & SND_CONTINUATION)) {
dst[0] |= opCode;
dst[0] |= (char) opCode;
}
char mask[4];
@@ -320,7 +320,7 @@ protected:
}
src += payLength + MESSAGE_HEADER;
length -= payLength + MESSAGE_HEADER;
length -= (unsigned int) (payLength + MESSAGE_HEADER);
wState->state.spillLength = 0;
return false;
} else {
@@ -419,7 +419,7 @@ public:
}
if (length) {
memcpy(wState->state.spill, src, length);
wState->state.spillLength = length;
wState->state.spillLength = length & 0xf;
}
} else if (consumeContinuation(src, length, wState, user)) {
goto parseNext;