Alexey I. Froloff raorn@altlinux.org
Alex Wang alexw@nicira.com
Alfredo Finelli alf@computationes.de
+Alin Serdean aserdean@cloudbasesolutions.com
Andrew Evans aevans@nicira.com
Andrew Lambeth wal@nicira.com
Andy Hill hillad@gmail.com
integer types. Use the PRId<N>, PRIu<N>, and PRIx<N> macros from
<inttypes.h> for formatting them with printf() and related functions.
- Use %zu to format size_t with printf().
+ For compatibility with antique printf() implementations:
+
+ - Instead of "%zu", use "%"PRIuSIZE.
+
+ - Instead of "%td", use "%"PRIdPTR.
+
+ - Instead of "%ju", use "%"PRIuMAX.
+
+Other variants exist for different radixes. For example, use
+"%"PRIxSIZE instead of "%zx" or "%x" instead of "%hhx".
+
+ Also, instead of "%hhd", use "%d". Be cautious substituting "%u",
+"%x", and "%o" for the corresponding versions with "hh": cast the
+argument to unsigned char if necessary, because printf("%hhu", -1)
+prints 255 but printf("%u", -1) prints 4294967295.
Use bit-fields sparingly. Do not use bit-fields for layout of
network protocol fields or in other circumstances where the exact
fi
.PHONY: config-h-check
+# Check for printf() type modifiers that MSVC doesn't support.
+ALL_LOCAL += printf-check
+printf-check:
+ @if test -e $(srcdir)/.git && (git --version) >/dev/null 2>&1 && \
+ git --no-pager grep -n -E -e '%[-+ #0-9.*]*([ztj]|hh)' --and --not -e 'ovs_scan' `git ls-files $(srcdir) | grep '\.[ch]$$'`; \
+ then \
+ echo "See above for list of violations of the rule that"; \
+ echo "'z', 't', 'j', 'hh' printf() type modifiers are"; \
+ echo "forbidden. See CodingStyle for replacements."; \
+ exit 1; \
+ fi
+.PHONY: printf-check
+
# Check that certain data structures are always declared "static".
ALL_LOCAL += static-check
static-check:
msg = ofpbuf_at(p, (uint8_t *)p->l7 - (uint8_t *)p->data, BFD_PACKET_LEN);
if (!msg) {
VLOG_INFO_RL(&rl, "%s: Received too-short BFD control message (only "
- "%td bytes long, at least %d required).",
+ "%"PRIdPTR" bytes long, at least %d required).",
bfd->name, (uint8_t *) ofpbuf_tail(p) - (uint8_t *) p->l7,
BFD_PACKET_LEN);
goto out;
if (&e->list_node != list_front(&slave->entries)) {
ds_put_cstr(&ds, " + ");
}
- ds_put_format(&ds, "h%td: %"PRIu64"kB",
+ ds_put_format(&ds, "h%"PRIdPTR": %"PRIu64"kB",
e - bond->hash, e->tx_bytes / 1024);
}
ds_put_cstr(&ds, ")");
struct bond *bond = from->bond;
uint64_t delta = hash->tx_bytes;
- VLOG_INFO("bond %s: shift %"PRIu64"kB of load (with hash %td) "
+ VLOG_INFO("bond %s: shift %"PRIu64"kB of load (with hash %"PRIdPTR") "
"from %s to %s (now carrying %"PRIu64"kB and "
"%"PRIu64"kB load, respectively)",
bond->name, delta / 1024, hash - bond->hash,
}
if (slaves_size < bundle->n_slaves * sizeof(ovs_be16)) {
- VLOG_WARN_RL(&rl, "Nicira action %"PRIu16" only has %zu bytes "
- "allocated for slaves. %zu bytes are required for "
+ VLOG_WARN_RL(&rl, "Nicira action %"PRIu16" only has %"PRIuSIZE" bytes "
+ "allocated for slaves. %"PRIuSIZE" bytes are required for "
"%"PRIu16" slaves.", subtype, slaves_size,
bundle->n_slaves * sizeof(ovs_be16), bundle->n_slaves);
error = OFPERR_OFPBAC_BAD_LEN;
}
}
- svec_add_nocopy(lines, xasprintf("%zu events never hit", n_never_hit));
+ svec_add_nocopy(lines, xasprintf("%"PRIuSIZE" events never hit", n_never_hit));
free(totals);
}
time_msec() - ch->last_poll);
}
- VLOG_WARN("%s: lost packet on channel %td%s",
+ VLOG_WARN("%s: lost packet on channel %"PRIdPTR"%s",
dpif_name(dpif_), ch - dpif->channels, ds_cstr(&s));
ds_destroy(&s);
}
#include <config.h>
#include "dynamic-string.h"
+#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
n = end - start;
/* Print line. */
- ds_put_format(ds, "%08jx ", (uintmax_t) ROUND_DOWN(ofs, per_line));
+ ds_put_format(ds, "%08"PRIxMAX" ",
+ (uintmax_t) ROUND_DOWN(ofs, per_line));
for (i = 0; i < start; i++) {
ds_put_format(ds, " ");
}
for (; i < end; i++) {
- ds_put_format(ds, "%02hhx%c",
+ ds_put_format(ds, "%02x%c",
buf[i - start], i == per_line / 2 - 1? '-' : ' ');
}
if (ascii) {
if (count > 5) {
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(10, 10);
COVERAGE_INC(hmap_pathological);
- VLOG_DBG_RL(&rl, "%s: %d nodes in bucket (%zu nodes, %zu buckets)",
+ VLOG_DBG_RL(&rl, "%s: %d nodes in bucket (%"PRIuSIZE" nodes, %"PRIuSIZE" buckets)",
where, count, hmap->n, hmap->mask + 1);
}
}
VLOG_WARN_RL(&rl, "unsupported algorithm %d", (int) mp->algorithm);
return OFPERR_OFPBAC_BAD_ARGUMENT;
} else if (mp->dst.n_bits < min_n_bits) {
- VLOG_WARN_RL(&rl, "multipath action requires at least %zu bits for "
+ VLOG_WARN_RL(&rl, "multipath action requires at least %"PRIuSIZE" bits for "
"%"PRIu32" links", min_n_bits, n_links);
return OFPERR_OFPBAC_BAD_ARGUMENT;
}
}
}
} else if (retval != size) {
- VLOG_WARN_RL(&rl, "sent partial Ethernet packet (%zd bytes of "
- "%zu) on %s", retval, size, name);
+ VLOG_WARN_RL(&rl, "sent partial Ethernet packet (%"PRIuSIZE"d bytes of "
+ "%"PRIuSIZE") on %s", retval, size, name);
error = EMSGSIZE;
} else {
break;
}
return errno;
} else if (retval != size) {
- VLOG_WARN_RL(&rl, "sent partial Ethernet packet (%zd bytes of "
- "%zu) on %s", retval, size, netdev_get_name(netdev_));
+ VLOG_WARN_RL(&rl, "sent partial Ethernet packet (%"PRIuSIZE"d bytes of "
+ "%"PRIuSIZE") on %s", retval, size, netdev_get_name(netdev_));
return EMSGSIZE;
} else {
return 0;
}
if (msg.msg_flags & MSG_TRUNC) {
- VLOG_ERR_RL(&rl, "truncated message (longer than %zu bytes)",
+ VLOG_ERR_RL(&rl, "truncated message (longer than %"PRIuSIZE" bytes)",
sizeof tail);
return E2BIG;
}
if (retval < sizeof *nlmsghdr
|| nlmsghdr->nlmsg_len < sizeof *nlmsghdr
|| nlmsghdr->nlmsg_len > retval) {
- VLOG_ERR_RL(&rl, "received invalid nlmsg (%zd bytes < %zu)",
+ VLOG_ERR_RL(&rl, "received invalid nlmsg (%"PRIuSIZE"d bytes < %"PRIuSIZE")",
retval, sizeof *nlmsghdr);
return EPROTO;
}
struct nlmsgerr *err = ofpbuf_at(msg, NLMSG_HDRLEN, sizeof *err);
int code = EPROTO;
if (!err) {
- VLOG_ERR_RL(&rl, "received invalid nlmsgerr (%zd bytes < %zd)",
+ VLOG_ERR_RL(&rl, "received invalid nlmsgerr (%"PRIuSIZE"d bytes < %"PRIuSIZE"d)",
msg->size, NLMSG_HDRLEN + sizeof *err);
} else if (err->error <= 0 && err->error > INT_MIN) {
code = -err->error;
/* Verify length. */
len = nl_attr_get_size(nla);
if (len < min_len || len > max_len) {
- VLOG_DBG_RL(&rl, "attr %"PRIu16" length %zu not in "
- "allowed range %zu...%zu", type, len, min_len, max_len);
+ VLOG_DBG_RL(&rl, "attr %"PRIu16" length %"PRIuSIZE" not in "
+ "allowed range %"PRIuSIZE"...%"PRIuSIZE, type, len, min_len, max_len);
return false;
}
for (i = 0; i < n_attrs; i++) {
const struct nl_policy *e = &policy[i];
if (!e->optional && e->type != NL_A_NO_ATTR && !attrs[i]) {
- VLOG_DBG_RL(&rl, "required attr %zu missing", i);
+ VLOG_DBG_RL(&rl, "required attr %"PRIuSIZE" missing", i);
return false;
}
}
if (!p) {
VLOG_DBG_RL(&rl, "nx_match length %u, rounded up to a "
"multiple of 8, is longer than space in message (max "
- "length %zu)", match_len, b->size);
+ "length %"PRIuSIZE")", match_len, b->size);
return OFPERR_OFPBMC_BAD_LEN;
}
}
if (!p) {
VLOG_DBG_RL(&rl, "oxm length %u, rounded up to a "
"multiple of 8, is longer than space in message (max "
- "length %zu)", match_len, b->size);
+ "length %"PRIuSIZE")", match_len, b->size);
return OFPERR_OFPBMC_BAD_LEN;
}
expected_len = odp_action_len(nl_attr_type(a));
if (expected_len != -2 && nl_attr_get_size(a) != expected_len) {
- ds_put_format(ds, "bad length %zu, expected %d for: ",
+ ds_put_format(ds, "bad length %"PRIuSIZE", expected %d for: ",
nl_attr_get_size(a), expected_len);
format_generic_odp_action(ds, a);
return;
if (bad_key_len || bad_mask_len) {
if (bad_key_len) {
- ds_put_format(ds, "(bad key length %zu, expected %d)(",
+ ds_put_format(ds, "(bad key length %"PRIuSIZE", expected %d)(",
nl_attr_get_size(a),
odp_flow_key_attr_len(nl_attr_type(a)));
}
format_generic_odp_key(a, ds);
if (bad_mask_len) {
ds_put_char(ds, '/');
- ds_put_format(ds, "(bad mask length %zu, expected %d)(",
+ ds_put_format(ds, "(bad mask length %"PRIuSIZE", expected %d)(",
nl_attr_get_size(ma),
odp_flow_key_attr_len(nl_attr_type(ma)));
}
if (len != expected_len && expected_len >= 0) {
char namebuf[OVS_KEY_ATTR_BUFSIZE];
- VLOG_ERR_RL(&rl, "attribute %s has length %zu but should have "
+ VLOG_ERR_RL(&rl, "attribute %s has length %"PRIuSIZE" but should have "
"length %d", ovs_key_attr_to_string(type, namebuf,
sizeof namebuf),
len, expected_len);
}
if (ids_size < ids->n_controllers * sizeof(ovs_be16)) {
- VLOG_WARN_RL(&rl, "Nicira action dec_ttl_cnt_ids only has %zu bytes "
- "allocated for controller ids. %zu bytes are required for "
+ VLOG_WARN_RL(&rl, "Nicira action dec_ttl_cnt_ids only has %"PRIuSIZE" bytes "
+ "allocated for controller ids. %"PRIuSIZE" bytes are required for "
"%"PRIu16" controllers.", ids_size,
ids->n_controllers * sizeof(ovs_be16), ids->n_controllers);
return OFPERR_OFPBAC_BAD_LEN;
ds_init(&s);
ds_put_hex_dump(&s, actions, max_actions * OFP_ACTION_ALIGN, 0, false);
- VLOG_WARN("bad action at offset %#tx (%s):\n%s",
+ VLOG_WARN("bad action at offset %#"PRIxPTR" (%s):\n%s",
(char *)bad_action - (char *)actions,
ofperr_get_name(error), ds_cstr(&s));
ds_destroy(&s);
actions = ofpbuf_try_pull(openflow, actions_len);
if (actions == NULL) {
VLOG_WARN_RL(&rl, "OpenFlow message actions length %u exceeds "
- "remaining message length (%zu)",
+ "remaining message length (%"PRIuSIZE")",
actions_len, openflow->size);
return OFPERR_OFPBRC_BAD_LEN;
}
}
if (left) {
- VLOG_WARN_RL(&rl, "bad instruction format at offset %zu",
+ VLOG_WARN_RL(&rl, "bad instruction format at offset %"PRIuSIZE,
(n_insts - left) * sizeof *inst);
return OFPERR_OFPBIC_BAD_LEN;
}
instructions = ofpbuf_try_pull(openflow, instructions_len);
if (instructions == NULL) {
VLOG_WARN_RL(&rl, "OpenFlow message instructions length %u exceeds "
- "remaining message length (%zu)",
+ "remaining message length (%"PRIuSIZE")",
instructions_len, openflow->size);
error = OFPERR_OFPBIC_BAD_LEN;
goto exit;
ds_put_format(string, " cookie=0x%"PRIx64, ntohll(pin.cookie));
}
- ds_put_format(string, " total_len=%zu in_port=", pin.total_len);
+ ds_put_format(string, " total_len=%"PRIuSIZE" in_port=", pin.total_len);
ofputil_format_port(pin.fmd.in_port, string);
if (pin.fmd.tun_id != htonll(0)) {
ofputil_packet_in_reason_to_string(pin.reason, reasonbuf,
sizeof reasonbuf));
- ds_put_format(string, " data_len=%zu", pin.packet_len);
+ ds_put_format(string, " data_len=%"PRIuSIZE, pin.packet_len);
if (pin.buffer_id == UINT32_MAX) {
ds_put_format(string, " (unbuffered)");
if (pin.total_len != pin.packet_len) {
ofpacts_format(po.ofpacts, po.ofpacts_len, string);
if (po.buffer_id == UINT32_MAX) {
- ds_put_format(string, " data_len=%zu", po.packet_len);
+ ds_put_format(string, " data_len=%"PRIuSIZE, po.packet_len);
if (verbosity > 0 && po.packet_len > 0) {
char *packet = ofp_packet_to_string(po.packet, po.packet_len);
ds_put_char(string, '\n');
{
struct ofpbuf b;
- ds_put_format(string, " %zu ports\n", ofputil_count_port_stats(oh));
+ ds_put_format(string, " %"PRIuSIZE" ports\n", ofputil_count_port_stats(oh));
if (verbosity < 1) {
return;
}
ofpraw_pull_assert(&b);
n = b.size / sizeof *ts;
- ds_put_format(string, " %zu tables\n", n);
+ ds_put_format(string, " %"PRIuSIZE" tables\n", n);
if (verbosity < 1) {
return;
}
ofpraw_pull_assert(&b);
n = b.size / sizeof *ts;
- ds_put_format(string, " %zu tables\n", n);
+ ds_put_format(string, " %"PRIuSIZE" tables\n", n);
if (verbosity < 1) {
return;
}
ofpraw_pull_assert(&b);
n = b.size / sizeof *ts;
- ds_put_format(string, " %zu tables\n", n);
+ ds_put_format(string, " %"PRIuSIZE" tables\n", n);
if (verbosity < 1) {
return;
}
ofpraw_pull_assert(&b);
n = b.size / sizeof *ts;
- ds_put_format(string, " %zu tables\n", n);
+ ds_put_format(string, " %"PRIuSIZE" tables\n", n);
if (verbosity < 1) {
return;
}
{
struct ofpbuf b;
- ds_put_format(string, " %zu queues\n", ofputil_count_queue_stats(oh));
+ ds_put_format(string, " %"PRIuSIZE" queues\n", ofputil_count_queue_stats(oh));
if (verbosity < 1) {
return;
}
{
size_t len = ntohs(oh->length);
- ds_put_format(string, " %zu bytes of payload\n", len - sizeof *oh);
+ ds_put_format(string, " %"PRIuSIZE" bytes of payload\n", len - sizeof *oh);
if (verbosity > 1) {
ds_put_hex_dump(string, oh + 1, len - sizeof *oh, 0, true);
}
if (!len) {
ds_put_cstr(&string, "OpenFlow message is empty\n");
} else if (len < sizeof(struct ofp_header)) {
- ds_put_format(&string, "OpenFlow packet too short (only %zu bytes):\n",
+ ds_put_format(&string, "OpenFlow packet too short (only %"PRIuSIZE" bytes):\n",
len);
} else if (ntohs(oh->length) > len) {
enum ofperr error;
}
ds_put_format(&string,
- "(***truncated to %zu bytes from %"PRIu16"***)\n",
+ "(***truncated to %"PRIuSIZE" bytes from %"PRIu16"***)\n",
len, ntohs(oh->length));
} else if (ntohs(oh->length) < len) {
ds_put_format(&string,
- "(***only uses %"PRIu16" bytes out of %zu***)\n",
+ "(***only uses %"PRIu16" bytes out of %"PRIuSIZE"***)\n",
ntohs(oh->length), len);
} else {
enum ofperr error;
omc = ofpbuf_try_pull(msg, sizeof *omc);
if (!omc) {
VLOG_WARN_RL(&bad_ofmsg_rl,
- "OFPMP_METER_CONFIG reply has %zu leftover bytes at end",
+ "OFPMP_METER_CONFIG reply has %"PRIuSIZE" leftover bytes at end",
msg->size);
return OFPERR_OFPBRC_BAD_LEN;
}
oms = ofpbuf_try_pull(msg, sizeof *oms);
if (!oms) {
VLOG_WARN_RL(&bad_ofmsg_rl,
- "OFPMP_METER reply has %zu leftover bytes at end",
+ "OFPMP_METER reply has %"PRIuSIZE" leftover bytes at end",
msg->size);
return OFPERR_OFPBRC_BAD_LEN;
}
ofs = ofpbuf_try_pull(msg, sizeof *ofs);
if (!ofs) {
- VLOG_WARN_RL(&bad_ofmsg_rl, "OFPST_FLOW reply has %zu leftover "
+ VLOG_WARN_RL(&bad_ofmsg_rl, "OFPST_FLOW reply has %"PRIuSIZE" leftover "
"bytes at end", msg->size);
return EINVAL;
}
length = ntohs(ofs->length);
if (length < sizeof *ofs) {
VLOG_WARN_RL(&bad_ofmsg_rl, "OFPST_FLOW reply claims invalid "
- "length %zu", length);
+ "length %"PRIuSIZE, length);
return EINVAL;
}
ofs = ofpbuf_try_pull(msg, sizeof *ofs);
if (!ofs) {
- VLOG_WARN_RL(&bad_ofmsg_rl, "OFPST_FLOW reply has %zu leftover "
+ VLOG_WARN_RL(&bad_ofmsg_rl, "OFPST_FLOW reply has %"PRIuSIZE" leftover "
"bytes at end", msg->size);
return EINVAL;
}
length = ntohs(ofs->length);
if (length < sizeof *ofs) {
VLOG_WARN_RL(&bad_ofmsg_rl, "OFPST_FLOW reply claims invalid "
- "length %zu", length);
+ "length %"PRIuSIZE, length);
return EINVAL;
}
nfs = ofpbuf_try_pull(msg, sizeof *nfs);
if (!nfs) {
- VLOG_WARN_RL(&bad_ofmsg_rl, "NXST_FLOW reply has %zu leftover "
+ VLOG_WARN_RL(&bad_ofmsg_rl, "NXST_FLOW reply has %"PRIuSIZE" leftover "
"bytes at end", msg->size);
return EINVAL;
}
length = ntohs(nfs->length);
match_len = ntohs(nfs->match_len);
if (length < sizeof *nfs + ROUND_UP(match_len, 8)) {
- VLOG_WARN_RL(&bad_ofmsg_rl, "NXST_FLOW reply with match_len=%zu "
- "claims invalid length %zu", match_len, length);
+ VLOG_WARN_RL(&bad_ofmsg_rl, "NXST_FLOW reply with match_len=%"PRIuSIZE" "
+ "claims invalid length %"PRIuSIZE, match_len, length);
return EINVAL;
}
if (nx_pull_match(msg, match_len, &fs->match, NULL, NULL)) {
nfmr = ofpbuf_try_pull(msg, sizeof *nfmr);
if (!nfmr) {
- VLOG_WARN_RL(&bad_ofmsg_rl, "NXST_FLOW_MONITOR request has %zu "
+ VLOG_WARN_RL(&bad_ofmsg_rl, "NXST_FLOW_MONITOR request has %"PRIuSIZE" "
"leftover bytes at end", msg->size);
return OFPERR_OFPBRC_BAD_LEN;
}
}
bad_len:
- VLOG_WARN_RL(&bad_ofmsg_rl, "NXST_FLOW_MONITOR reply has %zu "
+ VLOG_WARN_RL(&bad_ofmsg_rl, "NXST_FLOW_MONITOR reply has %"PRIuSIZE" "
"leftover bytes at end", msg->size);
return OFPERR_OFPBRC_BAD_LEN;
}
}
bad_len:
- VLOG_WARN_RL(&bad_ofmsg_rl, "OFPST_PORT reply has %zu leftover "
+ VLOG_WARN_RL(&bad_ofmsg_rl, "OFPST_PORT reply has %"PRIuSIZE" leftover "
"bytes at end", msg->size);
return OFPERR_OFPBRC_BAD_LEN;
}
}
if (!ogs11) {
- VLOG_WARN_RL(&bad_ofmsg_rl, "%s reply has %zu leftover bytes at end",
+ VLOG_WARN_RL(&bad_ofmsg_rl, "%s reply has %"PRIuSIZE" leftover bytes at end",
ofpraw_get_name(raw), msg->size);
return OFPERR_OFPBRC_BAD_LEN;
}
length = ntohs(ogs11->length);
if (length < sizeof base_len) {
- VLOG_WARN_RL(&bad_ofmsg_rl, "%s reply claims invalid length %zu",
+ VLOG_WARN_RL(&bad_ofmsg_rl, "%s reply claims invalid length %"PRIuSIZE,
ofpraw_get_name(raw), length);
return OFPERR_OFPBRC_BAD_LEN;
}
gs->n_buckets = (length - base_len) / sizeof *obc;
obc = ofpbuf_try_pull(msg, gs->n_buckets * sizeof *obc);
if (!obc) {
- VLOG_WARN_RL(&bad_ofmsg_rl, "%s reply has %zu leftover bytes at end",
+ VLOG_WARN_RL(&bad_ofmsg_rl, "%s reply has %"PRIuSIZE" leftover bytes at end",
ofpraw_get_name(raw), msg->size);
return OFPERR_OFPBRC_BAD_LEN;
}
? ofpbuf_try_pull(msg, sizeof *ob)
: NULL);
if (!ob) {
- VLOG_WARN_RL(&bad_ofmsg_rl, "buckets end with %zu leftover bytes",
+ VLOG_WARN_RL(&bad_ofmsg_rl, "buckets end with %"PRIuSIZE" leftover bytes",
buckets_length);
}
ob_len = ntohs(ob->len);
if (ob_len < sizeof *ob) {
VLOG_WARN_RL(&bad_ofmsg_rl, "OpenFlow message bucket length "
- "%zu is not valid", ob_len);
+ "%"PRIuSIZE" is not valid", ob_len);
return OFPERR_OFPGMFC_BAD_BUCKET;
} else if (ob_len > buckets_length) {
VLOG_WARN_RL(&bad_ofmsg_rl, "OpenFlow message bucket length "
- "%zu exceeds remaining buckets data size %zu",
+ "%"PRIuSIZE" exceeds remaining buckets data size %"PRIuSIZE,
ob_len, buckets_length);
return OFPERR_OFPGMFC_BAD_BUCKET;
}
ogds = ofpbuf_try_pull(msg, sizeof *ogds);
if (!ogds) {
- VLOG_WARN_RL(&bad_ofmsg_rl, "OFPST11_GROUP_DESC reply has %zu "
+ VLOG_WARN_RL(&bad_ofmsg_rl, "OFPST11_GROUP_DESC reply has %"PRIuSIZE" "
"leftover bytes at end", msg->size);
return OFPERR_OFPBRC_BAD_LEN;
}
length = ntohs(ogds->length);
if (length < sizeof *ogds || length - sizeof *ogds > msg->size) {
VLOG_WARN_RL(&bad_ofmsg_rl, "OFPST11_GROUP_DESC reply claims invalid "
- "length %zu", length);
+ "length %"PRIuSIZE, length);
return OFPERR_OFPBRC_BAD_LEN;
}
}
bad_len:
- VLOG_WARN_RL(&bad_ofmsg_rl, "OFPST_QUEUE reply has %zu leftover "
+ VLOG_WARN_RL(&bad_ofmsg_rl, "OFPST_QUEUE reply has %"PRIuSIZE" leftover "
"bytes at end", msg->size);
return OFPERR_OFPBRC_BAD_LEN;
}
struct ds s;
ds_init(&s);
- ds_put_format(&s, "size=%zu, allocated=%zu, head=%zu, tail=%zu\n",
+ ds_put_format(&s, "size=%"PRIuSIZE", allocated=%"PRIuSIZE", head=%"PRIuSIZE", tail=%"PRIuSIZE"\n",
b->size, b->allocated,
ofpbuf_headroom(b), ofpbuf_tailroom(b));
ds_put_hex_dump(&s, b->data, MIN(b->size, maxbytes), 0, false);
if (n_chars < c->minLen) {
return ovsdb_error(
"constraint violation",
- "\"%s\" length %zu is less than minimum allowed "
+ "\"%s\" length %"PRIuSIZE" is less than minimum allowed "
"length %u", s, n_chars, c->minLen);
} else if (n_chars > c->maxLen) {
return ovsdb_error(
"constraint violation",
- "\"%s\" length %zu is greater than maximum allowed "
+ "\"%s\" length %"PRIuSIZE" is greater than maximum allowed "
"length %u", s, n_chars, c->maxLen);
}
n = inner->u.array.n;
if (n < type->n_min || n > type->n_max) {
return ovsdb_syntax_error(json, NULL, "%s must have %u to "
- "%u members but %zu are present",
+ "%u members but %"PRIuSIZE" are present",
class, type->n_min, type->n_max, n);
}
if (txn->inc_index + 2 > results->n) {
VLOG_WARN_RL(&syntax_rl, "reply does not contain enough operations "
- "for increment (has %zu, needs %u)",
+ "for increment (has %"PRIuSIZE", needs %u)",
results->n, txn->inc_index + 2);
return false;
}
return false;
}
if (rows->u.array.n != 1) {
- VLOG_WARN_RL(&syntax_rl, "\"select\" reply \"rows\" has %zu elements "
+ VLOG_WARN_RL(&syntax_rl, "\"select\" reply \"rows\" has %"PRIuSIZE" elements "
"instead of 1",
rows->u.array.n);
return false;
if (insert->op_index >= results->n) {
VLOG_WARN_RL(&syntax_rl, "reply does not contain enough operations "
- "for insert (has %zu, needs %u)",
+ "for insert (has %"PRIuSIZE", needs %u)",
results->n, insert->op_index);
return false;
}
-/* Copyright (c) 2009, 2011 Nicira, Inc.
+/* Copyright (c) 2009, 2011, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
if (n_unused > 1) {
ovsdb_parser_raise_error(
parser,
- "Member '%s' and %zu other member%s "
+ "Member '%s' and %"PRIuSIZE" other member%s "
"are present but not allowed here.",
node->name, n_unused - 1, n_unused > 2 ? "s" : "");
} else {
((len & 0x0000ff00) << 8) |
((len & 0x000000ff) << 24));
if (swapped_len > 0xffff) {
- VLOG_WARN("bad packet length %zu or %"PRIu32" "
+ VLOG_WARN("bad packet length %"PRIuSIZE" or %"PRIu32" "
"reading pcap file",
len, swapped_len);
return EPROTO;
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
VLOG_WARN_RL(&rl, "Unix socket name %s is longer than maximum "
- "%zu bytes", name, MAX_UN_LEN);
+ "%"PRIuSIZE" bytes", name, MAX_UN_LEN);
return error;
}
VLOG_ERR_RL(&rl, "getsockopt(%s): %s", optname, ovs_strerror(error));
} else if (len != sizeof value) {
error = EINVAL;
- VLOG_ERR_RL(&rl, "getsockopt(%s): value is %u bytes (expected %zu)",
+ VLOG_ERR_RL(&rl, "getsockopt(%s): value is %u bytes (expected %"PRIuSIZE")",
optname, (unsigned int) len, sizeof value);
} else {
error = 0;
ovs_assert(n_fds > 0);
if (n_fds > SOUTIL_MAX_FDS) {
- VLOG_ERR("%zu fds received but only %d supported",
+ VLOG_ERR("%"PRIuSIZE" fds received but only %d supported",
n_fds, SOUTIL_MAX_FDS);
for (i = 0; i < n_fds; i++) {
close(fds_data[i]);
}
if (bpdu_size < sizeof(struct stp_bpdu_header)) {
- VLOG_WARN("%s: received runt %zu-byte BPDU", stp->name, bpdu_size);
+ VLOG_WARN("%s: received runt %"PRIuSIZE"-byte BPDU", stp->name, bpdu_size);
p->error_count++;
goto out;
}
switch (header->bpdu_type) {
case STP_TYPE_CONFIG:
if (bpdu_size < sizeof(struct stp_config_bpdu)) {
- VLOG_WARN("%s: received config BPDU with invalid size %zu",
+ VLOG_WARN("%s: received config BPDU with invalid size %"PRIuSIZE,
stp->name, bpdu_size);
p->error_count++;
goto out;
case STP_TYPE_TCN:
if (bpdu_size != sizeof(struct stp_tcn_bpdu)) {
- VLOG_WARN("%s: received TCN BPDU with invalid size %zu",
+ VLOG_WARN("%s: received TCN BPDU with invalid size %"PRIuSIZE,
stp->name, bpdu_size);
p->error_count++;
goto out;
if (i) {
ds_put_char(&fp, ':');
}
- ds_put_format(&fp, "%02hhx", digest[i]);
+ ds_put_format(&fp, "%02x", digest[i]);
}
}
subject = X509_NAME_oneline(X509_get_subject_name(cert), NULL, 0);
for (i = 0; i < n_certs; i++) {
/* SSL_CTX_add_client_CA makes a copy of the relevant data. */
if (SSL_CTX_add_client_CA(ctx, certs[i]) != 1) {
- VLOG_ERR("failed to add client certificate %zu from %s: %s",
+ VLOG_ERR("failed to add client certificate %"PRIuSIZE" from %s: %s",
i, file_name,
ERR_error_string(ERR_get_error(), NULL));
} else {
ds_put_format(&details, "type %d", content_type);
}
- VLOG_DBG("%s%u%s%s %s (%zu bytes)",
+ VLOG_DBG("%s%u%s%s %s (%"PRIuSIZE" bytes)",
sslv->type == CLIENT ? "client" : "server",
sslv->session_nr, write_p ? "-->" : "<--",
stream_get_name(&sslv->stream), ds_cstr(&details), len);
* is too short). We don't check the actual failure reason because
* POSIX requires strerror_r() to return the error but old glibc
* (before 2.13) returns -1 and sets errno. */
- snprintf(buffer, BUFSIZE, "Unknown error %d", error);
+ snprintf(buffer, BUFSIZE, "Unknown error %"PRIuSIZE, error);
}
#endif
n = end - start;
/* Print line. */
- fprintf(stream, "%08jx ", (uintmax_t) ROUND_DOWN(ofs, per_line));
+ fprintf(stream, "%08"PRIxMAX" ", (uintmax_t) ROUND_DOWN(ofs, per_line));
for (i = 0; i < start; i++)
fprintf(stream, " ");
for (; i < end; i++)
- fprintf(stream, "%02hhx%c",
+ fprintf(stream, "%02x%c",
buf[i - start], i == per_line / 2 - 1? '-' : ' ');
if (ascii)
{
* (void *). This is to suppress the alignment warning issued by clang. */
#define ALIGNED_CAST(TYPE, ATTR) ((TYPE) (void *) (ATTR))
+/* Use "%"PRIuSIZE to format size_t with printf(). */
+#ifdef _WIN32
+#define PRIdSIZE "Id"
+#define PRIiSIZE "Ii"
+#define PRIoSIZE "Io"
+#define PRIuSIZE "Iu"
+#define PRIxSIZE "Ix"
+#define PRIXSIZE "IX"
+#else
+#define PRIdSIZE "zd"
+#define PRIiSIZE "zi"
+#define PRIoSIZE "zo"
+#define PRIuSIZE "zu"
+#define PRIxSIZE "zx"
+#define PRIXSIZE "zX"
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
userdata_len = nl_attr_get_size(dpif_upcall->userdata);
if (userdata_len < sizeof cookie.type
|| userdata_len > sizeof cookie) {
- VLOG_WARN_RL(&rl, "action upcall cookie has unexpected size %zu",
+ VLOG_WARN_RL(&rl, "action upcall cookie has unexpected size %"PRIuSIZE,
userdata_len);
return BAD_UPCALL;
}
return IPFIX_UPCALL;
} else {
VLOG_WARN_RL(&rl, "invalid user cookie of type %"PRIu16
- " and size %zu", cookie.type, userdata_len);
+ " and size %"PRIuSIZE, cookie.type, userdata_len);
return BAD_UPCALL;
}
}
ds_put_char_multiple(result, '\t', level);
ds_put_format(result, "%s:", title);
for (i = 0; i < FLOW_N_REGS; i++) {
- ds_put_format(result, " reg%zu=0x%"PRIx32, i, trace->flow.regs[i]);
+ ds_put_format(result, " reg%"PRIuSIZE"=0x%"PRIx32, i, trace->flow.regs[i]);
}
ds_put_char(result, '\n');
}
ds_put_format(ds, "%s: hit:%"PRIu64" missed:%"PRIu64"\n",
dpif_name(backer->dpif), n_hit, n_missed);
- ds_put_format(ds, "\tflows: cur: %zu, avg: %u, max: %u,"
+ ds_put_format(ds, "\tflows: cur: %"PRIuSIZE", avg: %u, max: %u,"
" life span: %lldms\n", hmap_count(&backer->subfacets),
backer->avg_n_subfacet, backer->max_n_subfacet,
backer->avg_subfacet_life);
CLS_CURSOR_FOR_EACH (facet, cr, &cursor) {
cls_rule_format(&facet->cr, &ds);
ds_put_cstr(&ds, ", ");
- ds_put_format(&ds, "n_subfacets:%zu, ", list_size(&facet->subfacets));
+ ds_put_format(&ds, "n_subfacets:%"PRIuSIZE", ", list_size(&facet->subfacets));
ds_put_format(&ds, "used:%.3fs, ", (now - facet->used) / 1000.0);
ds_put_cstr(&ds, "Datapath actions: ");
if (facet->xout.slow) {
ots = xcalloc(p->n_tables, sizeof *ots);
for (i = 0; i < p->n_tables; i++) {
ots[i].table_id = i;
- sprintf(ots[i].name, "table%zu", i);
+ sprintf(ots[i].name, "table%"PRIuSIZE, i);
ots[i].match = htonll(OFPXMT13_MASK);
ots[i].wildcards = htonll(OFPXMT13_MASK);
ots[i].write_actions = htonl(OFPAT11_OUTPUT);
-/* Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
+/* Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
/* Parse and execute operation. */
ovsdb_parser_init(&parser, operation,
- "ovsdb operation %zu of %zu", i, n_operations);
+ "ovsdb operation %"PRIuSIZE" of %"PRIuSIZE, i, n_operations);
op = ovsdb_parser_member(&parser, "op", OP_ID);
result = json_object_create();
if (op) {
monitor_length = ovsdb_jsonrpc_monitor_json_length_all(s);
if (backlog > s->reply_backlog + monitor_length * 2) {
- VLOG_INFO("%s: %zu bytes backlogged but a complete replica "
- "would only take %zu bytes, disconnecting",
+ VLOG_INFO("%s: %"PRIuSIZE" bytes backlogged but a complete replica "
+ "would only take %"PRIuSIZE" bytes, disconnecting",
jsonrpc_session_get_name(s->js),
backlog - s->reply_backlog, monitor_length);
jsonrpc_session_force_reconnect(s->js);
/* Compose header. */
sha1_bytes(json_string, length, sha1);
- snprintf(header, sizeof header, "%s%zu "SHA1_FMT"\n",
+ snprintf(header, sizeof header, "%s%"PRIuSIZE" "SHA1_FMT"\n",
magic, length, SHA1_ARGS(sha1));
/* Write. */
const struct json *name = reply->result->u.array.elems[i];
if (name->type != JSON_STRING) {
- ovs_fatal(0, "list_dbs response %zu is not string", i);
+ ovs_fatal(0, "list_dbs response %"PRIuSIZE" is not string", i);
}
svec_add(dbs, name->u.string);
}
struct shash *row;
if (rows->elems[y]->type != JSON_OBJECT) {
- ovs_fatal(0, "row %zu in table %s response is not a JSON object: "
+ ovs_fatal(0, "row %"PRIuSIZE" in table %s response is not a JSON object: "
"%s", y, ts->name, json_to_string(rows->elems[y], 0));
}
row = json_object(rows->elems[y]);
for (x = 0; x < n_columns; x++) {
const struct json *json = shash_find_data(row, columns[x]->name);
if (!json) {
- ovs_fatal(0, "row %zu in table %s response lacks %s column",
+ ovs_fatal(0, "row %"PRIuSIZE" in table %s response lacks %s column",
y, ts->name, columns[x]->name);
}
/* Print database contents. */
if (reply->result->type != JSON_ARRAY
|| reply->result->u.array.n != n_tables) {
- ovs_fatal(0, "reply is not array of %zu elements: %s",
+ ovs_fatal(0, "reply is not array of %"PRIuSIZE" elements: %s",
n_tables, json_to_string(reply->result, 0));
}
for (i = 0; i < n_tables; i++) {
if (!VLOG_DROP_DBG(&rl)) {
char *type_name = ovsdb_type_to_english(&column->type);
VLOG_DBG("Table `%s' column `%s' has type %s, not expected "
- "key type %s, value type %s, max elements %zd.",
+ "key type %s, value type %s, max elements %"PRIuSIZE".",
schema->name, column_name, type_name,
ovsdb_atomic_type_to_string(key_type),
ovsdb_atomic_type_to_string(value_type),
-/* Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
+/* Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
} else {
return ovsdb_error("referential integrity violation",
"cannot delete %s row "UUID_FMT" because "
- "of %zu remaining reference(s)",
+ "of %"PRIuSIZE" remaining reference(s)",
r->table->schema->name, UUID_ARGS(&r->uuid),
r->n_refs);
}
if (n_rows > max_rows) {
return ovsdb_error("constraint violation",
"transaction causes \"%s\" table to contain "
- "%zu rows, greater than the schema-defined "
+ "%"PRIuSIZE" rows, greater than the schema-defined "
"limit of %u row(s)",
t->table->schema->name, n_rows, max_rows);
}
/*
- * Copyright (c) 2009, 2010 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
return;
error:
- ovs_fatal(0, "\"%s\" is not exactly %zu hex digits", input, n * 2);
+ ovs_fatal(0, "\"%s\" is not exactly %"PRIuSIZE" hex digits", input, n * 2);
}
int
printf("%s:", name);
HINDEX_FOR_EACH (e, node, hindex) {
- printf(" %d(%zu)", e->value, e->node.hash & hindex->mask);
+ printf(" %d(%"PRIuSIZE")", e->value, e->node.hash & hindex->mask);
}
printf("\n");
}
printf("%s:", name);
HMAP_FOR_EACH (e, node, hmap) {
- printf(" %d(%zu)", e->value, e->node.hash & hmap->mask);
+ printf(" %d(%"PRIuSIZE")", e->value, e->node.hash & hmap->mask);
}
printf("\n");
}
}
if (buf->size) {
- printf("%zu extra bytes after last record\n", buf->size);
+ printf("%"PRIuSIZE" extra bytes after last record\n", buf->size);
}
}
odp_flow_key_from_flow(&odp_key, &flow, flow.in_port.odp_port);
if (odp_key.size > ODPUTIL_FLOW_KEY_BYTES) {
- printf ("too long: %zu > %d\n",
+ printf ("too long: %"PRIuSIZE" > %d\n",
odp_key.size, ODPUTIL_FLOW_KEY_BYTES);
exit_code = 1;
}
json_destroy(json);
for (i = 0; i < n_conditions; i++) {
- printf("condition %2zu:", i);
+ printf("condition %2"PRIuSIZE":", i);
for (j = 0; j < n_rows; j++) {
bool result = ovsdb_condition_evaluate(rows[j], &conditions[i]);
if (j % 5 == 0) {
json_destroy(json);
for (i = 0; i < n_sets; i++) {
- printf("mutation %2zu:\n", i);
+ printf("mutation %2"PRIuSIZE":\n", i);
for (j = 0; j < n_rows; j++) {
struct ovsdb_error *error;
struct ovsdb_row *row;
row = ovsdb_row_clone(rows[j]);
error = ovsdb_mutation_set_execute(row, &sets[i]);
- printf("row %zu: ", j);
+ printf("row %"PRIuSIZE": ", j);
if (error) {
print_and_free_ovsdb_error(error);
} else {
memset(cbdata.counts, 0, cbdata.n_rows * sizeof *cbdata.counts);
ovsdb_query(table, &cnd, do_query_cb, &cbdata);
- printf("query %2zu:", i);
+ printf("query %2"PRIuSIZE":", i);
for (j = 0; j < cbdata.n_rows; j++) {
if (j % 5 == 0) {
putchar(' ');
}
ovsdb_row_set_destroy(&results);
- printf("query %2zu:", i);
+ printf("query %2"PRIuSIZE":", i);
for (j = 0; j < n_rows; j++) {
int count = rows[j].class->count;
struct uuid uuid;
if (json->type == JSON_STRING && uuid_from_string(&uuid, json->u.string)) {
- char *name = xasprintf("#%zu#", *n);
+ char *name = xasprintf("#%"PRIuSIZE"#", *n);
fprintf(stderr, "%s = "UUID_FMT"\n", name, UUID_ARGS(&uuid));
ovsdb_symbol_table_put(symtab, name, &uuid, false);
free(name);
/*
- * Copyright (c) 2008, 2009, 2010, 2012 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2012, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
{
va_list args;
- fprintf(stderr, "%s:%d:%td: ", file_name, line_number, pos - line);
+ fprintf(stderr, "%s:%d:%"PRIdPTR": ", file_name, line_number, pos - line);
va_start(args, message);
vfprintf(stderr, message, args);
va_end(args);
length = ntohs(oh->length);
if (length < sizeof *oh) {
- ovs_fatal(0, "%s: %zu-byte message is too short for OpenFlow",
+ ovs_fatal(0, "%s: %"PRIuSIZE"-byte message is too short for OpenFlow",
filename, length);
}
payload = argc > 2 ? atoi(argv[2]) : 64;
if (payload > max_payload) {
- ovs_fatal(0, "payload must be between 0 and %zu bytes", max_payload);
+ ovs_fatal(0, "payload must be between 0 and %"PRIuSIZE" bytes", max_payload);
}
open_vconn(argv[1], &vconn);
printf("Reply:\n");
ofp_print(stdout, reply, reply->size, verbosity + 2);
}
- printf("%zu bytes from %s: xid=%08"PRIx32" time=%.1f ms\n",
+ printf("%"PRIuSIZE" bytes from %s: xid=%08"PRIx32" time=%.1f ms\n",
reply->size, argv[1], ntohl(rpy_hdr->xid),
(1000*(double)(end.tv_sec - start.tv_sec))
+ (.001*(end.tv_usec - start.tv_usec)));
payload_size = atoi(argv[2]);
if (payload_size > max_payload) {
- ovs_fatal(0, "payload must be between 0 and %zu bytes", max_payload);
+ ovs_fatal(0, "payload must be between 0 and %"PRIuSIZE" bytes", max_payload);
}
message_size = sizeof(struct ofp_header) + payload_size;
for (i = 0; i < MIN(a_len, b_len); i++) {
if (a[i] != b[i]) {
- printf("%s%2zu: %02"PRIx8" -> %02"PRIx8"\n",
+ printf("%s%2"PRIuSIZE": %02"PRIx8" -> %02"PRIx8"\n",
prefix, i, a[i], b[i]);
}
}
for (i = a_len; i < b_len; i++) {
- printf("%s%2zu: (none) -> %02"PRIx8"\n", prefix, i, b[i]);
+ printf("%s%2"PRIuSIZE": (none) -> %02"PRIx8"\n", prefix, i, b[i]);
}
for (i = b_len; i < a_len; i++) {
- printf("%s%2zu: %02"PRIx8" -> (none)\n", prefix, i, a[i]);
+ printf("%s%2"PRIuSIZE": %02"PRIx8" -> (none)\n", prefix, i, a[i]);
}
}
ovs_fatal(0, "Trailing garbage in hex data");
}
if (match_expout.size != sizeof(struct ofp10_match)) {
- ovs_fatal(0, "Input is %zu bytes, expected %zu",
+ ovs_fatal(0, "Input is %"PRIuSIZE" bytes, expected %"PRIuSIZE,
match_expout.size, sizeof(struct ofp10_match));
}
ovs_fatal(0, "Trailing garbage in hex data");
}
if (match_in.size != sizeof(struct ofp10_match)) {
- ovs_fatal(0, "Input is %zu bytes, expected %zu",
+ ovs_fatal(0, "Input is %"PRIuSIZE" bytes, expected %"PRIuSIZE,
match_in.size, sizeof(struct ofp10_match));
}
ovs_fatal(0, "Trailing garbage in hex data");
}
if (match_in.size != sizeof(struct ofp11_match)) {
- ovs_fatal(0, "Input is %zu bytes, expected %zu",
+ ovs_fatal(0, "Input is %"PRIuSIZE" bytes, expected %"PRIuSIZE,
match_in.size, sizeof(struct ofp11_match));
}