Permalink
Browse files

Correct comment on label representation.

* The operation being performed is negation on the *value* of the
label.  The comments are talking about changing the *representation* of the
label, which could be twos complement, sign magnitude, etc.

* The comments also repeat what very clearly happens in the code:

/* Set x to its negation. */
x = ~x;

* Since `~x == ((x * -1) - 1)`, there's no need for the latter.

All in all, previous content was confusing and overly verbose.
  • Loading branch information...
1 parent 0de3a73 commit 2dc151bf5f35c92f73b933e13f7ed502781c84b9 @andres-perera andres-perera committed Dec 9, 2012
Showing with 13 additions and 28 deletions.
  1. +5 −14 pcap-bpf.c
  2. +8 −14 pcap-linux.c
View
@@ -210,30 +210,21 @@ pcap_setnonblock_bpf(pcap_t *p, int nonblock, char *errbuf)
#ifdef HAVE_ZEROCOPY_BPF
if (p->md.zerocopy) {
/*
- * Map each value to the corresponding 2's complement, to
+ * Map each value to their corresponding negation to
* preserve the timeout value provided with pcap_set_timeout.
* (from pcap-linux.c).
*/
if (nonblock) {
if (p->md.timeout >= 0) {
/*
- * Timeout is non-negative, so we're not
- * currently in non-blocking mode; set it
- * to the 2's complement, to make it
- * negative, as an indication that we're
- * in non-blocking mode.
+ * Indicate that we're switching to
+ * non-blocking mode.
*/
- p->md.timeout = p->md.timeout * -1 - 1;
+ p->md.timeout = ~p->md.timeout;
}
} else {
if (p->md.timeout < 0) {
- /*
- * Timeout is negative, so we're currently
- * in blocking mode; reverse the previous
- * operation, to make the timeout non-negative
- * again.
- */
- p->md.timeout = (p->md.timeout + 1) * -1;
+ p->md.timeout = ~p->md.timeout;
}
}
return (0);
View
@@ -3648,27 +3648,21 @@ pcap_getnonblock_mmap(pcap_t *p, char *errbuf)
static int
pcap_setnonblock_mmap(pcap_t *p, int nonblock, char *errbuf)
{
- /* map each value to the corresponding 2's complement, to
- * preserve the timeout value provided with pcap_set_timeout */
+ /*
+ * Map each value to their corresponding negation to
+ * preserve the timeout value provided with pcap_set_timeout.
+ */
if (nonblock) {
if (p->md.timeout >= 0) {
/*
- * Timeout is non-negative, so we're not already
- * in non-blocking mode; set it to the 2's
- * complement, to make it negative, as an
- * indication that we're in non-blocking mode.
+ * Indicate that we're switching to
+ * non-blocking mode.
*/
- p->md.timeout = p->md.timeout*-1 - 1;
+ p->md.timeout = ~p->md.timeout;
}
} else {
if (p->md.timeout < 0) {
- /*
- * Timeout is negative, so we're not already
- * in blocking mode; reverse the previous
- * operation, to make the timeout non-negative
- * again.
- */
- p->md.timeout = (p->md.timeout+1)*-1;
+ p->md.timeout = ~p->md.timeout;
}
}
return 0;

0 comments on commit 2dc151b

Please sign in to comment.