OSSP CVS Repository

ossp - Check-in [2917]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 2917
Date: 2002-Nov-28 16:42:29 (local)
2002-Nov-28 15:42:29 (UTC)
User:rse
Branch:
Comment: fix a few bugs, remove a lot of warnings; all found by splint
Tickets:
Inspections:
Files:
ossp-pkg/sa/sa.c      1.71 -> 1.72     123 inserted, 102 deleted
ossp-pkg/sa/sa.h      1.34 -> 1.35     2 inserted, 0 deleted

ossp-pkg/sa/sa.c 1.71 -> 1.72

--- sa.c 2002/11/14 08:54:00     1.71
+++ sa.c 2002/11/28 15:42:29     1.72
@@ -329,19 +329,19 @@
             if (c == '%') {
                 /* expand "%%" */
                 cp = &c;
-                n = sizeof(char);
+                n = (int)sizeof(char);
             }
             else if (c == 'c') {
                 /* expand "%c" */
                 c = (char)va_arg(ap, int);
                 cp = &c;
-                n = sizeof(char);
+                n = (int)sizeof(char);
             }
             else if (c == 's') {
                 /* expand "%s" */
                 if ((cp = (char *)va_arg(ap, char *)) == NULL)
                     cp = "(null)";
-                n = strlen(cp);
+                n = (int)strlen(cp);
             }
             else if (c == 'd') {
                 /* expand "%d" */
@@ -352,7 +352,7 @@
                 sprintf(ibuf, "%d", d);                /* implicitly secure */
 #endif
                 cp = ibuf;
-                n = strlen(cp);
+                n = (int)strlen(cp);
             }
             else {
                 /* any other "%X" */
@@ -366,11 +366,11 @@
             cp = (char *)format;
             if ((format = strchr(cp, '%')) == NULL)
                 format = strchr(cp, '\0');
-            n = format - cp;
+            n = (int)(format - cp);
         }
         /* perform output operation */
         if (output != NULL)
-            if ((n = output(ctx, cp, n)) == -1)
+            if ((n = output(ctx, cp, (size_t)n)) == -1)
                 break;
         bytes += n;
     }
@@ -393,7 +393,7 @@
     memcpy(ctx->bufptr, buffer, bufsize);
     ctx->bufptr += bufsize;
     ctx->buflen -= bufsize;
-    return bufsize;
+    return (int)bufsize;
 }
 
 /* minimal vsnprintf(3) variant which supports %{c,s,d} only */
@@ -497,7 +497,8 @@
     char uribuf[1024];
     char *cp;
     int i;
-    int n;
+    size_t n;
+    int k;
 
     /* argument sanity check(s) */
     if (saa == NULL || uri == NULL)
@@ -505,8 +506,10 @@
 
     /* on-the-fly create or just take over URI */
     va_start(ap, uri);
-    sa_mvsnprintf(uribuf, sizeof(uribuf), uri, ap);
+    k = sa_mvsnprintf(uribuf, sizeof(uribuf), uri, ap);
     va_end(ap);
+    if (k == -1)
+        return SA_RC(SA_ERR_MEM);
 
     /* initialize result variables */
     sa = NULL;
@@ -543,7 +546,7 @@
 
         /* provide results */
         sa = (struct sockaddr *)&un;
-        sl = sizeof(un);
+        sl = (socklen_t)sizeof(un);
         sf = AF_LOCAL;
     }
     else if (strncmp(uri, "inet://", 7) == 0) {
@@ -607,7 +610,7 @@
             sa4.sin_family = AF_INET;
             sa4.sin_port = htons(nPort);
             sa = (struct sockaddr *)&sa4;
-            sl = sizeof(sa4);
+            sl = (socklen_t)sizeof(sa4);
             sf = AF_INET;
         }
 #ifdef AF_INET6
@@ -615,7 +618,7 @@
             sa6.sin6_family = AF_INET6;
             sa6.sin6_port = htons(nPort);
             sa = (struct sockaddr *)&sa6;
-            sl = sizeof(sa6);
+            sl = (socklen_t)sizeof(sa6);
             sf = AF_INET6;
         }
 #endif
@@ -626,7 +629,7 @@
                 memcpy(&sa4.sin_addr.s_addr, he->h_addr_list[0],
                        sizeof(sa4.sin_addr.s_addr));
                 sa = (struct sockaddr *)&sa4;
-                sl = sizeof(sa4);
+                sl = (socklen_t)sizeof(sa4);
                 sf = AF_INET;
             }
 #ifdef AF_INET6
@@ -636,7 +639,7 @@
                 memcpy(&sa6.sin6_addr.s6_addr, he->h_addr_list[0],
                        sizeof(sa6.sin6_addr.s6_addr));
                 sa = (struct sockaddr *)&sa6;
-                sl = sizeof(sa6);
+                sl = (socklen_t)sizeof(sa6);
                 sf = AF_INET6;
             }
 #endif
@@ -652,11 +655,11 @@
     /* fill-in result address structure */
     if (saa->saBuf != NULL)
         free(saa->saBuf);
-    if ((saa->saBuf = (struct sockaddr *)malloc(sl)) == NULL)
+    if ((saa->saBuf = (struct sockaddr *)malloc((size_t)sl)) == NULL)
         return SA_RC(SA_ERR_MEM);
-    memcpy(saa->saBuf, sa, sl);
+    memcpy(saa->saBuf, sa, (size_t)sl);
     saa->slBuf = sl;
-    saa->nFamily = sf;
+    saa->nFamily = (int)sf;
 
     return SA_OK;
 }
@@ -680,13 +683,13 @@
     /* create result address structure */
     if (saa->saBuf != NULL)
         free(saa->saBuf);
-    if ((saa->saBuf = (struct sockaddr *)malloc(salen)) == NULL)
+    if ((saa->saBuf = (struct sockaddr *)malloc((size_t)salen)) == NULL)
         return SA_RC(SA_ERR_MEM);
-    memcpy(saa->saBuf, sabuf, salen);
+    memcpy(saa->saBuf, sabuf, (size_t)salen);
     saa->slBuf = salen;
 
     /* remember family */
-    saa->nFamily = sabuf->sa_family;
+    saa->nFamily = (int)(sabuf->sa_family);
 
     return SA_OK;
 }
@@ -712,27 +715,35 @@
         un = (struct sockaddr_un *)((void *)saa->saBuf);
         if (   (   saa->slBuf >= (socklen_t)(&(((struct sockaddr_un *)0)->sun_path[0]))
                 && un->sun_path[0] == '\0')
-            || saa->slBuf < sizeof(struct sockaddr_un))
+            || (size_t)(saa->slBuf) < sizeof(struct sockaddr_un)) {
             /* in case the remote side of a Unix Domain socket was not
                bound, a "struct sockaddr_un" can occur with a length less
                than the expected one. Then there is actually no path at all.
                This has been verified under FreeBSD, Linux and Solaris. */
-            sa_msnprintf(uribuf, sizeof(uribuf), "unix:/NOT-BOUND");
-        else
-            sa_msnprintf(uribuf, sizeof(uribuf), "unix:%s", un->sun_path);
+            if (sa_msnprintf(uribuf, sizeof(uribuf), "unix:/NOT-BOUND") == -1)
+                return SA_RC(SA_ERR_FMT);
+        }
+        else {
+            if (sa_msnprintf(uribuf, sizeof(uribuf), "unix:%s", un->sun_path) == -1)
+                return SA_RC(SA_ERR_FMT);
+        }
     }
     else if (saa->nFamily == AF_INET) {
         sa4 = (struct sockaddr_in *)((void *)saa->saBuf);
-        sa_inet_ntop(AF_INET, &sa4->sin_addr.s_addr, caHost, sizeof(caHost));
+        if (sa_inet_ntop(AF_INET, &sa4->sin_addr.s_addr, caHost, sizeof(caHost)) == NULL)
+            return SA_RC(SA_ERR_NET);
         nPort = ntohs(sa4->sin_port);
-        sa_msnprintf(uribuf, sizeof(uribuf), "inet://%s:%d", caHost, nPort);
+        if (sa_msnprintf(uribuf, sizeof(uribuf), "inet://%s:%d", caHost, nPort) == -1)
+            return SA_RC(SA_ERR_FMT);
     }
 #ifdef AF_INET6
     else if (saa->nFamily == AF_INET6) {
         sa6 = (struct sockaddr_in6 *)((void *)saa->saBuf);
-        sa_inet_ntop(AF_INET6, &sa6->sin6_addr.s6_addr, caHost, sizeof(caHost));
+        if (sa_inet_ntop(AF_INET6, &sa6->sin6_addr.s6_addr, caHost, sizeof(caHost)) == NULL)
+            return SA_RC(SA_ERR_NET);
         nPort = ntohs(sa6->sin6_port);
-        sa_msnprintf(uribuf, sizeof(uribuf), "inet://[%s]:%d", caHost, nPort);
+        if (sa_msnprintf(uribuf, sizeof(uribuf), "inet://[%s]:%d", caHost, nPort) == -1)
+            return SA_RC(SA_ERR_FMT);
     }
 #endif
     else
@@ -752,9 +763,9 @@
         return SA_RC(SA_ERR_ARG);
 
     /* export underlying address structure */
-    if ((*sabuf = (struct sockaddr *)malloc(saa->slBuf)) == NULL)
+    if ((*sabuf = (struct sockaddr *)malloc((size_t)saa->slBuf)) == NULL)
         return SA_RC(SA_ERR_MEM);
-    memmove(*sabuf, saa->saBuf, saa->slBuf);
+    memmove(*sabuf, saa->saBuf, (size_t)saa->slBuf);
     *salen = saa->slBuf;
 
     return SA_OK;
@@ -793,10 +804,10 @@
         if (prefixlen < 0) {
             if (l1 != l2)
                 return SA_RC(SA_ERR_MTC);
-            nBits = l1;
+            nBits = (int)l1;
         }
         else {
-            if (l1 < prefixlen || l2 < prefixlen)
+            if ((int)l1 < prefixlen || (int)l2 < prefixlen)
                 return SA_RC(SA_ERR_MTC);
             nBits = prefixlen;
         }
@@ -823,9 +834,9 @@
             ucp2 += 12;
         }
         for (i = 0; i < 10; i++)
-            if (ucp0[i] != 0x00)
+            if ((int)ucp0[i] != 0x00)
                 return SA_RC(SA_ERR_MTC);
-        if (!(ucp0[10] == 0xFF && ucp0[11] == 0xFF))
+        if (!((int)ucp0[10] == 0xFF && (int)ucp0[11] == 0xFF))
             return SA_RC(SA_ERR_MTC);
         nBits = 32;
     }
@@ -866,13 +877,13 @@
     nBytes = (prefixlen / 8);
     nBits  = (prefixlen % 8);
     if (nBytes > 0) {
-        if (memcmp(ucp1, ucp2, nBytes) != 0)
+        if (memcmp(ucp1, ucp2, (size_t)nBytes) != 0)
             return SA_RC(SA_ERR_MTC);
     }
     if (nBits > 0) {
-        uc1 = ucp1[nBytes];
-        uc2 = ucp2[nBytes];
-        mask = (0xFF << (8-nBits)) & 0xFF;
+        uc1 = (unsigned int)ucp1[nBytes];
+        uc2 = (unsigned int)ucp2[nBytes];
+        mask = ((unsigned int)0xFF << (8-nBits)) & (unsigned int)0xFF;
         if ((uc1 & mask) != (uc2 & mask))
             return SA_RC(SA_ERR_MTC);
     }
@@ -921,7 +932,7 @@
 
     /* check for pending options */
     rv = SA_OK;
-    for (i = 0; i < (sizeof(sa->optInfo)/sizeof(sa->optInfo[0])); i++) {
+    for (i = 0; i < (int)(sizeof(sa->optInfo)/sizeof(sa->optInfo[0])); i++) {
         if (sa->optInfo[i].todo) {
             switch (i) {
                 /* enable/disable Nagle's Algorithm (see RFC898) */
@@ -1085,7 +1096,7 @@
         return SA_RC(SA_ERR_USE);
 
     /* close socket */
-    close(sa->fdSocket);
+    (void)close(sa->fdSocket);
     sa->fdSocket = -1;
 
     return SA_OK;
@@ -1116,13 +1127,13 @@
     sa->cpWriteBuf     = NULL;
 
     /* init timeval object attributes */
-    for (i = 0; i < (sizeof(sa->tvTimeout)/sizeof(sa->tvTimeout[0])); i++) {
+    for (i = 0; i < (int)(sizeof(sa->tvTimeout)/sizeof(sa->tvTimeout[0])); i++) {
         sa->tvTimeout[i].tv_sec  = 0;
         sa->tvTimeout[i].tv_usec = 0;
     }
 
     /* init options object attributes */
-    for (i = 0; i < (sizeof(sa->optInfo)/sizeof(sa->optInfo[0])); i++) {
+    for (i = 0; i < (int)(sizeof(sa->optInfo)/sizeof(sa->optInfo[0])); i++) {
         sa->optInfo[i].todo  = FALSE;
         sa->optInfo[i].value = 0;
     }
@@ -1150,7 +1161,7 @@
         return SA_RC(SA_ERR_ARG);
 
     /* kill underlying socket */
-    sa_socket_kill(sa);
+    (void)sa_socket_kill(sa);
 
     /* free object and sub-objects */
     if (sa->cpReadBuf != NULL)
@@ -1192,7 +1203,7 @@
         return SA_RC(SA_ERR_ARG);
 
     if (id == SA_TIMEOUT_ALL) {
-        for (i = 0; i < (sizeof(sa->tvTimeout)/sizeof(sa->tvTimeout[0])); i++) {
+        for (i = 0; i < (int)(sizeof(sa->tvTimeout)/sizeof(sa->tvTimeout[0])); i++) {
             sa->tvTimeout[i].tv_sec  = sec;
             sa->tvTimeout[i].tv_usec = usec;
         }
@@ -1220,7 +1231,7 @@
 
     if (id == SA_BUFFER_READ) {
         /* configure read/incoming buffer */
-        if (sa->nReadLen > size)
+        if (sa->nReadLen > (int)size)
             return SA_RC(SA_ERR_USE);
         if (size > 0) {
             if (sa->cpReadBuf == NULL)
@@ -1230,7 +1241,7 @@
             if (cp == NULL)
                 return SA_RC(SA_ERR_MEM);
             sa->cpReadBuf = cp;
-            sa->nReadSize = size;
+            sa->nReadSize = (int)size;
         }
         else {
             if (sa->cpReadBuf != NULL)
@@ -1241,7 +1252,7 @@
     }
     else if (id == SA_BUFFER_WRITE) {
         /* configure write/outgoing buffer */
-        if (sa->nWriteLen > size)
+        if (sa->nWriteLen > (int)size)
             return SA_RC(SA_ERR_USE);
         if (size > 0) {
             if (sa->cpWriteBuf == NULL)
@@ -1251,7 +1262,7 @@
             if (cp == NULL)
                 return SA_RC(SA_ERR_MEM);
             sa->cpWriteBuf = cp;
-            sa->nWriteSize = size;
+            sa->nWriteSize = (int)size;
         }
         else {
             if (sa->cpWriteBuf != NULL)
@@ -1388,7 +1399,7 @@
     /* remove a possibly existing old Unix Domain socket on filesystem */
     if (laddr->nFamily == AF_LOCAL) {
         un = (struct sockaddr_un *)((void *)laddr->saBuf);
-        unlink(un->sun_path);
+        (void)unlink(un->sun_path);
     }
 
     /* perform bind operation on underlying socket */
@@ -1431,7 +1442,7 @@
 
         /* temporarily switch underlying socket to non-blocking mode */
         flags = fcntl(sa->fdSocket, F_GETFL, 0);
-        fcntl(sa->fdSocket, F_SETFL, flags|O_NONBLOCK);
+        (void)fcntl(sa->fdSocket, F_SETFL, flags|O_NONBLOCK);
 
         /* perform the connect operation */
         if ((n = SA_SC_CALL_3(sa, connect, sa->fdSocket, raddr->saBuf, raddr->slBuf)) < 0) {
@@ -1461,25 +1472,25 @@
             goto done;
         }
         else if (n == 0) {
-            close(sa->fdSocket); /* stop TCP three-way handshake */
+            (void)close(sa->fdSocket); /* stop TCP three-way handshake */
             sa->fdSocket = -1;
             rv = SA_ERR_TMT;
             goto done;
         }
 
         /* fetch pending error */
-        len = sizeof(error);
+        len = (socklen_t)sizeof(error);
         if (getsockopt(sa->fdSocket, SOL_SOCKET, SO_ERROR, (void *)&error, &len) < 0)
             error = errno;
 
         done:
 
         /* reset socket flags */
-        fcntl(sa->fdSocket, F_SETFL, flags);
+        (void)fcntl(sa->fdSocket, F_SETFL, flags);
 
         /* optionally set errno */
         if (error != 0) {
-            close(sa->fdSocket); /* just in case */
+            (void)close(sa->fdSocket); /* just in case */
             sa->fdSocket = -1;
             errno = error;
             rv = SA_ERR_SYS;
@@ -1554,7 +1565,7 @@
     }
 
     /* perform accept operation on underlying socket */
-    sa_size = sizeof(sa_buf);
+    sa_size = (socklen_t)sizeof(sa_buf);
     if ((s = SA_SC_CALL_3(sa, accept, sa->fdSocket, (struct sockaddr *)&sa_buf, &sa_size)) == -1)
         return SA_RC(SA_ERR_SYS);
 
@@ -1562,13 +1573,13 @@
     if ((rv = sa_addr_create(caddr)) != SA_OK)
         return SA_RC(rv);
     if ((rv = sa_addr_s2a(*caddr, (struct sockaddr *)&sa_buf, sa_size)) != SA_OK) {
-        sa_addr_destroy(*caddr);
+        (void)sa_addr_destroy(*caddr);
         return SA_RC(rv);
     }
 
     /* create result socket object */
     if ((rv = sa_create(csa)) != SA_OK) {
-        sa_addr_destroy(*caddr);
+        (void)sa_addr_destroy(*caddr);
         return SA_RC(rv);
     }
 
@@ -1585,7 +1596,7 @@
     SA_SC_COPY((*csa), sa, sendto);
 
     /* copy-over original timeout values */
-    for (i = 0; i < (sizeof(sa->tvTimeout)/sizeof(sa->tvTimeout[0])); i++) {
+    for (i = 0; i < (int)(sizeof(sa->tvTimeout)/sizeof(sa->tvTimeout[0])); i++) {
         (*csa)->tvTimeout[i].tv_sec  = sa->tvTimeout[i].tv_sec;
         (*csa)->tvTimeout[i].tv_usec = sa->tvTimeout[i].tv_usec;
     }
@@ -1618,7 +1629,7 @@
         return SA_RC(SA_ERR_USE);
 
     /* determine remote address of underlying socket */
-    sa_size = sizeof(sa_buf);
+    sa_size = (socklen_t)sizeof(sa_buf);
     if (getpeername(sa->fdSocket, (struct sockaddr *)&sa_buf, &sa_size) < 0)
         return SA_RC(SA_ERR_SYS);
 
@@ -1626,7 +1637,7 @@
     if ((rv = sa_addr_create(raddr)) != SA_OK)
         return SA_RC(rv);
     if ((rv = sa_addr_s2a(*raddr, (struct sockaddr *)&sa_buf, sa_size)) != SA_OK) {
-        sa_addr_destroy(*raddr);
+        (void)sa_addr_destroy(*raddr);
         return SA_RC(rv);
     }
 
@@ -1654,7 +1665,7 @@
         return SA_RC(SA_ERR_USE);
 
     /* determine local address of underlying socket */
-    sa_size = sizeof(sa_buf);
+    sa_size = (socklen_t)sizeof(sa_buf);
     if (getsockname(sa->fdSocket, (struct sockaddr *)&sa_buf, &sa_size) < 0)
         return SA_RC(SA_ERR_SYS);
 
@@ -1662,7 +1673,7 @@
     if ((rv = sa_addr_create(laddr)) != SA_OK)
         return SA_RC(rv);
     if ((rv = sa_addr_s2a(*laddr, (struct sockaddr *)&sa_buf, sa_size)) != SA_OK) {
-        sa_addr_destroy(*laddr);
+        (void)sa_addr_destroy(*laddr);
         return SA_RC(rv);
     }
 
@@ -1713,7 +1724,7 @@
 
     /* perform read operation on underlying socket */
     do {
-        rv = SA_SC_CALL_3(sa, read, sa->fdSocket, cpBuf, nBufLen);
+        rv = (int)SA_SC_CALL_3(sa, read, sa->fdSocket, cpBuf, (size_t)nBufLen);
     } while (rv == -1 && errno == EINTR);
 
 #if defined(SO_RCVTIMEO) && defined(SO_SNDTIMEO)
@@ -1748,8 +1759,8 @@
     if (sa->nReadSize == 0) {
         /* user-space unbuffered I/O */
         if (sa->nWriteLen > 0)
-            sa_flush(sa);
-        res = sa_read_raw(sa, cpBuf, nBufReq);
+            (void)sa_flush(sa);
+        res = sa_read_raw(sa, cpBuf, (int)nBufReq);
         if (res == 0)
             rv = SA_ERR_EOF;
         else if (res < 0 && errno == ETIMEDOUT)
@@ -1761,7 +1772,7 @@
         /* user-space buffered I/O */
         res = 0;
         for (;;) {
-            if (nBufReq <= sa->nReadLen) {
+            if ((int)nBufReq <= sa->nReadLen) {
                 /* buffer holds enough data, so just use this */
                 memmove(cpBuf, sa->cpReadBuf, nBufReq);
                 memmove(sa->cpReadBuf, sa->cpReadBuf+nBufReq, sa->nReadLen-nBufReq);
@@ -1771,17 +1782,17 @@
             else {
                 if (sa->nReadLen > 0) {
                     /* fetch already existing buffer contents as a start */
-                    memmove(cpBuf, sa->cpReadBuf, sa->nReadLen);
+                    memmove(cpBuf, sa->cpReadBuf, (size_t)sa->nReadLen);
                     nBufReq -= sa->nReadLen;
                     cpBuf   += sa->nReadLen;
                     res     += sa->nReadLen;
                     sa->nReadLen = 0;
                 }
                 if (sa->nWriteLen > 0)
-                    sa_flush(sa);
-                if (nBufReq >= sa->nReadSize) {
+                    (void)sa_flush(sa);
+                if ((int)nBufReq >= sa->nReadSize) {
                     /* buffer is too small at all, so read directly */
-                    n = sa_read_raw(sa, cpBuf, nBufReq);
+                    n = sa_read_raw(sa, cpBuf, (int)nBufReq);
                     if (n > 0)
                         res += n;
                     else if (n == 0)
@@ -1850,7 +1861,7 @@
         rv = sa_read(sa, &c, 1, &n);
         if (rv != SA_OK)
             break;
-        if (n <= 0)
+        if (n == 0)
             break;
         cpBuf[res++] = c;
         if (c == '\n')
@@ -1892,7 +1903,7 @@
 
     /* perform write operation on underlying socket */
     do {
-        rv = SA_SC_CALL_3(sa, write, sa->fdSocket, cpBuf, nBufLen);
+        rv = (int)SA_SC_CALL_3(sa, write, sa->fdSocket, cpBuf, (size_t)nBufLen);
     } while (rv == -1 && errno == EINTR);
 
 #if defined(SO_RCVTIMEO) && defined(SO_SNDTIMEO)
@@ -1925,7 +1936,7 @@
     rv = SA_OK;
     if (sa->nWriteSize == 0) {
         /* user-space unbuffered I/O */
-        res = sa_write_raw(sa, cpBuf, nBufReq);
+        res = sa_write_raw(sa, cpBuf, (int)nBufReq);
         if (res < 0 && errno == ETIMEDOUT)
             rv = SA_ERR_TMT;
         else if (res < 0)
@@ -1933,15 +1944,15 @@
     }
     else {
         /* user-space buffered I/O */
-        if (nBufReq > (sa->nWriteSize - sa->nWriteLen)) {
+        if ((int)nBufReq > (sa->nWriteSize - sa->nWriteLen)) {
             /* not enough space in buffer, so flush buffer first */
-            sa_flush(sa);
+            (void)sa_flush(sa);
         }
         res = 0;
-        if (nBufReq >= sa->nWriteSize) {
+        if ((int)nBufReq >= sa->nWriteSize) {
             /* buffer too small at all, so write immediately */
             while (nBufReq > 0) {
-                n = sa_write_raw(sa, cpBuf, nBufReq);
+                n = sa_write_raw(sa, cpBuf, (int)nBufReq);
                 if (n < 0 && errno == ETIMEDOUT)
                     rv = (res == 0 ? SA_ERR_TMT : SA_OK);
                 else if (n < 0)
@@ -1957,7 +1968,7 @@
             /* (again) enough sprace in buffer, so store data */
             memmove(sa->cpWriteBuf+sa->nWriteLen, cpBuf, nBufReq);
             sa->nWriteLen += nBufReq;
-            res = nBufReq;
+            res = (int)nBufReq;
         }
     }
 
@@ -1989,7 +2000,7 @@
 sa_rc_t sa_writef(sa_t *sa, const char *cpFmt, ...)
 {
     va_list ap;
-    size_t n;
+    int n;
     sa_writef_cb_t ctx;
 
     /* argument sanity check(s) */
@@ -2009,6 +2020,8 @@
     ctx.sa = sa;
     ctx.rv = SA_OK;
     n = sa_mvxprintf(sa_writef_cb, &ctx, cpFmt, ap);
+    if (n == -1 && ctx.rv == SA_OK)
+        ctx.rv = SA_ERR_FMT;
     va_end(ap);
 
     return ctx.rv;
@@ -2043,7 +2056,7 @@
                 rv = SA_ERR_SYS;
             if (n <= 0)
                 break;
-            memmove(sa->cpWriteBuf, sa->cpWriteBuf+n, sa->nWriteLen-n);
+            memmove(sa->cpWriteBuf, sa->cpWriteBuf+n, (size_t)(sa->nWriteLen-n));
             sa->nWriteLen -= n;
         }
         sa->nWriteLen = 0;
@@ -2081,7 +2094,7 @@
 
     /* flush write buffers */
     if ((how & SHUT_WR) || (how & SHUT_RDWR))
-        sa_flush(sa);
+        (void)sa_flush(sa);
 
     /* perform shutdown operation on underlying socket */
     if (shutdown(sa->fdSocket, how) == -1)
@@ -2101,7 +2114,8 @@
 #endif
     } sa_buf;
     socklen_t sa_size;
-    size_t n;
+    ssize_t n;
+    int k;
     fd_set fds;
 
     /* argument sanity check(s) */
@@ -2122,17 +2136,17 @@
         FD_ZERO(&fds);
         FD_SET(sa->fdSocket, &fds);
         do {
-            n = SA_SC_CALL_5(sa, select, sa->fdSocket+1, &fds, NULL, NULL,
+            k = SA_SC_CALL_5(sa, select, sa->fdSocket+1, &fds, NULL, NULL,
                              &sa->tvTimeout[SA_TIMEOUT_READ]);
-        } while (n == -1 && errno == EINTR);
-        if (n == 0)
+        } while (k == -1 && errno == EINTR);
+        if (k == 0)
             errno = ETIMEDOUT;
-        if (n <= 0)
+        if (k <= 0)
             return SA_RC(SA_ERR_SYS);
     }
 
     /* perform receive operation on underlying socket */
-    sa_size = sizeof(sa_buf);
+    sa_size = (socklen_t)sizeof(sa_buf);
     if ((n = SA_SC_CALL_6(sa, recvfrom, sa->fdSocket, buf, buflen, 0,
                           (struct sockaddr *)&sa_buf, &sa_size)) == -1)
         return SA_RC(SA_ERR_SYS);
@@ -2141,13 +2155,13 @@
     if ((rv = sa_addr_create(raddr)) != SA_OK)
         return rv;
     if ((rv = sa_addr_s2a(*raddr, (struct sockaddr *)&sa_buf, sa_size)) != SA_OK) {
-        sa_addr_destroy(*raddr);
+        (void)sa_addr_destroy(*raddr);
         return rv;
     }
 
     /* pass actual number of received bytes to caller */
     if (bufdone != NULL)
-        *bufdone = n;
+        *bufdone = (size_t)n;
 
     return SA_OK;
 }
@@ -2155,7 +2169,8 @@
 /* send data via socket */
 sa_rc_t sa_send(sa_t *sa, sa_addr_t *raddr, const char *buf, size_t buflen, size_t *bufdone)
 {
-    size_t n;
+    ssize_t n;
+    int k;
     fd_set fds;
     sa_rc_t rv;
 
@@ -2178,12 +2193,12 @@
         FD_ZERO(&fds);
         FD_SET(sa->fdSocket, &fds);
         do {
-            n = SA_SC_CALL_5(sa, select, sa->fdSocket+1, NULL, &fds, NULL,
+            k = SA_SC_CALL_5(sa, select, sa->fdSocket+1, NULL, &fds, NULL,
                              &sa->tvTimeout[SA_TIMEOUT_WRITE]);
-        } while (n == -1 && errno == EINTR);
-        if (n == 0)
+        } while (k == -1 && errno == EINTR);
+        if (k == 0)
             errno = ETIMEDOUT;
-        if (n <= 0)
+        if (k <= 0)
             return SA_RC(SA_ERR_SYS);
     }
 
@@ -2193,7 +2208,7 @@
 
     /* pass actual number of sent bytes to caller */
     if (bufdone != NULL)
-        *bufdone = n;
+        *bufdone = (size_t)n;
 
     return SA_OK;
 }
@@ -2202,7 +2217,7 @@
 sa_rc_t sa_sendf(sa_t *sa, sa_addr_t *raddr, const char *cpFmt, ...)
 {
     va_list ap;
-    size_t nBuf;
+    int nBuf;
     char *cpBuf;
     sa_rc_t rv;
     char caBuf[1024];
@@ -2213,11 +2228,12 @@
 
     /* format string into temporary buffer */
     va_start(ap, cpFmt);
-    nBuf = sa_mvsnprintf(NULL, 0, cpFmt, ap);
+    if ((nBuf = sa_mvsnprintf(NULL, 0, cpFmt, ap)) == -1)
+        return SA_RC(SA_ERR_FMT);
     va_end(ap);
-    if ((nBuf+1) > sizeof(caBuf)) {
+    if ((nBuf+1) > (int)sizeof(caBuf)) {
         /* requires a larger buffer, so allocate dynamically */
-        if ((cpBuf = (char *)malloc(nBuf+1)) == NULL)
+        if ((cpBuf = (char *)malloc((size_t)(nBuf+1))) == NULL)
             return SA_RC(SA_ERR_MEM);
     }
     else {
@@ -2225,14 +2241,17 @@
         cpBuf = caBuf;
     }
     va_start(ap, cpFmt);
-    sa_mvsnprintf(cpBuf, nBuf+1, cpFmt, ap);
+    rv = SA_OK;
+    if (sa_mvsnprintf(cpBuf, (size_t)(nBuf+1), cpFmt, ap) == -1)
+        rv = SA_ERR_FMT;
     va_end(ap);
 
     /* pass-through to sa_send() */
-    rv = sa_send(sa, raddr, cpBuf, nBuf, NULL);
+    if (rv == SA_OK)
+        rv = sa_send(sa, raddr, cpBuf, (size_t)nBuf, NULL);
 
     /* cleanup dynamically allocated buffer */
-    if ((nBuf+1) > sizeof(caBuf))
+    if ((nBuf+1) > (int)sizeof(caBuf))
         free(cpBuf);
 
     return rv;
@@ -2252,6 +2271,8 @@
     else if (rv == SA_ERR_EOF) sz = "End Of Communication";
     else if (rv == SA_ERR_TMT) sz = "Communication Timeout";
     else if (rv == SA_ERR_SYS) sz = "Operating System Error";
+    else if (rv == SA_ERR_NET) sz = "Networking Error";
+    else if (rv == SA_ERR_FMT) sz = "Formatting Error";
     else if (rv == SA_ERR_IMP) sz = "Implementation Not Available";
     else if (rv == SA_ERR_INT) sz = "Internal Error";
     else                       sz = "Invalid Result Code";


ossp-pkg/sa/sa.h 1.34 -> 1.35

--- sa.h 2002/10/30 20:22:06     1.34
+++ sa.h 2002/11/28 15:42:41     1.35
@@ -116,6 +116,8 @@
     SA_ERR_EOF, /* End Of Communication         */
     SA_ERR_TMT, /* Communication Timeout        */
     SA_ERR_SYS, /* Operating System Error       */
+    SA_ERR_NET, /* Networking Error             */
+    SA_ERR_FMT, /* Formatting Error             */
     SA_ERR_IMP, /* Implementation Not Available */
     SA_ERR_INT  /* Internal Error               */
 } sa_rc_t;

CVSTrac 2.0.1