Replace g_assert() with ws_assert() in places

This commit is contained in:
João Valverde 2021-05-24 00:46:43 +01:00 committed by Wireshark GitLab Utility
parent ef0f022f86
commit 4aff36d501
24 changed files with 122 additions and 96 deletions

View File

@ -12,6 +12,7 @@
#include "wtap-int.h" #include "wtap-int.h"
#include "file_wrappers.h" #include "file_wrappers.h"
#include "capsa.h" #include "capsa.h"
#include <wsutil/ws_assert.h>
/* /*
* A file begins with a header containing: * A file begins with a header containing:
@ -368,7 +369,7 @@ capsa_read_packet(wtap *wth, FILE_T fh, wtap_rec *rec,
break; break;
default: default:
g_assert_not_reached(); ws_assert_not_reached();
*err = WTAP_ERR_INTERNAL; *err = WTAP_ERR_INTERNAL;
*err_info = g_strdup_printf("capsa: format indicator is %u", capsa->format_indicator); *err_info = g_strdup_printf("capsa: format indicator is %u", capsa->format_indicator);
return -1; return -1;

View File

@ -18,6 +18,7 @@
#ifdef HAVE_PLUGINS #ifdef HAVE_PLUGINS
#include <wsutil/plugins.h> #include <wsutil/plugins.h>
#endif #endif
#include <wsutil/ws_assert.h>
#include "wtap-int.h" #include "wtap-int.h"
#include "wtap_modules.h" #include "wtap_modules.h"
@ -461,7 +462,7 @@ static void
set_heuristic_routine(void) set_heuristic_routine(void)
{ {
guint i; guint i;
g_assert(open_info_arr != NULL); ws_assert(open_info_arr != NULL);
for (i = 0; i < open_info_arr->len; i++) { for (i = 0; i < open_info_arr->len; i++) {
if (open_routines[i].type == OPEN_INFO_HEURISTIC) { if (open_routines[i].type == OPEN_INFO_HEURISTIC) {
@ -469,10 +470,10 @@ set_heuristic_routine(void)
break; break;
} }
/* sanity check */ /* sanity check */
g_assert(open_routines[i].type == OPEN_INFO_MAGIC); ws_assert(open_routines[i].type == OPEN_INFO_MAGIC);
} }
g_assert(heuristic_open_routine_idx > 0); ws_assert(heuristic_open_routine_idx > 0);
} }
void void
@ -1255,7 +1256,7 @@ void
wtap_init_file_type_subtypes(void) wtap_init_file_type_subtypes(void)
{ {
/* Don't do this twice. */ /* Don't do this twice. */
g_assert(file_type_subtype_table_arr == NULL); ws_assert(file_type_subtype_table_arr == NULL);
/* /*
* Estimate the number of file types/subtypes as twice the * Estimate the number of file types/subtypes as twice the
@ -1833,7 +1834,7 @@ wtap_pcap_file_type_subtype(void)
* Make sure pcap was registered as a file type/subtype; * Make sure pcap was registered as a file type/subtype;
* it's one of our "native" formats. * it's one of our "native" formats.
*/ */
g_assert(pcap_file_type_subtype != -1); ws_assert(pcap_file_type_subtype != -1);
return pcap_file_type_subtype; return pcap_file_type_subtype;
} }
@ -1847,7 +1848,7 @@ wtap_pcap_nsec_file_type_subtype(void)
* Make sure nanosecond-resolution pcap was registered * Make sure nanosecond-resolution pcap was registered
* as a file type/subtype; it's one of our "native" formats. * as a file type/subtype; it's one of our "native" formats.
*/ */
g_assert(pcap_nsec_file_type_subtype != -1); ws_assert(pcap_nsec_file_type_subtype != -1);
return pcap_nsec_file_type_subtype; return pcap_nsec_file_type_subtype;
} }
@ -1861,7 +1862,7 @@ wtap_pcapng_file_type_subtype(void)
* Make sure pcapng was registered as a file type/subtype; * Make sure pcapng was registered as a file type/subtype;
* it's one of our "native" formats. * it's one of our "native" formats.
*/ */
g_assert(pcapng_file_type_subtype != -1); ws_assert(pcapng_file_type_subtype != -1);
return pcapng_file_type_subtype; return pcapng_file_type_subtype;
} }

View File

@ -21,6 +21,7 @@
#include "wtap-int.h" #include "wtap-int.h"
#include "file_wrappers.h" #include "file_wrappers.h"
#include <wsutil/file_util.h> #include <wsutil/file_util.h>
#include <wsutil/ws_assert.h>
#ifdef HAVE_ZLIB #ifdef HAVE_ZLIB
#define ZLIB_CONST #define ZLIB_CONST
@ -1072,7 +1073,7 @@ file_seek(FILE_T file, gint64 offset, int whence, int *err)
guint n; guint n;
if (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END) { if (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END) {
g_assert_not_reached(); ws_assert_not_reached();
/* /*
*err = EINVAL; *err = EINVAL;
return -1; return -1;

View File

@ -147,6 +147,7 @@ Number S/R Length Timer MAC Address MAC Address
#include <wsutil/str_util.h> #include <wsutil/str_util.h>
#include <wsutil/strtoi.h> #include <wsutil/strtoi.h>
#include <wsutil/ws_assert.h>
#define ISERIES_LINE_LENGTH 270 #define ISERIES_LINE_LENGTH 270
#define ISERIES_HDR_LINES_TO_CHECK 100 #define ISERIES_HDR_LINES_TO_CHECK 100
@ -1015,7 +1016,7 @@ iseries_UNICODE_to_ASCII (guint8 * buf, guint bytes)
if (buf[i] == 0x0A) if (buf[i] == 0x0A)
break; break;
} }
g_assert(bufptr < buf + bytes); ws_assert(bufptr < buf + bytes);
*bufptr = '\0'; *bufptr = '\0';
return i; return i;
} }

View File

@ -18,6 +18,7 @@
#include "pcap-encap.h" #include "pcap-encap.h"
#include "libpcap.h" #include "libpcap.h"
#include "erf-common.h" #include "erf-common.h"
#include <wsutil/ws_assert.h>
/* See source to the "libpcap" library for information on the "libpcap" /* See source to the "libpcap" library for information on the "libpcap"
file format. */ file format. */
@ -584,7 +585,7 @@ done:
break; break;
default: default:
g_assert_not_reached(); ws_assert_not_reached();
} }
/* /*
@ -969,7 +970,7 @@ static int libpcap_read_header(wtap *wth, FILE_T fh, int *err, gchar **err_info,
break; break;
default: default:
g_assert_not_reached(); ws_assert_not_reached();
bytes_to_read = 0; bytes_to_read = 0;
} }
if (!wtap_read_bytes_or_eof(fh, hdr, bytes_to_read, err, err_info)) if (!wtap_read_bytes_or_eof(fh, hdr, bytes_to_read, err, err_info))

View File

@ -31,6 +31,7 @@
#include <wsutil/filesystem.h> #include <wsutil/filesystem.h>
#include "wsutil/os_version_info.h" #include "wsutil/os_version_info.h"
#include <wsutil/wslog.h> #include <wsutil/wslog.h>
#include <wsutil/ws_assert.h>
@ -70,7 +71,7 @@ merge_idb_merge_mode_to_string(const int mode)
static void static void
cleanup_in_file(merge_in_file_t *in_file) cleanup_in_file(merge_in_file_t *in_file)
{ {
g_assert(in_file != NULL); ws_assert(in_file != NULL);
wtap_close(in_file->wth); wtap_close(in_file->wth);
in_file->wth = NULL; in_file->wth = NULL;
@ -83,17 +84,17 @@ cleanup_in_file(merge_in_file_t *in_file)
} }
static void static void
add_idb_index_map(merge_in_file_t *in_file, const guint orig_index, const guint found_index) add_idb_index_map(merge_in_file_t *in_file, const guint orig_index _U_, const guint found_index)
{ {
g_assert(in_file != NULL); ws_assert(in_file != NULL);
g_assert(in_file->idb_index_map != NULL); ws_assert(in_file->idb_index_map != NULL);
/* /*
* we didn't really need the orig_index, since just appending to the array * we didn't really need the orig_index, since just appending to the array
* should result in the orig_index being its location in the array; but we * should result in the orig_index being its location in the array; but we
* pass it into this function to do a sanity check here * pass it into this function to do a sanity check here
*/ */
g_assert(orig_index == in_file->idb_index_map->len); ws_assert(orig_index == in_file->idb_index_map->len);
g_array_append_val(in_file->idb_index_map, found_index); g_array_append_val(in_file->idb_index_map, found_index);
} }
@ -465,7 +466,7 @@ is_duplicate_idb(const wtap_block_t idb1, const wtap_block_t idb2)
char *idb1_if_hardware, *idb2_if_hardware; char *idb1_if_hardware, *idb2_if_hardware;
char *idb1_if_os, *idb2_if_os; char *idb1_if_os, *idb2_if_os;
g_assert(idb1 && idb2); ws_assert(idb1 && idb2);
idb1_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(idb1); idb1_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(idb1);
idb2_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(idb2); idb2_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(idb2);
@ -627,18 +628,18 @@ all_idbs_are_duplicates(const merge_in_file_t *in_files, const guint in_file_cou
wtap_block_t first_file_idb, other_file_idb; wtap_block_t first_file_idb, other_file_idb;
guint i, j; guint i, j;
g_assert(in_files != NULL); ws_assert(in_files != NULL);
/* get the first file's info */ /* get the first file's info */
first_idb_list = wtap_file_get_idb_info(in_files[0].wth); first_idb_list = wtap_file_get_idb_info(in_files[0].wth);
g_assert(first_idb_list->interface_data); ws_assert(first_idb_list->interface_data);
first_idb_list_size = first_idb_list->interface_data->len; first_idb_list_size = first_idb_list->interface_data->len;
/* now compare the other input files with that */ /* now compare the other input files with that */
for (i = 1; i < in_file_count; i++) { for (i = 1; i < in_file_count; i++) {
other_idb_list = wtap_file_get_idb_info(in_files[i].wth); other_idb_list = wtap_file_get_idb_info(in_files[i].wth);
g_assert(other_idb_list->interface_data); ws_assert(other_idb_list->interface_data);
other_idb_list_size = other_idb_list->interface_data->len; other_idb_list_size = other_idb_list->interface_data->len;
if (other_idb_list_size != first_idb_list_size) { if (other_idb_list_size != first_idb_list_size) {
@ -687,10 +688,10 @@ find_duplicate_idb(const wtap_block_t input_file_idb,
wtap_block_t merged_idb; wtap_block_t merged_idb;
guint i; guint i;
g_assert(input_file_idb != NULL); ws_assert(input_file_idb != NULL);
g_assert(merged_idb_list != NULL); ws_assert(merged_idb_list != NULL);
g_assert(merged_idb_list->interface_data != NULL); ws_assert(merged_idb_list->interface_data != NULL);
g_assert(found_index != NULL); ws_assert(found_index != NULL);
for (i = 0; i < merged_idb_list->interface_data->len; i++) { for (i = 0; i < merged_idb_list->interface_data->len; i++) {
merged_idb = g_array_index(merged_idb_list->interface_data, wtap_block_t, i); merged_idb = g_array_index(merged_idb_list->interface_data, wtap_block_t, i);
@ -712,9 +713,9 @@ add_idb_to_merged_file(wtapng_iface_descriptions_t *merged_idb_list,
wtap_block_t idb = wtap_block_create(WTAP_BLOCK_IF_ID_AND_INFO); wtap_block_t idb = wtap_block_create(WTAP_BLOCK_IF_ID_AND_INFO);
wtapng_if_descr_mandatory_t* idb_mand; wtapng_if_descr_mandatory_t* idb_mand;
g_assert(merged_idb_list != NULL); ws_assert(merged_idb_list != NULL);
g_assert(merged_idb_list->interface_data != NULL); ws_assert(merged_idb_list->interface_data != NULL);
g_assert(input_file_idb != NULL); ws_assert(input_file_idb != NULL);
wtap_block_copy(idb, input_file_idb); wtap_block_copy(idb, input_file_idb);
idb_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(idb); idb_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(idb);
@ -812,9 +813,9 @@ static gboolean
map_rec_interface_id(wtap_rec *rec, const merge_in_file_t *in_file) map_rec_interface_id(wtap_rec *rec, const merge_in_file_t *in_file)
{ {
guint current_interface_id = 0; guint current_interface_id = 0;
g_assert(rec != NULL); ws_assert(rec != NULL);
g_assert(in_file != NULL); ws_assert(in_file != NULL);
g_assert(in_file->idb_index_map != NULL); ws_assert(in_file->idb_index_map != NULL);
if (rec->presence_flags & WTAP_HAS_INTERFACE_ID) { if (rec->presence_flags & WTAP_HAS_INTERFACE_ID) {
current_interface_id = rec->rec_header.packet_header.interface_id; current_interface_id = rec->rec_header.packet_header.interface_id;
@ -1000,15 +1001,15 @@ merge_files_common(const gchar* out_filename, /* normal output mode */
wtapng_iface_descriptions_t *idb_inf = NULL; wtapng_iface_descriptions_t *idb_inf = NULL;
GArray *dsb_combined = NULL; GArray *dsb_combined = NULL;
g_assert(in_file_count > 0); ws_assert(in_file_count > 0);
g_assert(in_filenames != NULL); ws_assert(in_filenames != NULL);
g_assert(err != NULL); ws_assert(err != NULL);
g_assert(err_info != NULL); ws_assert(err_info != NULL);
g_assert(err_fileno != NULL); ws_assert(err_fileno != NULL);
g_assert(err_framenum != NULL); ws_assert(err_framenum != NULL);
/* if a callback was given, it has to have a callback function ptr */ /* if a callback was given, it has to have a callback function ptr */
g_assert((cb != NULL) ? (cb->callback_func != NULL) : TRUE); ws_assert((cb != NULL) ? (cb->callback_func != NULL) : TRUE);
ws_debug("merge_files: begin"); ws_debug("merge_files: begin");
@ -1116,7 +1117,7 @@ merge_files(const gchar* out_filename, const int file_type,
int *err, gchar **err_info, guint *err_fileno, int *err, gchar **err_info, guint *err_fileno,
guint32 *err_framenum) guint32 *err_framenum)
{ {
g_assert(out_filename != NULL); ws_assert(out_filename != NULL);
return merge_files_common(out_filename, NULL, NULL, return merge_files_common(out_filename, NULL, NULL,
file_type, in_filenames, in_file_count, file_type, in_filenames, in_file_count,
@ -1138,7 +1139,7 @@ merge_files_to_tempfile(gchar **out_filenamep, const char *pfx,
int *err, gchar **err_info, guint *err_fileno, int *err, gchar **err_info, guint *err_fileno,
guint32 *err_framenum) guint32 *err_framenum)
{ {
g_assert(out_filenamep != NULL); ws_assert(out_filenamep != NULL);
/* no temporary file name yet */ /* no temporary file name yet */
*out_filenamep = NULL; *out_filenamep = NULL;

View File

@ -12,6 +12,7 @@
#include "wtap-int.h" #include "wtap-int.h"
#include "file_wrappers.h" #include "file_wrappers.h"
#include "netscaler.h" #include "netscaler.h"
#include <wsutil/ws_assert.h>
/* Defines imported from netscaler code: nsperfrc.h */ /* Defines imported from netscaler code: nsperfrc.h */
@ -2188,7 +2189,7 @@ static gboolean nstrace_add_signature(wtap_dumper *wdh, int *err)
nstrace->page_offset += (guint16) sig35.sig_RecordSize; nstrace->page_offset += (guint16) sig35.sig_RecordSize;
} else } else
{ {
g_assert_not_reached(); ws_assert_not_reached();
return FALSE; return FALSE;
} }
@ -2256,7 +2257,7 @@ nstrace_add_abstime(wtap_dumper *wdh, const wtap_rec *rec,
} else } else
{ {
g_assert_not_reached(); ws_assert_not_reached();
return FALSE; return FALSE;
} }
@ -2299,7 +2300,7 @@ static gboolean nstrace_dump(wtap_dumper *wdh, const wtap_rec *rec,
return FALSE; return FALSE;
} else } else
{ {
g_assert_not_reached(); ws_assert_not_reached();
return FALSE; return FALSE;
} }
} }
@ -2403,13 +2404,13 @@ static gboolean nstrace_dump(wtap_dumper *wdh, const wtap_rec *rec,
nstrace->page_offset += (guint16) rec->rec_header.packet_header.caplen; nstrace->page_offset += (guint16) rec->rec_header.packet_header.caplen;
} else } else
{ {
g_assert_not_reached(); ws_assert_not_reached();
return FALSE; return FALSE;
} }
break; break;
default: default:
g_assert_not_reached(); ws_assert_not_reached();
return FALSE; return FALSE;
} }

View File

@ -30,6 +30,7 @@
#include "wsutil/os_version_info.h" #include "wsutil/os_version_info.h"
#include "wsutil/str_util.h" #include "wsutil/str_util.h"
#include <wsutil/inet_addr.h> #include <wsutil/inet_addr.h>
#include <wsutil/ws_assert.h>
#include "nettrace_3gpp_32_423.h" #include "nettrace_3gpp_32_423.h"
@ -449,7 +450,7 @@ nettrace_msg_to_packet(nettrace_3gpp_32_423_file_info_t *file_info, wtap_rec *re
if (exported_pdu_info.presence_flags & EXP_PDU_TAG_COL_PROT_BIT) { if (exported_pdu_info.presence_flags & EXP_PDU_TAG_COL_PROT_BIT) {
/* The assert prevents static code analyzers to raise warnings */ /* The assert prevents static code analyzers to raise warnings */
g_assert(exported_pdu_info.proto_col_str); ws_assert(exported_pdu_info.proto_col_str);
exp_pdu_tags_len += 4 + (int)strlen(exported_pdu_info.proto_col_str); exp_pdu_tags_len += 4 + (int)strlen(exported_pdu_info.proto_col_str);
} }

View File

@ -47,6 +47,7 @@
#include "wtap-int.h" #include "wtap-int.h"
#include "file_wrappers.h" #include "file_wrappers.h"
#include "ngsniffer.h" #include "ngsniffer.h"
#include <wsutil/ws_assert.h>
/* Magic number in Sniffer files. */ /* Magic number in Sniffer files. */
static const char ngsniffer_magic[] = { static const char ngsniffer_magic[] = {
@ -1115,7 +1116,7 @@ ngsniffer_seek_read(wtap *wth, gint64 seek_off,
/* /*
* "Can't happen". * "Can't happen".
*/ */
g_assert_not_reached(); ws_assert_not_reached();
return FALSE; return FALSE;
} }
@ -2500,7 +2501,7 @@ ng_read_bytes_or_eof(wtap *wth, void *buffer, unsigned int nbytes, gboolean is_r
random stream open, allocate the first element for the random stream open, allocate the first element for the
list of blobs, and make it the last element as well. */ list of blobs, and make it the last element as well. */
if (wth->random_fh != NULL) { if (wth->random_fh != NULL) {
g_assert(ngsniffer->first_blob == NULL); ws_assert(ngsniffer->first_blob == NULL);
blob = g_new(blob_info_t,1); blob = g_new(blob_info_t,1);
blob->blob_comp_offset = comp_stream->comp_offset; blob->blob_comp_offset = comp_stream->comp_offset;
blob->blob_uncomp_offset = comp_stream->uncomp_offset; blob->blob_uncomp_offset = comp_stream->uncomp_offset;
@ -2829,7 +2830,7 @@ ng_file_seek_rand(wtap *wth, gint64 offset, int *err, gchar **err_info)
the blob, as otherwise it'd mean we need to seek before the blob, as otherwise it'd mean we need to seek before
the beginning or after the end of this blob. */ the beginning or after the end of this blob. */
delta = offset - ngsniffer->rand.uncomp_offset; delta = offset - ngsniffer->rand.uncomp_offset;
g_assert(delta >= 0 && (unsigned long)delta < ngsniffer->rand.nbytes); ws_assert(delta >= 0 && (unsigned long)delta < ngsniffer->rand.nbytes);
} }
/* OK, the place to which we're seeking is in the buffer; adjust /* OK, the place to which we're seeking is in the buffer; adjust

View File

@ -26,6 +26,7 @@
#include <wsutil/wslog.h> #include <wsutil/wslog.h>
#include <wsutil/strtoi.h> #include <wsutil/strtoi.h>
#include <wsutil/glib-compat.h> #include <wsutil/glib-compat.h>
#include <wsutil/ws_assert.h>
#include "wtap-int.h" #include "wtap-int.h"
#include "file_wrappers.h" #include "file_wrappers.h"
@ -412,7 +413,7 @@ static GHashTable *option_handlers[NUM_BT_INDICES];
static gboolean static gboolean
get_block_type_index(guint block_type, guint *bt_index) get_block_type_index(guint block_type, guint *bt_index)
{ {
g_assert(bt_index); ws_assert(bt_index);
switch (block_type) { switch (block_type) {
@ -3258,7 +3259,7 @@ pcapng_seek_read(wtap *wth, gint64 seek_off,
* First, make sure we have at least one section; if we don't, that's * First, make sure we have at least one section; if we don't, that's
* an internal error. * an internal error.
*/ */
g_assert(pcapng->sections->len >= 1); ws_assert(pcapng->sections->len >= 1);
/* /*
* Now scan backwards through the array to find the first section * Now scan backwards through the array to find the first section
@ -3278,7 +3279,7 @@ pcapng_seek_read(wtap *wth, gint64 seek_off,
* If that's section 0, something's wrong; that section should * If that's section 0, something's wrong; that section should
* have an offset of 0. * have an offset of 0.
*/ */
g_assert(section_number != 0); ws_assert(section_number != 0);
section_number--; section_number--;
} }
@ -4844,7 +4845,7 @@ static void write_wtap_idb_option(wtap_block_t block _U_, guint option_id, wtap_
break; break;
default: default:
g_assert_not_reached(); ws_assert_not_reached();
return; return;
} }

View File

@ -27,6 +27,7 @@
#include <wsutil/epochs.h> #include <wsutil/epochs.h>
#include <wsutil/802_11-utils.h> #include <wsutil/802_11-utils.h>
#include <wsutil/ws_assert.h>
#include "wtap-int.h" #include "wtap-int.h"
#include "file_wrappers.h" #include "file_wrappers.h"
@ -172,7 +173,7 @@ wtap_open_return_val peekclassic_open(wtap *wth, int *err, gchar **err_info)
* is zero, and check some other fields; this isn't perfect, * is zero, and check some other fields; this isn't perfect,
* and we may have to add more checks at some point. * and we may have to add more checks at some point.
*/ */
g_assert(sizeof(ep_hdr.master) == PEEKCLASSIC_MASTER_HDR_SIZE); ws_assert(sizeof(ep_hdr.master) == PEEKCLASSIC_MASTER_HDR_SIZE);
if (!wtap_read_bytes(wth->fh, &ep_hdr.master, if (!wtap_read_bytes(wth->fh, &ep_hdr.master,
(int)sizeof(ep_hdr.master), err, err_info)) { (int)sizeof(ep_hdr.master), err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ) if (*err != WTAP_ERR_SHORT_READ)
@ -201,7 +202,7 @@ wtap_open_return_val peekclassic_open(wtap *wth, int *err, gchar **err_info)
case 6: case 6:
case 7: case 7:
/* get the secondary header */ /* get the secondary header */
g_assert(sizeof(ep_hdr.secondary.v567) == ws_assert(sizeof(ep_hdr.secondary.v567) ==
PEEKCLASSIC_V567_HDR_SIZE); PEEKCLASSIC_V567_HDR_SIZE);
if (!wtap_read_bytes(wth->fh, &ep_hdr.secondary.v567, if (!wtap_read_bytes(wth->fh, &ep_hdr.secondary.v567,
(int)sizeof(ep_hdr.secondary.v567), err, err_info)) { (int)sizeof(ep_hdr.secondary.v567), err, err_info)) {
@ -343,7 +344,7 @@ wtap_open_return_val peekclassic_open(wtap *wth, int *err, gchar **err_info)
default: default:
/* this is impossible */ /* this is impossible */
g_assert_not_reached(); ws_assert_not_reached();
} }
wth->snapshot_length = 0; /* not available in header */ wth->snapshot_length = 0; /* not available in header */

View File

@ -14,6 +14,8 @@
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <wsutil/ws_assert.h>
/* /*
pppdump records pppdump records
Daniel Thompson (STMicroelectronics) <daniel.thompson@st.com> Daniel Thompson (STMicroelectronics) <daniel.thompson@st.com>
@ -457,7 +459,7 @@ process_data(pppdump_t *state, FILE_T fh, pkt_t *pkt, int n, guint8 *pd,
pid->offset = pkt->id_offset; pid->offset = pkt->id_offset;
pid->num_bytes_to_skip = pid->num_bytes_to_skip =
pkt->sd_offset - pkt->id_offset - 3; pkt->sd_offset - pkt->id_offset - 3;
g_assert(pid->num_bytes_to_skip >= 0); ws_assert(pid->num_bytes_to_skip >= 0);
} }
num_bytes--; num_bytes--;
@ -557,7 +559,7 @@ collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd,
* sequential processing. * sequential processing.
*/ */
if (state->num_bytes > 0) { if (state->num_bytes > 0) {
g_assert(num_bytes_to_skip == 0); ws_assert(num_bytes_to_skip == 0);
pkt = state->pkt; pkt = state->pkt;
num_written = process_data(state, fh, pkt, state->num_bytes, num_written = process_data(state, fh, pkt, state->num_bytes,
pd, err, err_info, pid); pd, err, err_info, pid);
@ -631,7 +633,7 @@ collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd,
if (n == 0) if (n == 0)
continue; continue;
g_assert(num_bytes_to_skip < n); ws_assert(num_bytes_to_skip < n);
while (num_bytes_to_skip) { while (num_bytes_to_skip) {
if (file_getc(fh) == EOF) if (file_getc(fh) == EOF)
goto done; goto done;

View File

@ -16,6 +16,7 @@
#include "file_wrappers.h" #include "file_wrappers.h"
#include "vwr.h" #include "vwr.h"
#include <wsutil/ws_assert.h>
/* platform-specific definitions for portability */ /* platform-specific definitions for portability */
@ -3362,7 +3363,7 @@ vwr_process_rec_data(FILE_T fh, int rec_size,
break; break;
default: default:
g_free(rec); g_free(rec);
g_assert_not_reached(); ws_assert_not_reached();
return ret; return ret;
} }

View File

@ -19,6 +19,7 @@
#include "file_wrappers.h" #include "file_wrappers.h"
#include <wsutil/file_util.h> #include <wsutil/file_util.h>
#include <wsutil/buffer.h> #include <wsutil/buffer.h>
#include <wsutil/ws_assert.h>
#ifdef HAVE_PLUGINS #ifdef HAVE_PLUGINS
#include <wsutil/plugins.h> #include <wsutil/plugins.h>
#endif #endif
@ -209,9 +210,9 @@ wtap_add_generated_idb(wtap *wth)
wtapng_if_descr_mandatory_t *if_descr_mand; wtapng_if_descr_mandatory_t *if_descr_mand;
int snaplen; int snaplen;
g_assert(wth->file_encap != WTAP_ENCAP_UNKNOWN && ws_assert(wth->file_encap != WTAP_ENCAP_UNKNOWN &&
wth->file_encap != WTAP_ENCAP_PER_PACKET); wth->file_encap != WTAP_ENCAP_PER_PACKET);
g_assert(wth->file_tsprec != WTAP_TSPREC_UNKNOWN && ws_assert(wth->file_tsprec != WTAP_TSPREC_UNKNOWN &&
wth->file_tsprec != WTAP_TSPREC_PER_PACKET); wth->file_tsprec != WTAP_TSPREC_PER_PACKET);
idb = wtap_block_create(WTAP_BLOCK_IF_ID_AND_INFO); idb = wtap_block_create(WTAP_BLOCK_IF_ID_AND_INFO);
@ -257,7 +258,7 @@ wtap_add_generated_idb(wtap *wth)
/* /*
* Don't do this. * Don't do this.
*/ */
g_assert_not_reached(); ws_assert_not_reached();
break; break;
} }
snaplen = wth->snapshot_length; snaplen = wth->snapshot_length;
@ -316,7 +317,7 @@ wtap_get_debug_if_descr(const wtap_block_t if_descr,
guint8 tmp8; guint8 tmp8;
if_filter_opt_t if_filter; if_filter_opt_t if_filter;
g_assert(if_descr); ws_assert(if_descr);
if_descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(if_descr); if_descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(if_descr);
if (wtap_block_get_string_option_value(if_descr, OPT_IDB_NAME, &tmp_content) == WTAP_OPTTYPE_SUCCESS) { if (wtap_block_get_string_option_value(if_descr, OPT_IDB_NAME, &tmp_content) == WTAP_OPTTYPE_SUCCESS) {
@ -1557,7 +1558,7 @@ wtap_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err,
* but the read routine didn't set this packet's * but the read routine didn't set this packet's
* encapsulation type. * encapsulation type.
*/ */
g_assert(rec->rec_header.packet_header.pkt_encap != WTAP_ENCAP_PER_PACKET); ws_assert(rec->rec_header.packet_header.pkt_encap != WTAP_ENCAP_PER_PACKET);
} }
return TRUE; /* success */ return TRUE; /* success */
@ -1702,7 +1703,7 @@ wtap_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf,
* but the read routine didn't set this packet's * but the read routine didn't set this packet's
* encapsulation type. * encapsulation type.
*/ */
g_assert(rec->rec_header.packet_header.pkt_encap != WTAP_ENCAP_PER_PACKET); ws_assert(rec->rec_header.packet_header.pkt_encap != WTAP_ENCAP_PER_PACKET);
} }
return TRUE; return TRUE;

View File

@ -15,6 +15,7 @@
#include "wtap_opttypes.h" #include "wtap_opttypes.h"
#include "wtap-int.h" #include "wtap-int.h"
#include "pcapng_module.h" #include "pcapng_module.h"
#include <wsutil/ws_assert.h>
#include <wsutil/glib-compat.h> #include <wsutil/glib-compat.h>
@ -120,15 +121,15 @@ static void wtap_opttype_block_register(wtap_blocktype_t *blocktype)
block_type = blocktype->block_type; block_type = blocktype->block_type;
/* Check input */ /* Check input */
g_assert(block_type < MAX_WTAP_BLOCK_TYPE_VALUE); ws_assert(block_type < MAX_WTAP_BLOCK_TYPE_VALUE);
/* Don't re-register. */ /* Don't re-register. */
g_assert(blocktype_list[block_type] == NULL); ws_assert(blocktype_list[block_type] == NULL);
/* Sanity check */ /* Sanity check */
g_assert(blocktype->name); ws_assert(blocktype->name);
g_assert(blocktype->description); ws_assert(blocktype->description);
g_assert(blocktype->create); ws_assert(blocktype->create);
/* /*
* Initialize the set of supported options. * Initialize the set of supported options.

View File

@ -11,6 +11,7 @@
#include <string.h> #include <string.h>
#include "buffer.h" #include "buffer.h"
#include <wsutil/ws_assert.h>
#define SMALL_BUFFER_SIZE (2 * 1024) /* Everyone still uses 1500 byte frames, right? */ #define SMALL_BUFFER_SIZE (2 * 1024) /* Everyone still uses 1500 byte frames, right? */
static GPtrArray *small_buffers = NULL; /* Guaranteed to be at least SMALL_BUFFER_SIZE */ static GPtrArray *small_buffers = NULL; /* Guaranteed to be at least SMALL_BUFFER_SIZE */
@ -20,13 +21,13 @@ static GPtrArray *small_buffers = NULL; /* Guaranteed to be at least SMALL_BUFFE
void void
ws_buffer_init(Buffer* buffer, gsize space) ws_buffer_init(Buffer* buffer, gsize space)
{ {
g_assert(buffer); ws_assert(buffer);
if (G_UNLIKELY(!small_buffers)) small_buffers = g_ptr_array_sized_new(1024); if (G_UNLIKELY(!small_buffers)) small_buffers = g_ptr_array_sized_new(1024);
if (space <= SMALL_BUFFER_SIZE) { if (space <= SMALL_BUFFER_SIZE) {
if (small_buffers->len > 0) { if (small_buffers->len > 0) {
buffer->data = (guint8*) g_ptr_array_remove_index(small_buffers, small_buffers->len - 1); buffer->data = (guint8*) g_ptr_array_remove_index(small_buffers, small_buffers->len - 1);
g_assert(buffer->data); ws_assert(buffer->data);
} else { } else {
buffer->data = (guint8*)g_malloc(SMALL_BUFFER_SIZE); buffer->data = (guint8*)g_malloc(SMALL_BUFFER_SIZE);
} }
@ -43,9 +44,9 @@ ws_buffer_init(Buffer* buffer, gsize space)
void void
ws_buffer_free(Buffer* buffer) ws_buffer_free(Buffer* buffer)
{ {
g_assert(buffer); ws_assert(buffer);
if (buffer->allocated == SMALL_BUFFER_SIZE) { if (buffer->allocated == SMALL_BUFFER_SIZE) {
g_assert(buffer->data); ws_assert(buffer->data);
g_ptr_array_add(small_buffers, buffer->data); g_ptr_array_add(small_buffers, buffer->data);
} else { } else {
g_free(buffer->data); g_free(buffer->data);
@ -61,7 +62,7 @@ ws_buffer_free(Buffer* buffer)
void void
ws_buffer_assure_space(Buffer* buffer, gsize space) ws_buffer_assure_space(Buffer* buffer, gsize space)
{ {
g_assert(buffer); ws_assert(buffer);
gsize available_at_end = buffer->allocated - buffer->first_free; gsize available_at_end = buffer->allocated - buffer->first_free;
gsize space_used; gsize space_used;
gboolean space_at_beginning; gboolean space_at_beginning;
@ -100,7 +101,7 @@ ws_buffer_assure_space(Buffer* buffer, gsize space)
void void
ws_buffer_append(Buffer* buffer, guint8 *from, gsize bytes) ws_buffer_append(Buffer* buffer, guint8 *from, gsize bytes)
{ {
g_assert(buffer); ws_assert(buffer);
ws_buffer_assure_space(buffer, bytes); ws_buffer_assure_space(buffer, bytes);
memcpy(buffer->data + buffer->first_free, from, bytes); memcpy(buffer->data + buffer->first_free, from, bytes);
buffer->first_free += bytes; buffer->first_free += bytes;
@ -109,7 +110,7 @@ ws_buffer_append(Buffer* buffer, guint8 *from, gsize bytes)
void void
ws_buffer_remove_start(Buffer* buffer, gsize bytes) ws_buffer_remove_start(Buffer* buffer, gsize bytes)
{ {
g_assert(buffer); ws_assert(buffer);
if (buffer->start + bytes > buffer->first_free) { if (buffer->start + bytes > buffer->first_free) {
g_error("ws_buffer_remove_start trying to remove %" G_GINT64_MODIFIER "u bytes. s=%" G_GINT64_MODIFIER "u ff=%" G_GINT64_MODIFIER "u!\n", g_error("ws_buffer_remove_start trying to remove %" G_GINT64_MODIFIER "u bytes. s=%" G_GINT64_MODIFIER "u ff=%" G_GINT64_MODIFIER "u!\n",
(guint64)bytes, (guint64)buffer->start, (guint64)bytes, (guint64)buffer->start,
@ -129,7 +130,7 @@ ws_buffer_remove_start(Buffer* buffer, gsize bytes)
void void
ws_buffer_clean(Buffer* buffer) ws_buffer_clean(Buffer* buffer)
{ {
g_assert(buffer); ws_assert(buffer);
ws_buffer_remove_start(buffer, ws_buffer_length(buffer)); ws_buffer_remove_start(buffer, ws_buffer_length(buffer));
} }
#endif #endif
@ -138,7 +139,7 @@ ws_buffer_clean(Buffer* buffer)
void void
ws_buffer_increase_length(Buffer* buffer, gsize bytes) ws_buffer_increase_length(Buffer* buffer, gsize bytes)
{ {
g_assert(buffer); ws_assert(buffer);
buffer->first_free += bytes; buffer->first_free += bytes;
} }
#endif #endif
@ -147,7 +148,7 @@ ws_buffer_increase_length(Buffer* buffer, gsize bytes)
gsize gsize
ws_buffer_length(Buffer* buffer) ws_buffer_length(Buffer* buffer)
{ {
g_assert(buffer); ws_assert(buffer);
return buffer->first_free - buffer->start; return buffer->first_free - buffer->start;
} }
#endif #endif
@ -156,7 +157,7 @@ ws_buffer_length(Buffer* buffer)
guint8 * guint8 *
ws_buffer_start_ptr(Buffer* buffer) ws_buffer_start_ptr(Buffer* buffer)
{ {
g_assert(buffer); ws_assert(buffer);
return buffer->data + buffer->start; return buffer->data + buffer->start;
} }
#endif #endif
@ -165,7 +166,7 @@ ws_buffer_start_ptr(Buffer* buffer)
guint8 * guint8 *
ws_buffer_end_ptr(Buffer* buffer) ws_buffer_end_ptr(Buffer* buffer)
{ {
g_assert(buffer); ws_assert(buffer);
return buffer->data + buffer->first_free; return buffer->data + buffer->first_free;
} }
#endif #endif
@ -174,7 +175,7 @@ ws_buffer_end_ptr(Buffer* buffer)
void void
ws_buffer_append_buffer(Buffer* buffer, Buffer* src_buffer) ws_buffer_append_buffer(Buffer* buffer, Buffer* src_buffer)
{ {
g_assert(buffer); ws_assert(buffer);
ws_buffer_append(buffer, ws_buffer_start_ptr(src_buffer), ws_buffer_length(src_buffer)); ws_buffer_append(buffer, ws_buffer_start_ptr(src_buffer), ws_buffer_length(src_buffer));
} }
#endif #endif

View File

@ -44,6 +44,7 @@
#include <wsutil/privileges.h> #include <wsutil/privileges.h>
#include <wsutil/file_util.h> #include <wsutil/file_util.h>
#include <wsutil/utf8_entities.h> #include <wsutil/utf8_entities.h>
#include <wsutil/ws_assert.h>
#include <wiretap/wtap.h> /* for WTAP_ERR_SHORT_WRITE */ #include <wiretap/wtap.h> /* for WTAP_ERR_SHORT_WRITE */
@ -104,7 +105,7 @@ get_basename(const char *path)
{ {
const char *filename; const char *filename;
g_assert(path != NULL); ws_assert(path != NULL);
filename = find_last_pathname_separator(path); filename = find_last_pathname_separator(path);
if (filename == NULL) { if (filename == NULL) {
/* /*
@ -131,7 +132,7 @@ get_dirname(char *path)
{ {
char *separator; char *separator;
g_assert(path != NULL); ws_assert(path != NULL);
separator = find_last_pathname_separator(path); separator = find_last_pathname_separator(path);
if (separator == NULL) { if (separator == NULL) {
/* /*

View File

@ -34,6 +34,8 @@
#define _NTOP_SRC_CAST_ #define _NTOP_SRC_CAST_
#endif #endif
#include <wsutil/ws_assert.h>
/* /*
* We assume and require an inet_pton/inet_ntop that supports AF_INET * We assume and require an inet_pton/inet_ntop that supports AF_INET
* and AF_INET6. * and AF_INET6.
@ -54,7 +56,7 @@ _inet_pton(int af, const gchar *src, gpointer dst)
g_critical("ws_inet_pton6: EAFNOSUPPORT"); g_critical("ws_inet_pton6: EAFNOSUPPORT");
} }
else { else {
g_assert_not_reached(); ws_assert_not_reached();
} }
errno = EAFNOSUPPORT; errno = EAFNOSUPPORT;
} }

View File

@ -26,6 +26,7 @@
#include <wsutil/report_message.h> #include <wsutil/report_message.h>
#include <wsutil/plugins.h> #include <wsutil/plugins.h>
#include <wsutil/ws_assert.h>
typedef struct _plugin { typedef struct _plugin {
GModule *handle; /* handle returned by g_module_open */ GModule *handle; /* handle returned by g_module_open */
@ -60,7 +61,7 @@ type_to_dir(plugin_type_e type)
g_error("Unknown plugin type: %u. Aborting.", (unsigned) type); g_error("Unknown plugin type: %u. Aborting.", (unsigned) type);
break; break;
} }
g_assert_not_reached(); ws_assert_not_reached();
} }
static inline const char * static inline const char *
@ -77,7 +78,7 @@ type_to_name(plugin_type_e type)
g_error("Unknown plugin type: %u. Aborting.", (unsigned) type); g_error("Unknown plugin type: %u. Aborting.", (unsigned) type);
break; break;
} }
g_assert_not_reached(); ws_assert_not_reached();
} }
static void static void

View File

@ -17,6 +17,7 @@
#include <glib.h> #include <glib.h>
#include "privileges.h" #include "privileges.h"
#include <wsutil/ws_assert.h>
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
@ -148,7 +149,7 @@ init_process_policies(void)
gboolean gboolean
started_with_special_privs(void) started_with_special_privs(void)
{ {
g_assert(init_process_policies_called); ws_assert(init_process_policies_called);
#ifdef HAVE_ISSETUGID #ifdef HAVE_ISSETUGID
return issetugid(); return issetugid();
#else #else

View File

@ -12,13 +12,14 @@
#define __WSUTIL_SIGN_EXT_H__ #define __WSUTIL_SIGN_EXT_H__
#include <glib.h> #include <glib.h>
#include <wsutil/ws_assert.h>
/* sign extension routines */ /* sign extension routines */
static inline guint32 static inline guint32
ws_sign_ext32(guint32 val, int no_of_bits) ws_sign_ext32(guint32 val, int no_of_bits)
{ {
g_assert (no_of_bits >= 0 && no_of_bits <= 32); ws_assert (no_of_bits >= 0 && no_of_bits <= 32);
if ((no_of_bits == 0) || (no_of_bits == 32)) if ((no_of_bits == 0) || (no_of_bits == 32))
return val; return val;
@ -38,7 +39,7 @@ ws_sign_ext32(guint32 val, int no_of_bits)
static inline guint64 static inline guint64
ws_sign_ext64(guint64 val, int no_of_bits) ws_sign_ext64(guint64 val, int no_of_bits)
{ {
g_assert (no_of_bits >= 0 && no_of_bits <= 64); ws_assert (no_of_bits >= 0 && no_of_bits <= 64);
if ((no_of_bits == 0) || (no_of_bits == 64)) if ((no_of_bits == 0) || (no_of_bits == 64))
return val; return val;

View File

@ -19,6 +19,7 @@
#include <wsutil/socket.h> #include <wsutil/socket.h>
#include <wsutil/inet_addr.h> #include <wsutil/inet_addr.h>
#include <wsutil/ws_assert.h>
#ifdef _WIN32 #ifdef _WIN32
#include <wsutil/win32-utils.h> #include <wsutil/win32-utils.h>
@ -143,7 +144,7 @@ ws_socket_ptoa(struct sockaddr_storage *dst, const gchar *src,
ret = 0; ret = 0;
} }
else { else {
g_assert_not_reached(); ws_assert_not_reached();
} }
out: out:

View File

@ -11,6 +11,7 @@
#include <config.h> #include <config.h>
#include "str_util.h" #include "str_util.h"
#include <wsutil/ws_assert.h>
int int
ws_xton(char ch) ws_xton(char ch)
@ -205,7 +206,7 @@ format_size(gint64 size, format_size_flags_e flags)
g_string_append(human_str, "packets/s"); g_string_append(human_str, "packets/s");
break; break;
default: default:
g_assert_not_reached(); ws_assert_not_reached();
} }
ret_val = g_string_free(human_str, FALSE); ret_val = g_string_free(human_str, FALSE);

View File

@ -14,13 +14,14 @@
#include "strtoi.h" #include "strtoi.h"
#include <errno.h> #include <errno.h>
#include <wsutil/ws_assert.h>
gboolean ws_strtoi64(const gchar* str, const gchar** endptr, gint64* cint) gboolean ws_strtoi64(const gchar* str, const gchar** endptr, gint64* cint)
{ {
gchar* end; gchar* end;
gint64 val; gint64 val;
g_assert(cint); ws_assert(cint);
if (!str) { if (!str) {
errno = EINVAL; errno = EINVAL;
@ -151,7 +152,7 @@ gboolean ws_basestrtou64(const gchar* str, const gchar** endptr, guint64* cint,
gchar* end; gchar* end;
guint64 val; guint64 val;
g_assert(cint); ws_assert(cint);
if (!str) { if (!str) {
errno = EINVAL; errno = EINVAL;