diff options
author | Michal Labedzki <michal.labedzki@tieto.com> | 2014-07-23 12:26:05 +0200 |
---|---|---|
committer | Michal Labedzki <michal.labedzki@tieto.com> | 2014-09-22 10:52:03 +0000 |
commit | 56a09d24dcdcaddae1cb67a18bbc2fd588c427ed (patch) | |
tree | a9961e4700a00680f7247d714709e6164f9e5d9d /wiretap | |
parent | c1d6a4123a2e100a77ae8ec2b3d01544f168febc (diff) | |
download | wireshark-56a09d24dcdcaddae1cb67a18bbc2fd588c427ed.tar.gz |
Try to fix some buildbot warnings
Most interesting are:
warning: cannot optimize loop, the loop counter may overflow [-Wunsafe-loop-optimizations]
warning: ISO C forbids zero-size array [-Wpedantic]
warning: ISO C90 doesn't support unnamed structs/unions [-Wpedantic]
warning: cast discards '__attribute__((const))' qualifier from pointer target type [-Wcast-qual
warning: initializer element is not computable at load time [enabled by default]
Change-Id: I5573c6bdca856a304877d9bef643f8c0fa93cdaf
Reviewed-on: https://code.wireshark.org/review/3174
Petri-Dish: Michal Labedzki <michal.labedzki@tieto.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michal Labedzki <michal.labedzki@tieto.com>
Diffstat (limited to 'wiretap')
-rw-r--r-- | wiretap/file_access.c | 12 | ||||
-rw-r--r-- | wiretap/file_wrappers.c | 4 | ||||
-rw-r--r-- | wiretap/logcat.c | 20 | ||||
-rw-r--r-- | wiretap/logcat.h | 6 | ||||
-rw-r--r-- | wiretap/logcat_text.c | 37 | ||||
-rw-r--r-- | wiretap/merge.c | 5 |
6 files changed, 46 insertions, 38 deletions
diff --git a/wiretap/file_access.c b/wiretap/file_access.c index 0ce14727c9..6e216d8010 100644 --- a/wiretap/file_access.c +++ b/wiretap/file_access.c @@ -1510,10 +1510,8 @@ init_file_types_subtypes(void) /* if subtype is WTAP_FILE_TYPE_SUBTYPE_UNKNOWN, then create a new subtype as well as register it, else replace the existing entry in that spot */ -int -wtap_register_file_type_subtypes(const struct file_type_subtype_info* fi, const int subtype) -{ - struct file_type_subtype_info* finfo = NULL; +int wtap_register_file_type_subtypes(const struct file_type_subtype_info* fi, const int subtype) { + struct file_type_subtype_info* finfo; init_file_types_subtypes(); if (!fi || !fi->name || !fi->short_name || subtype > wtap_num_file_types_subtypes) { @@ -1560,10 +1558,8 @@ wtap_register_file_type_subtypes(const struct file_type_subtype_info* fi, const /* De-registers a file writer - they can never be removed from the GArray, but we can "clear" an entry. */ -void -wtap_deregister_file_type_subtype(const int subtype) -{ - struct file_type_subtype_info* finfo = NULL; +void wtap_deregister_file_type_subtype(const int subtype) { + struct file_type_subtype_info* finfo; if (subtype < 0 || subtype >= wtap_num_file_types_subtypes) { g_error("invalid file type to de-register"); diff --git a/wiretap/file_wrappers.c b/wiretap/file_wrappers.c index 65c35d1e6c..667727346e 100644 --- a/wiretap/file_wrappers.c +++ b/wiretap/file_wrappers.c @@ -1641,7 +1641,11 @@ gzwfile_write(GZWFILE_T state, const void *buf, guint len) /* directly compress user buffer to file */ strm->avail_in = len; +#if ZLIB_CONST + strm->next_in = (z_const Bytef *)buf; +#else strm->next_in = (Bytef *)buf; +#endif state->pos += len; if (gz_comp(state, Z_NO_FLUSH) == -1) return 0; diff --git a/wiretap/logcat.c b/wiretap/logcat.c index ff80f99a39..d71f583b9d 100644 --- a/wiretap/logcat.c +++ b/wiretap/logcat.c @@ -50,7 +50,9 @@ static gint detect_version(wtap *wth, int *err, gchar **err_info) struct logger_entry_v2 *log_entry_v2; guint8 *buffer; guint16 tmp; - guint8 *msg_payload, *msg_part, *msg_end; + guint8 *msg_payload; + guint8 *msg_part; + guint8 *msg_end; guint16 msg_len; /* 16-bit payload length */ @@ -90,11 +92,11 @@ static gint detect_version(wtap *wth, int *err, gchar **err_info) * version is in use. First assume the smallest msg. */ for (version = 1; version <= 2; ++version) { if (version == 1) { - msg_payload = log_entry->msg; + msg_payload = (guint8 *) (log_entry + 1); entry_len = sizeof(*log_entry) + payload_length; } else if (version == 2) { /* v2 is 4 bytes longer */ - msg_payload = log_entry_v2->msg; + msg_payload = (guint8 *) (log_entry_v2 + 1); entry_len = sizeof(*log_entry_v2) + payload_length; if (hdr_size != sizeof(*log_entry_v2)) continue; @@ -137,18 +139,18 @@ static gint detect_version(wtap *wth, int *err, gchar **err_info) } gint logcat_exported_pdu_length(const guint8 *pd) { - guint16 *tag; - guint16 *tag_length; - gint length = 0; + const guint16 *tag; + const guint16 *tag_length; + gint length = 0; - tag = (guint16 *) pd; + tag = (const guint16 *) pd; while(GINT16_FROM_BE(*tag)) { - tag_length = (guint16 *) (pd + 2); + tag_length = (const guint16 *) (pd + 2); length += 2 + 2 + GINT16_FROM_BE(*tag_length); pd += 2 + 2 + GINT16_FROM_BE(*tag_length); - tag = (guint16 *) pd; + tag = (const guint16 *) pd; } length += 2 + 2; diff --git a/wiretap/logcat.h b/wiretap/logcat.h index 9b2ea5cc25..71a0e7da5b 100644 --- a/wiretap/logcat.h +++ b/wiretap/logcat.h @@ -39,7 +39,7 @@ struct logger_entry { gint32 tid; /* generating process's tid */ gint32 sec; /* seconds since Epoch */ gint32 nsec; /* nanoseconds */ - char msg[0]; /* the entry's payload */ +/* char msg[0]; *//* the entry's payload */ }; struct logger_entry_v2 { @@ -53,8 +53,8 @@ struct logger_entry_v2 { /* v1: not present */ guint32 euid; /* v2: effective UID of logger */ guint32 lid; /* v3: log id of the payload */ - }; - char msg[0]; /* the entry's payload */ + } id; +/* char msg[0]; *//* the entry's payload */ }; int logcat_open(wtap *wth, int *err, gchar **err_info); diff --git a/wiretap/logcat_text.c b/wiretap/logcat_text.c index 75e651dca1..006e82c025 100644 --- a/wiretap/logcat_text.c +++ b/wiretap/logcat_text.c @@ -56,16 +56,16 @@ static gchar get_priority(const guint8 priority) { static gint buffered_detect_version(const guint8 *pd) { - struct logger_entry *log_entry; - struct logger_entry_v2 *log_entry_v2; + const struct logger_entry *log_entry; + const struct logger_entry_v2 *log_entry_v2; gint version; - guint8 *msg_payload = NULL; + const guint8 *msg_payload = NULL; guint8 *msg_part; guint8 *msg_end; guint16 msg_len; - log_entry_v2 = (struct logger_entry_v2 *) pd; - log_entry = (struct logger_entry *) pd; + log_entry_v2 = (const struct logger_entry_v2 *) pd; + log_entry = (const struct logger_entry *) pd; /* must contain at least priority and two nulls as separator */ if (log_entry->len < 3) @@ -79,10 +79,10 @@ static gint buffered_detect_version(const guint8 *pd) * version is in use. First assume the smallest msg. */ for (version = 1; version <= 2; ++version) { if (version == 1) { - msg_payload = log_entry->msg; + msg_payload = (const guint8 *) (log_entry + 1); } else if (version == 2) { /* v2 is 4 bytes longer */ - msg_payload = log_entry_v2->msg; + msg_payload = (const guint8 *) (log_entry_v2 + 1); if (log_entry_v2->hdr_size != sizeof(*log_entry_v2)) continue; } @@ -427,6 +427,7 @@ static gboolean logcat_text_dump_text(wtap_dumper *wdh, gint32 tid; gint32 seconds; gint32 milliseconds; + const guint8 *msg_payload = NULL; const gchar *msg_begin; gint msg_pre_skip; gchar *log; @@ -458,8 +459,8 @@ static gboolean logcat_text_dump_text(wtap_dumper *wdh, logcat_version = pseudo_header->logcat.version; } - log_entry = (struct logger_entry *) pd; - log_entry_v2 = (struct logger_entry_v2 *) pd; + log_entry = (const struct logger_entry *) pd; + log_entry_v2 = (const struct logger_entry_v2 *) pd; payload_length = GINT32_FROM_LE(log_entry->len); pid = GINT32_FROM_LE(log_entry->pid); @@ -469,15 +470,19 @@ static gboolean logcat_text_dump_text(wtap_dumper *wdh, /* msg: <prio:1><tag:N>\0<msg:N>\0 with N >= 0, last \0 can be missing */ if (logcat_version == 1) { - priority = get_priority(log_entry->msg[0]); - tag = log_entry->msg + 1; + msg_payload = (const guint8 *) (log_entry + 1); + + priority = get_priority(msg_payload[0]); + tag = msg_payload + 1; msg_pre_skip = 1 + (gint) strlen(tag) + 1; - msg_begin = log_entry->msg + msg_pre_skip; + msg_begin = msg_payload + msg_pre_skip; } else if (logcat_version == 2) { - priority = get_priority(log_entry_v2->msg[0]); - tag = log_entry_v2->msg + 1; + msg_payload = (const guint8 *) (log_entry_v2 + 1); + + priority = get_priority(msg_payload[0]); + tag = msg_payload + 1; msg_pre_skip = 1 + (gint) strlen(tag) + 1; - msg_begin = log_entry_v2->msg + msg_pre_skip; + msg_begin = msg_payload + msg_pre_skip; } else { *err = WTAP_ERR_UNSUPPORTED; return FALSE; @@ -533,7 +538,7 @@ static gboolean logcat_text_dump_text(wtap_dumper *wdh, case WTAP_ENCAP_LOGCAT_THREADTIME: case WTAP_ENCAP_LOGCAT_LONG: if (dumper->type == wdh->encap) { - if (!wtap_dump_file_write(wdh, (gchar*) pd, phdr->caplen, err)) { + if (!wtap_dump_file_write(wdh, (const gchar*) pd, phdr->caplen, err)) { return FALSE; } } else { diff --git a/wiretap/merge.c b/wiretap/merge.c index bea6b53220..bf10f4ccdc 100644 --- a/wiretap/merge.c +++ b/wiretap/merge.c @@ -50,7 +50,8 @@ merge_open_in_files(int in_file_count, char *const *in_file_names, merge_in_file_t **in_files, int *err, gchar **err_info, int *err_fileno) { - int i, j; + gint i; + gint j; size_t files_size = in_file_count * sizeof(merge_in_file_t); merge_in_file_t *files; gint64 size; @@ -73,7 +74,7 @@ merge_open_in_files(int in_file_count, char *const *in_file_names, } size = wtap_file_size(files[i].wth, err); if (size == -1) { - for (j = 0; j <= i; j++) + for (j = 0; j + 1 > j && j <= i; j++) wtap_close(files[j].wth); *err_fileno = i; return FALSE; |