mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-13 05:41:26 +01:00
bluetooth: Use nitems(foo) instead of sizeof(foo)/sizeof(foo[0])
Pull Request: https://github.com/freebsd/freebsd-src/pull/888 Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
This commit is contained in:
parent
2b8df536a6
commit
fdbf7cab91
@ -30,7 +30,7 @@
|
||||
* $Id: sdp.c,v 1.3 2004/02/17 22:14:57 max Exp $
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/sysctl.h>
|
||||
#define L2CAP_SOCKET_CHECKED
|
||||
@ -79,10 +79,10 @@ SDP_ATTR_RANGE( 0x0209, /* HIDBatteryPower */
|
||||
SDP_ATTR_RANGE( 0x020d, /* HIDNormallyConnectable */
|
||||
0x020d)
|
||||
};
|
||||
#define nattrs (sizeof(attrs)/sizeof(attrs[0]))
|
||||
#define nattrs nitems(attrs)
|
||||
|
||||
static sdp_attr_t values[8];
|
||||
#define nvalues (sizeof(values)/sizeof(values[0]))
|
||||
#define nvalues nitems(values)
|
||||
|
||||
static uint8_t buffer[nvalues][512];
|
||||
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include <sys/consio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/kbio.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/wait.h>
|
||||
#include <assert.h>
|
||||
@ -319,7 +320,7 @@ static int32_t const x[] =
|
||||
/* Right GUI E7 */ E0PREFIX|0x5C /* E0 DC */
|
||||
};
|
||||
|
||||
#define xsize ((int32_t)(sizeof(x)/sizeof(x[0])))
|
||||
#define xsize (int32_t)nitems(x)
|
||||
|
||||
/*
|
||||
* Get a max HID keycode (aligned)
|
||||
@ -437,7 +438,7 @@ kbd_write(bitstr_t *m, int32_t fb, int32_t make, int32_t fd)
|
||||
int32_t i, *b, *eob, n, buf[64];
|
||||
|
||||
b = buf;
|
||||
eob = b + sizeof(buf)/sizeof(buf[0]);
|
||||
eob = b + nitems(buf);
|
||||
i = fb;
|
||||
|
||||
while (i < xsize) {
|
||||
|
@ -33,6 +33,7 @@
|
||||
#define L2CAP_SOCKET_CHECKED
|
||||
#include <bluetooth.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
@ -153,11 +154,11 @@ socket_open(char const *node)
|
||||
(void * const) &filter, sizeof(filter)) < 0)
|
||||
err(4, "Could not setsockopt()");
|
||||
|
||||
size = (sizeof(mib)/sizeof(mib[0]));
|
||||
size = nitems(mib);
|
||||
if (sysctlnametomib("net.bluetooth.hci.command_timeout",mib,&size) < 0)
|
||||
err(5, "Could not sysctlnametomib()");
|
||||
|
||||
if (sysctl(mib, sizeof(mib)/sizeof(mib[0]),
|
||||
if (sysctl(mib, nitems(mib),
|
||||
(void *) &timeout, &size, NULL, 0) < 0)
|
||||
err(6, "Could not sysctl()");
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/param.h>
|
||||
#define L2CAP_SOCKET_CHECKED
|
||||
#include <bluetooth.h>
|
||||
#include <errno.h>
|
||||
@ -160,7 +161,7 @@ hci_read_node_features(int s, int argc, char **argv)
|
||||
return (ERROR);
|
||||
|
||||
fprintf(stdout, "Features: ");
|
||||
for (n = 0; n < sizeof(r.features)/sizeof(r.features[0]); n++)
|
||||
for (n = 0; n < nitems(r.features); n++)
|
||||
fprintf(stdout, "%#02x ", r.features[n]);
|
||||
fprintf(stdout, "\n%s\n", hci_features2str(r.features,
|
||||
buffer, sizeof(buffer)));
|
||||
@ -243,8 +244,8 @@ hci_read_neighbor_cache(int s, int argc, char **argv)
|
||||
|
||||
for (n = 0; n < r.num_entries; n++) {
|
||||
uint8_t addrtype = r.entries[n].addrtype;
|
||||
if(addrtype >= sizeof(addrtype2str)/sizeof(addrtype2str[0]))
|
||||
addrtype = sizeof(addrtype2str)/sizeof(addrtype2str[0]) - 1;
|
||||
if(addrtype >= nitems(addrtype2str))
|
||||
addrtype = nitems(addrtype2str) - 1;
|
||||
fprintf(stdout,
|
||||
"%1s %-17.17s " \
|
||||
"%02x %02x %02x %02x %02x %02x %02x %02x " \
|
||||
|
@ -30,6 +30,7 @@
|
||||
* $Id: search.c,v 1.2 2003/09/08 17:35:15 max Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <netinet/in.h>
|
||||
#define L2CAP_SOCKET_CHECKED
|
||||
#include <bluetooth.h>
|
||||
@ -51,7 +52,7 @@ static uint32_t attrs[] =
|
||||
SDP_ATTR_RANGE( SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST,
|
||||
SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST)
|
||||
};
|
||||
#define attrs_len (sizeof(attrs)/sizeof(attrs[0]))
|
||||
#define attrs_len nitems(attrs)
|
||||
|
||||
/* Buffer for the attributes */
|
||||
#define NRECS 25 /* request this much records from the SDP server */
|
||||
@ -60,7 +61,7 @@ static uint8_t buffer[NRECS * attrs_len][BSIZE];
|
||||
|
||||
/* SDP attributes */
|
||||
static sdp_attr_t values[NRECS * attrs_len];
|
||||
#define values_len (sizeof(values)/sizeof(values[0]))
|
||||
#define values_len nitems(values)
|
||||
|
||||
/*
|
||||
* Print Service Class ID List
|
||||
|
@ -32,6 +32,7 @@
|
||||
* $Id: profile.c,v 1.6 2004/01/13 19:31:54 max Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
#define L2CAP_SOCKET_CHECKED
|
||||
#include <bluetooth.h>
|
||||
@ -77,7 +78,7 @@ profile_get_descriptor(uint16_t uuid)
|
||||
|
||||
int32_t i;
|
||||
|
||||
for (i = 0; i < sizeof(profiles)/sizeof(profiles[0]); i++)
|
||||
for (i = 0; i < nitems(profiles); i++)
|
||||
if (profiles[i]->uuid == uuid)
|
||||
return (profiles[i]);
|
||||
|
||||
@ -444,7 +445,7 @@ bnep_profile_create_protocol_descriptor_list(
|
||||
};
|
||||
|
||||
uint16_t i, psm, version = 0x0100,
|
||||
nptypes = sizeof(ptype)/sizeof(ptype[0]),
|
||||
nptypes = nitems(ptype),
|
||||
nptypes_size = nptypes * 3;
|
||||
|
||||
if (datalen != 2 || 18 + nptypes_size > 255 ||
|
||||
|
@ -30,6 +30,7 @@
|
||||
* $Id: sar.c,v 1.2 2004/01/08 23:46:51 max Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/uio.h>
|
||||
#include <netinet/in.h>
|
||||
@ -304,7 +305,7 @@ server_send_service_attribute_response(server_p srv, int32_t fd)
|
||||
iov[3].iov_len = 1 + cs[0];
|
||||
|
||||
do {
|
||||
size = writev(fd, (struct iovec const *) &iov, sizeof(iov)/sizeof(iov[0]));
|
||||
size = writev(fd, (struct iovec const *) &iov, nitems(iov));
|
||||
} while (size < 0 && errno == EINTR);
|
||||
|
||||
/* Check if we have sent (or failed to sent) last response chunk */
|
||||
|
@ -30,6 +30,7 @@
|
||||
* $Id: srr.c,v 1.1 2004/01/13 01:54:39 max Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/uio.h>
|
||||
#include <netinet/in.h>
|
||||
@ -129,7 +130,7 @@ server_send_service_register_response(server_p srv, int32_t fd)
|
||||
iov[1].iov_len = srv->fdidx[fd].rsp_size;
|
||||
|
||||
do {
|
||||
size = writev(fd, (struct iovec const *) &iov, sizeof(iov)/sizeof(iov[0]));
|
||||
size = writev(fd, (struct iovec const *) &iov, nitems(iov));
|
||||
} while (size < 0 && errno == EINTR);
|
||||
|
||||
srv->fdidx[fd].rsp_cs = 0;
|
||||
|
@ -30,6 +30,7 @@
|
||||
* $Id: ssr.c,v 1.5 2004/01/13 01:54:39 max Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/uio.h>
|
||||
#include <netinet/in.h>
|
||||
@ -269,7 +270,7 @@ server_send_service_search_response(server_p srv, int32_t fd)
|
||||
iov[3].iov_len = 1 + cs[0];
|
||||
|
||||
do {
|
||||
size = writev(fd, (struct iovec const *) &iov, sizeof(iov)/sizeof(iov[0]));
|
||||
size = writev(fd, (struct iovec const *) &iov, nitems(iov));
|
||||
} while (size < 0 && errno == EINTR);
|
||||
|
||||
/* Check if we have sent (or failed to sent) last response chunk */
|
||||
|
Loading…
Reference in New Issue
Block a user