aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2023-03-14 16:12:51 -0700
committerGuy Harris <gharris@sonic.net>2023-03-14 16:51:41 -0700
commit64a98d35e7a320ff6956b6c4396f3300dab66036 (patch)
treee8dca6b2ad91898c7f5d5ae48830f4155f43e00b
parente13ef2e19f7e669af2997d932412d2390f8e7006 (diff)
wiretap: fix some narrowing warnings.
Make the protocol names passed to wtap_buffer_append_epdu_tag() static arrays, so we can use sizeof to compute the string length; this should keep at least some compilers from warning about a narrowing, as they can determine at compile time that the length fits in 16 bits. To prevent other warnings, make the data argument to wtap_buffer_append_epdu_tag() const. It's not modified, and it *shouldn't* be modified, so make it const so that you can pass pointers to const values to it (and so that somebody has to un-constify it if they change wtap_buffer_append_epdu_tag() so as to break the contract).
-rw-r--r--wiretap/busmaster.c15
-rw-r--r--wiretap/candump.c14
-rw-r--r--wiretap/wtap.c2
-rw-r--r--wiretap/wtap.h2
4 files changed, 22 insertions, 11 deletions
diff --git a/wiretap/busmaster.c b/wiretap/busmaster.c
index e16dffded0..1280b202f2 100644
--- a/wiretap/busmaster.c
+++ b/wiretap/busmaster.c
@@ -62,10 +62,8 @@ busmaster_gen_packet(wtap_rec *rec, Buffer *buf,
|| (msg->type == MSG_TYPE_EXT_RTR);
gboolean is_err = (msg->type == MSG_TYPE_ERR);
- static const char *const can_proto_name = "can-hostendian";
- static const char *const canfd_proto_name = "canfd";
-
- const char *proto_name = is_fd ? canfd_proto_name : can_proto_name;
+ static const char can_proto_name[] = "can-hostendian";
+ static const char canfd_proto_name[] = "canfd";
if (!priv_entry)
{
@@ -76,7 +74,14 @@ busmaster_gen_packet(wtap_rec *rec, Buffer *buf,
/* Generate Exported PDU tags for the packet info */
ws_buffer_clean(buf);
- wtap_buffer_append_epdu_tag(buf, EXP_PDU_TAG_DISSECTOR_NAME, (guint8 *)proto_name, strlen(proto_name));
+ if (is_fd)
+ {
+ wtap_buffer_append_epdu_tag(buf, EXP_PDU_TAG_DISSECTOR_NAME, (const guint8 *)canfd_proto_name, sizeof canfd_proto_name - 1);
+ }
+ else
+ {
+ wtap_buffer_append_epdu_tag(buf, EXP_PDU_TAG_DISSECTOR_NAME, (const guint8 *)can_proto_name, sizeof can_proto_name - 1);
+ }
wtap_buffer_append_epdu_end(buf);
if (is_fd)
diff --git a/wiretap/candump.c b/wiretap/candump.c
index f9e5242dbf..62f89e7b56 100644
--- a/wiretap/candump.c
+++ b/wiretap/candump.c
@@ -37,13 +37,19 @@ void register_candump(void);
static void
candump_write_packet(wtap_rec *rec, Buffer *buf, const msg_t *msg)
{
- static const char *can_proto_name = "can-hostendian";
- static const char *canfd_proto_name = "canfd";
- const char *proto_name = msg->is_fd ? canfd_proto_name : can_proto_name;
+ static const char can_proto_name[] = "can-hostendian";
+ static const char canfd_proto_name[] = "canfd";
/* Generate Exported PDU tags for the packet info */
ws_buffer_clean(buf);
- wtap_buffer_append_epdu_tag(buf, EXP_PDU_TAG_DISSECTOR_NAME, (guint8 *)proto_name, strlen(proto_name));
+ if (msg->is_fd)
+ {
+ wtap_buffer_append_epdu_tag(buf, EXP_PDU_TAG_DISSECTOR_NAME, (const guint8 *)canfd_proto_name, sizeof canfd_proto_name - 1);
+ }
+ else
+ {
+ wtap_buffer_append_epdu_tag(buf, EXP_PDU_TAG_DISSECTOR_NAME, (const guint8 *)can_proto_name, sizeof can_proto_name - 1);
+ }
wtap_buffer_append_epdu_end(buf);
if (msg->is_fd)
diff --git a/wiretap/wtap.c b/wiretap/wtap.c
index 7c6752b6ec..387406189a 100644
--- a/wiretap/wtap.c
+++ b/wiretap/wtap.c
@@ -1934,7 +1934,7 @@ wtap_full_file_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf,
}
void
-wtap_buffer_append_epdu_tag(Buffer *buf, guint16 epdu_tag, guint8 *data, guint16 data_len)
+wtap_buffer_append_epdu_tag(Buffer *buf, guint16 epdu_tag, const guint8 *data, guint16 data_len)
{
guint8 pad_len = 0;
guint space_needed = 4; /* 2 for tag field, 2 for length field */
diff --git a/wiretap/wtap.h b/wiretap/wtap.h
index 90a2aa72e4..804329a7d4 100644
--- a/wiretap/wtap.h
+++ b/wiretap/wtap.h
@@ -2222,7 +2222,7 @@ gboolean wtap_dump_can_write(const GArray *file_encaps, guint32 required_comment
* @param data_len length of data
*/
WS_DLL_PUBLIC
-void wtap_buffer_append_epdu_tag(Buffer *buf, guint16 epdu_tag, guint8 *data, guint16 data_len);
+void wtap_buffer_append_epdu_tag(Buffer *buf, guint16 epdu_tag, const guint8 *data, guint16 data_len);
/**
* Generates packet data for an unsigned integer in "exported PDU" format.