Assign more suitable types and fix narrowing conversion warns.
[tinc] / src / invitation.c
index b2e35f9..3c23a17 100644 (file)
@@ -136,7 +136,7 @@ char *get_my_hostname() {
 
                if(s >= 0) {
                        send(s, request, sizeof(request) - 1, 0);
-                       int len = recv(s, line, sizeof(line) - 1, MSG_WAITALL);
+                       ssize_t len = recv(s, line, sizeof(line) - 1, MSG_WAITALL);
 
                        if(len > 0) {
                                line[len] = 0;
@@ -170,7 +170,7 @@ char *get_my_hostname() {
        // Check that the hostname is reasonable
        if(hostname) {
                for(char *p = hostname; *p; p++) {
-                       if(isalnum(*p) || *p == '-' || *p == '.' || *p == ':') {
+                       if(isalnum((uint8_t) *p) || *p == '-' || *p == '.' || *p == ':') {
                                continue;
                        }
 
@@ -216,7 +216,7 @@ again:
        }
 
        for(char *p = line; *p; p++) {
-               if(isalnum(*p) || *p == '-' || *p == '.') {
+               if(isalnum((uint8_t) *p) || *p == '-' || *p == '.') {
                        continue;
                }
 
@@ -457,7 +457,7 @@ int cmd_invite(int argc, char *argv[]) {
        randomize(cookie, 18);
 
        // Create a filename that doesn't reveal the cookie itself
-       char buf[18 + strlen(fingerprint)];
+       uint8_t buf[18 + strlen(fingerprint)];
        char cookiehash[64];
        memcpy(buf, cookie, 18);
        memcpy(buf + 18, fingerprint, sizeof(buf) - 18);
@@ -572,7 +572,7 @@ static char *get_line(const char **data) {
                return NULL;
        }
 
-       if(len && !isprint(**data)) {
+       if(len && !isprint((uint8_t) **data)) {
                abort();
        }
 
@@ -615,7 +615,7 @@ static char *grep(const char *data, const char *var) {
        static char value[1024];
 
        const char *p = data;
-       int varlen = strlen(var);
+       size_t varlen = strlen(var);
 
        // Skip all lines not starting with var
        while(strncasecmp(p, var, varlen) || !strchr(" \t=", p[varlen])) {
@@ -781,7 +781,7 @@ make_names:
                }
 
                // Split line into variable and value
-               int len = strcspn(l, "\t =");
+               size_t len = strcspn(l, "\t =");
                value = l + len;
                value += strspn(value, "\t ");
 
@@ -886,7 +886,7 @@ make_names:
                                continue;
                        }
 
-                       int len = strcspn(l, "\t =");
+                       size_t len = strcspn(l, "\t =");
 
                        if(len == 4 && !strncasecmp(l, "Name", 4)) {
                                value = l + len;
@@ -1087,10 +1087,10 @@ ask_netname:
 static bool invitation_send(void *handle, uint8_t type, const void *vdata, size_t len) {
        (void)handle;
        (void)type;
-       const char *data = vdata;
+       const uint8_t *data = vdata;
 
        while(len) {
-               int result = send(sock, data, len, 0);
+               ssize_t result = send(sock, data, len, 0);
 
                if(result == -1 && sockwouldblock(sockerrno)) {
                        continue;
@@ -1286,7 +1286,7 @@ next:
        fprintf(stderr, "Connected to %s port %s...\n", address, port);
 
        // Tell him we have an invitation, and give him our throw-away key.
-       int len = snprintf(line, sizeof(line), "0 ?%s %d.%d\n", b64key, PROT_MAJOR, PROT_MINOR);
+       ssize_t len = snprintf(line, sizeof(line), "0 ?%s %d.%d\n", b64key, PROT_MAJOR, PROT_MINOR);
 
        if(len <= 0 || (size_t)len >= sizeof(line)) {
                abort();
@@ -1368,13 +1368,13 @@ next:
                char *p = line;
 
                while(len) {
-                       int done = sptps_receive_data(&sptps, p, len);
+                       size_t done = sptps_receive_data(&sptps, p, len);
 
                        if(!done) {
                                return 1;
                        }
 
-                       len -= done;
+                       len -= (ssize_t) done;
                        p += done;
                }
        }