mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-08 01:47:29 +00:00
lib: Avoid using assignments within checks
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
This commit is contained in:
parent
11dbcdd35c
commit
0e2d70760d
14
lib/buffer.c
14
lib/buffer.c
@ -357,7 +357,8 @@ buffer_status_t buffer_flush_window(struct buffer *b, int fd, int width,
|
|||||||
|
|
||||||
iov_size =
|
iov_size =
|
||||||
((iov_index > IOV_MAX) ? IOV_MAX : iov_index);
|
((iov_index > IOV_MAX) ? IOV_MAX : iov_index);
|
||||||
if ((nbytes = writev(fd, c_iov, iov_size)) < 0) {
|
nbytes = writev(fd, c_iov, iov_size);
|
||||||
|
if (nbytes < 0) {
|
||||||
flog_err(EC_LIB_SOCKET,
|
flog_err(EC_LIB_SOCKET,
|
||||||
"%s: writev to fd %d failed: %s",
|
"%s: writev to fd %d failed: %s",
|
||||||
__func__, fd, safe_strerror(errno));
|
__func__, fd, safe_strerror(errno));
|
||||||
@ -370,7 +371,8 @@ buffer_status_t buffer_flush_window(struct buffer *b, int fd, int width,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else /* IOV_MAX */
|
#else /* IOV_MAX */
|
||||||
if ((nbytes = writev(fd, iov, iov_index)) < 0)
|
nbytes = writev(fd, iov, iov_index);
|
||||||
|
if (nbytes < 0)
|
||||||
flog_err(EC_LIB_SOCKET, "%s: writev to fd %d failed: %s",
|
flog_err(EC_LIB_SOCKET, "%s: writev to fd %d failed: %s",
|
||||||
__func__, fd, safe_strerror(errno));
|
__func__, fd, safe_strerror(errno));
|
||||||
#endif /* IOV_MAX */
|
#endif /* IOV_MAX */
|
||||||
@ -472,15 +474,19 @@ buffer_status_t buffer_write(struct buffer *b, int fd, const void *p,
|
|||||||
/* Buffer is not empty, so do not attempt to write the new data.
|
/* Buffer is not empty, so do not attempt to write the new data.
|
||||||
*/
|
*/
|
||||||
nbytes = 0;
|
nbytes = 0;
|
||||||
else if ((nbytes = write(fd, p, size)) < 0) {
|
else {
|
||||||
|
nbytes = write(fd, p, size);
|
||||||
|
if (nbytes < 0) {
|
||||||
if (ERRNO_IO_RETRY(errno))
|
if (ERRNO_IO_RETRY(errno))
|
||||||
nbytes = 0;
|
nbytes = 0;
|
||||||
else {
|
else {
|
||||||
flog_err(EC_LIB_SOCKET, "%s: write error on fd %d: %s",
|
flog_err(EC_LIB_SOCKET,
|
||||||
|
"%s: write error on fd %d: %s",
|
||||||
__func__, fd, safe_strerror(errno));
|
__func__, fd, safe_strerror(errno));
|
||||||
return BUFFER_ERROR;
|
return BUFFER_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* Add any remaining data to the buffer. */
|
/* Add any remaining data to the buffer. */
|
||||||
{
|
{
|
||||||
size_t written = nbytes;
|
size_t written = nbytes;
|
||||||
|
@ -641,7 +641,8 @@ static int get_memory_usage(pid_t pid)
|
|||||||
char *vm;
|
char *vm;
|
||||||
|
|
||||||
snprintf(status_child, sizeof(status_child), "/proc/%d/status", pid);
|
snprintf(status_child, sizeof(status_child), "/proc/%d/status", pid);
|
||||||
if ((fd = open(status_child, O_RDONLY)) < 0)
|
fd = open(status_child, O_RDONLY);
|
||||||
|
if (fd < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
read(fd, buf, 4095);
|
read(fd, buf, 4095);
|
||||||
|
@ -78,7 +78,8 @@ int set_nonblocking(int fd)
|
|||||||
/* According to the Single UNIX Spec, the return value for F_GETFL
|
/* According to the Single UNIX Spec, the return value for F_GETFL
|
||||||
should
|
should
|
||||||
never be negative. */
|
never be negative. */
|
||||||
if ((flags = fcntl(fd, F_GETFL)) < 0) {
|
flags = fcntl(fd, F_GETFL);
|
||||||
|
if (flags < 0) {
|
||||||
flog_err(EC_LIB_SYSTEM_CALL,
|
flog_err(EC_LIB_SYSTEM_CALL,
|
||||||
"fcntl(F_GETFL) failed for fd %d: %s", fd,
|
"fcntl(F_GETFL) failed for fd %d: %s", fd,
|
||||||
safe_strerror(errno));
|
safe_strerror(errno));
|
||||||
|
@ -40,15 +40,19 @@ static inline void putbyte(uint8_t bytex, char **posx)
|
|||||||
bool zero = false;
|
bool zero = false;
|
||||||
int byte = bytex, tmp, a, b;
|
int byte = bytex, tmp, a, b;
|
||||||
|
|
||||||
if ((tmp = byte - 200) >= 0) {
|
tmp = byte - 200;
|
||||||
|
if (tmp >= 0) {
|
||||||
*pos++ = '2';
|
*pos++ = '2';
|
||||||
zero = true;
|
zero = true;
|
||||||
byte = tmp;
|
byte = tmp;
|
||||||
} else if ((tmp = byte - 100) >= 0) {
|
} else {
|
||||||
|
tmp = byte - 100;
|
||||||
|
if (tmp >= 0) {
|
||||||
*pos++ = '1';
|
*pos++ = '1';
|
||||||
zero = true;
|
zero = true;
|
||||||
byte = tmp;
|
byte = tmp;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* make sure the compiler knows the value range of "byte" */
|
/* make sure the compiler knows the value range of "byte" */
|
||||||
assume(byte < 100 && byte >= 0);
|
assume(byte < 100 && byte >= 0);
|
||||||
|
@ -1034,7 +1034,8 @@ const char *prefix2str(union prefixconstptr pu, char *str, int size)
|
|||||||
l = strlen(buf);
|
l = strlen(buf);
|
||||||
buf[l++] = '/';
|
buf[l++] = '/';
|
||||||
byte = p->prefixlen;
|
byte = p->prefixlen;
|
||||||
if ((tmp = p->prefixlen - 100) >= 0) {
|
tmp = p->prefixlen - 100;
|
||||||
|
if (tmp >= 0) {
|
||||||
buf[l++] = '1';
|
buf[l++] = '1';
|
||||||
z = true;
|
z = true;
|
||||||
byte = tmp;
|
byte = tmp;
|
||||||
|
@ -379,14 +379,14 @@ static int setsockopt_ipv4_ifindex(int sock, ifindex_t val)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
#if defined(IP_PKTINFO)
|
#if defined(IP_PKTINFO)
|
||||||
if ((ret = setsockopt(sock, IPPROTO_IP, IP_PKTINFO, &val, sizeof(val)))
|
ret = setsockopt(sock, IPPROTO_IP, IP_PKTINFO, &val, sizeof(val));
|
||||||
< 0)
|
if (ret < 0)
|
||||||
flog_err(EC_LIB_SOCKET,
|
flog_err(EC_LIB_SOCKET,
|
||||||
"Can't set IP_PKTINFO option for fd %d to %d: %s",
|
"Can't set IP_PKTINFO option for fd %d to %d: %s",
|
||||||
sock, val, safe_strerror(errno));
|
sock, val, safe_strerror(errno));
|
||||||
#elif defined(IP_RECVIF)
|
#elif defined(IP_RECVIF)
|
||||||
if ((ret = setsockopt(sock, IPPROTO_IP, IP_RECVIF, &val, sizeof(val)))
|
ret = setsockopt(sock, IPPROTO_IP, IP_RECVIF, &val, sizeof(val));
|
||||||
< 0)
|
if (ret < 0)
|
||||||
flog_err(EC_LIB_SOCKET,
|
flog_err(EC_LIB_SOCKET,
|
||||||
"Can't set IP_RECVIF option for fd %d to %d: %s", sock,
|
"Can't set IP_RECVIF option for fd %d to %d: %s", sock,
|
||||||
val, safe_strerror(errno));
|
val, safe_strerror(errno));
|
||||||
@ -639,12 +639,8 @@ int sockopt_tcp_signature_ext(int sock, union sockunion *su, uint16_t prefixlen,
|
|||||||
|
|
||||||
#endif /* GNU_LINUX */
|
#endif /* GNU_LINUX */
|
||||||
|
|
||||||
if ((ret = setsockopt(sock, IPPROTO_TCP, optname, &md5sig,
|
ret = setsockopt(sock, IPPROTO_TCP, optname, &md5sig, sizeof(md5sig));
|
||||||
sizeof(md5sig)))
|
if (ret < 0) {
|
||||||
< 0) {
|
|
||||||
/* ENOENT is harmless. It is returned when we clear a password
|
|
||||||
for which
|
|
||||||
one was not previously set. */
|
|
||||||
if (ENOENT == errno)
|
if (ENOENT == errno)
|
||||||
ret = 0;
|
ret = 0;
|
||||||
else
|
else
|
||||||
|
@ -1097,7 +1097,8 @@ ssize_t stream_read_try(struct stream *s, int fd, size_t size)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((nbytes = read(fd, s->data + s->endp, size)) >= 0) {
|
nbytes = read(fd, s->data + s->endp, size);
|
||||||
|
if (nbytes >= 0) {
|
||||||
s->endp += nbytes;
|
s->endp += nbytes;
|
||||||
return nbytes;
|
return nbytes;
|
||||||
}
|
}
|
||||||
@ -1126,9 +1127,8 @@ ssize_t stream_recvfrom(struct stream *s, int fd, size_t size, int flags,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((nbytes = recvfrom(fd, s->data + s->endp, size, flags, from,
|
nbytes = recvfrom(fd, s->data + s->endp, size, flags, from, fromlen);
|
||||||
fromlen))
|
if (nbytes >= 0) {
|
||||||
>= 0) {
|
|
||||||
s->endp += nbytes;
|
s->endp += nbytes;
|
||||||
return nbytes;
|
return nbytes;
|
||||||
}
|
}
|
||||||
|
@ -3798,7 +3798,8 @@ static int zclient_read(struct thread *thread)
|
|||||||
zclient->t_read = NULL;
|
zclient->t_read = NULL;
|
||||||
|
|
||||||
/* Read zebra header (if we don't have it already). */
|
/* Read zebra header (if we don't have it already). */
|
||||||
if ((already = stream_get_endp(zclient->ibuf)) < ZEBRA_HEADER_SIZE) {
|
already = stream_get_endp(zclient->ibuf);
|
||||||
|
if (already < ZEBRA_HEADER_SIZE) {
|
||||||
ssize_t nbyte;
|
ssize_t nbyte;
|
||||||
if (((nbyte = stream_read_try(zclient->ibuf, zclient->sock,
|
if (((nbyte = stream_read_try(zclient->ibuf, zclient->sock,
|
||||||
ZEBRA_HEADER_SIZE - already))
|
ZEBRA_HEADER_SIZE - already))
|
||||||
@ -3811,7 +3812,6 @@ static int zclient_read(struct thread *thread)
|
|||||||
return zclient_failed(zclient);
|
return zclient_failed(zclient);
|
||||||
}
|
}
|
||||||
if (nbyte != (ssize_t)(ZEBRA_HEADER_SIZE - already)) {
|
if (nbyte != (ssize_t)(ZEBRA_HEADER_SIZE - already)) {
|
||||||
/* Try again later. */
|
|
||||||
zclient_event(ZCLIENT_READ, zclient);
|
zclient_event(ZCLIENT_READ, zclient);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user