Check assert.h header and use it conditionally.

assert(3) should be replaced with g_assert().

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2012-01-04 14:36:53 +03:00 committed by Slava Zanko
parent b3d1eafb5e
commit f7f37f674e
13 changed files with 78 additions and 4 deletions

View File

@ -149,6 +149,7 @@ AC_CHECK_HEADERS([unistd.h string.h memory.h limits.h malloc.h \
AC_HEADER_TIME AC_HEADER_TIME
AC_HEADER_DIRENT AC_HEADER_DIRENT
AC_HEADER_ASSERT
dnl Missing structure components dnl Missing structure components
AC_CHECK_MEMBERS([struct stat.st_blksize, struct stat.st_rdev]) AC_CHECK_MEMBERS([struct stat.st_blksize, struct stat.st_rdev])

View File

@ -137,8 +137,10 @@
#else #else
#define NDEBUG #define NDEBUG
#endif #endif
#ifdef HAVE_ASSERT_H
#include <assert.h> #include <assert.h>
#endif #endif
#endif
#define MC_ERROR g_quark_from_static_string (PACKAGE) #define MC_ERROR g_quark_from_static_string (PACKAGE)

View File

@ -5,7 +5,9 @@
#include <sys/types.h> #include <sys/types.h>
#include <string.h> #include <string.h>
#ifdef HAVE_ASSERT_H
#include <assert.h> /* assert() */ #include <assert.h> /* assert() */
#endif
/* Header file for strutil.c, strutilascii.c, strutil8bit.c, strutilutf8.c. /* Header file for strutil.c, strutilascii.c, strutil8bit.c, strutilutf8.c.
* There are two sort of functions: * There are two sort of functions:
@ -558,7 +560,9 @@ str_move (char *dest, const char *src)
{ {
size_t n; size_t n;
#ifdef HAVE_ASSERT_H
assert (dest <= src); assert (dest <= src);
#endif
n = strlen (src) + 1; /* + '\0' */ n = strlen (src) + 1; /* + '\0' */

View File

@ -34,7 +34,9 @@
#include <config.h> #include <config.h>
#ifdef HAVE_ASSERT_H
#include <assert.h> #include <assert.h>
#endif
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
@ -356,7 +358,9 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath)
vfs_path_t *tmp_vpath; vfs_path_t *tmp_vpath;
gboolean ok; gboolean ok;
#ifdef HAVE_ASSERT_H
assert (option_backup_ext != NULL); assert (option_backup_ext != NULL);
#endif
tmp_vpath = vfs_path_append_new (real_filename_vpath, option_backup_ext, (char *) NULL); tmp_vpath = vfs_path_append_new (real_filename_vpath, option_backup_ext, (char *) NULL);
ok = (mc_rename (real_filename_vpath, tmp_vpath) != -1); ok = (mc_rename (real_filename_vpath, tmp_vpath) != -1);
vfs_path_free (tmp_vpath); vfs_path_free (tmp_vpath);
@ -1413,7 +1417,9 @@ menu_save_mode_cmd (void)
size_t maxlen = 0; size_t maxlen = 0;
size_t w0, w1, b_len, w3; size_t w0, w1, b_len, w3;
#ifdef HAVE_ASSERT_H
assert (option_backup_ext != NULL); assert (option_backup_ext != NULL);
#endif
/* OK/Cancel buttons */ /* OK/Cancel buttons */
w0 = str_term_width1 (_(widgets[0].u.button.text)) + 3; w0 = str_term_width1 (_(widgets[0].u.button.text)) + 3;

View File

@ -30,7 +30,6 @@
#include <config.h> #include <config.h>
#include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <sys/types.h> #include <sys/types.h>

View File

@ -147,7 +147,9 @@ mcview_ccache_find (mcview_t * view, const coord_cache_entry_t * coord, cmp_func
size_t base = 0; size_t base = 0;
size_t limit = view->coord_cache->size; size_t limit = view->coord_cache->size;
#ifdef HAVE_ASSERT_H
assert (limit != 0); assert (limit != 0);
#endif
while (limit > 1) while (limit > 1)
{ {
@ -214,7 +216,9 @@ mcview_ccache_dump (mcview_t * view)
guint i; guint i;
const coord_cache_t *cache = view->coord_cache; const coord_cache_t *cache = view->coord_cache;
#ifdef HAVE_ASSERT_H
assert (cache != NULL); assert (cache != NULL);
#endif
filesize = mcview_get_filesize (view); filesize = mcview_get_filesize (view);

View File

@ -80,7 +80,9 @@
static void static void
mcview_set_datasource_stdio_pipe (mcview_t * view, FILE * fp) mcview_set_datasource_stdio_pipe (mcview_t * view, FILE * fp)
{ {
#ifdef HAVE_ASSERT_H
assert (fp != NULL); assert (fp != NULL);
#endif
view->datasource = DS_STDIO_PIPE; view->datasource = DS_STDIO_PIPE;
view->ds_stdio_pipe = fp; view->ds_stdio_pipe = fp;
@ -112,7 +114,9 @@ mcview_get_filesize (mcview_t * view)
case DS_STRING: case DS_STRING:
return view->ds_string_len; return view->ds_string_len;
default: default:
#ifdef HAVE_ASSERT_H
assert (!"Unknown datasource type"); assert (!"Unknown datasource type");
#endif
return 0; return 0;
} }
} }
@ -135,7 +139,9 @@ mcview_update_filesize (mcview_t * view)
char * char *
mcview_get_ptr_file (mcview_t * view, off_t byte_index) mcview_get_ptr_file (mcview_t * view, off_t byte_index)
{ {
#ifdef HAVE_ASSERT_H
assert (view->datasource == DS_FILE); assert (view->datasource == DS_FILE);
#endif
mcview_file_load_data (view, byte_index); mcview_file_load_data (view, byte_index);
if (mcview_already_loaded (view->ds_file_offset, byte_index, view->ds_file_datalen)) if (mcview_already_loaded (view->ds_file_offset, byte_index, view->ds_file_datalen))
@ -148,7 +154,9 @@ mcview_get_ptr_file (mcview_t * view, off_t byte_index)
char * char *
mcview_get_ptr_string (mcview_t * view, off_t byte_index) mcview_get_ptr_string (mcview_t * view, off_t byte_index)
{ {
#ifdef HAVE_ASSERT_H
assert (view->datasource == DS_STRING); assert (view->datasource == DS_STRING);
#endif
if (byte_index < (off_t) view->ds_string_len) if (byte_index < (off_t) view->ds_string_len)
return (char *) (view->ds_string_data + byte_index); return (char *) (view->ds_string_data + byte_index);
return NULL; return NULL;
@ -232,7 +240,9 @@ mcview_get_utf (mcview_t * view, off_t byte_index, int *char_width, gboolean * r
gboolean gboolean
mcview_get_byte_string (mcview_t * view, off_t byte_index, int *retval) mcview_get_byte_string (mcview_t * view, off_t byte_index, int *retval)
{ {
#ifdef HAVE_ASSERT_H
assert (view->datasource == DS_STRING); assert (view->datasource == DS_STRING);
#endif
if (byte_index < (off_t) view->ds_string_len) if (byte_index < (off_t) view->ds_string_len)
{ {
if (retval) if (retval)
@ -249,10 +259,14 @@ mcview_get_byte_string (mcview_t * view, off_t byte_index, int *retval)
gboolean gboolean
mcview_get_byte_none (mcview_t * view, off_t byte_index, int *retval) mcview_get_byte_none (mcview_t * view, off_t byte_index, int *retval)
{ {
assert (view->datasource == DS_NONE);
(void) &view; (void) &view;
(void) byte_index; (void) byte_index;
if (retval)
#ifdef HAVE_ASSERT_H
assert (view->datasource == DS_NONE);
#endif
if (retval != NULL)
*retval = -1; *retval = -1;
return FALSE; return FALSE;
} }
@ -263,8 +277,13 @@ void
mcview_set_byte (mcview_t * view, off_t offset, byte b) mcview_set_byte (mcview_t * view, off_t offset, byte b)
{ {
(void) &b; (void) &b;
#ifndef HAVE_ASSERT_H
(void) offset;
#else
assert (offset < mcview_get_filesize (view)); assert (offset < mcview_get_filesize (view));
assert (view->datasource == DS_FILE); assert (view->datasource == DS_FILE);
#endif
view->ds_file_datalen = 0; /* just force reloading */ view->ds_file_datalen = 0; /* just force reloading */
} }
@ -278,7 +297,9 @@ mcview_file_load_data (mcview_t * view, off_t byte_index)
ssize_t res; ssize_t res;
size_t bytes_read; size_t bytes_read;
#ifdef HAVE_ASSERT_H
assert (view->datasource == DS_FILE); assert (view->datasource == DS_FILE);
#endif
if (mcview_already_loaded (view->ds_file_offset, byte_index, view->ds_file_datalen)) if (mcview_already_loaded (view->ds_file_offset, byte_index, view->ds_file_datalen))
return; return;
@ -356,7 +377,10 @@ mcview_close_datasource (mcview_t * view)
view->ds_string_data = NULL; view->ds_string_data = NULL;
break; break;
default: default:
assert (!"Unknown datasource type"); #ifdef HAVE_ASSERT_H
assert (!"Unknown datasource type")
#endif
;
} }
view->datasource = DS_NONE; view->datasource = DS_NONE;
} }
@ -426,7 +450,9 @@ mcview_load_command_output (mcview_t * view, const char *command)
void void
mcview_set_datasource_vfs_pipe (mcview_t * view, int fd) mcview_set_datasource_vfs_pipe (mcview_t * view, int fd)
{ {
#ifdef HAVE_ASSERT_H
assert (fd != -1); assert (fd != -1);
#endif
view->datasource = DS_VFS_PIPE; view->datasource = DS_VFS_PIPE;
view->ds_vfs_pipe = fd; view->ds_vfs_pipe = fd;

View File

@ -313,7 +313,9 @@ mcview_update_bytes_per_line (mcview_t * view)
bytes = 4; bytes = 4;
else else
bytes = 4 * ((cols - 8) / ((cols < 80) ? 17 : 18)); bytes = 4 * ((cols - 8) / ((cols < 80) ? 17 : 18));
#ifdef HAVE_ASSERT_H
assert (bytes != 0); assert (bytes != 0);
#endif
view->bytes_per_line = bytes; view->bytes_per_line = bytes;
view->dirty = mcview_max_dirt_limit + 1; /* To force refresh */ view->dirty = mcview_max_dirt_limit + 1; /* To force refresh */
@ -331,7 +333,9 @@ mcview_display_toggle_ruler (mcview_t * view)
RULER_NONE RULER_NONE
}; };
#ifdef HAVE_ASSERT_H
assert ((size_t) ruler < 3); assert ((size_t) ruler < 3);
#endif
ruler = next[(size_t) ruler]; ruler = next[(size_t) ruler];
mcview_compute_areas (view); mcview_compute_areas (view);
view->dirty++; view->dirty++;

View File

@ -76,7 +76,9 @@ mcview_growbuf_init (mcview_t * view)
void void
mcview_growbuf_free (mcview_t * view) mcview_growbuf_free (mcview_t * view)
{ {
#ifdef HAVE_ASSERT_H
assert (view->growbuf_in_use); assert (view->growbuf_in_use);
#endif
g_ptr_array_foreach (view->growbuf_blockptr, (GFunc) g_free, NULL); g_ptr_array_foreach (view->growbuf_blockptr, (GFunc) g_free, NULL);
@ -91,7 +93,9 @@ mcview_growbuf_free (mcview_t * view)
off_t off_t
mcview_growbuf_filesize (mcview_t * view) mcview_growbuf_filesize (mcview_t * view)
{ {
#ifdef HAVE_ASSERT_H
assert (view->growbuf_in_use); assert (view->growbuf_in_use);
#endif
if (view->growbuf_blockptr->len == 0) if (view->growbuf_blockptr->len == 0)
return 0; return 0;
@ -113,7 +117,9 @@ mcview_growbuf_read_until (mcview_t * view, off_t ofs)
size_t bytesfree; size_t bytesfree;
gboolean short_read; gboolean short_read;
#ifdef HAVE_ASSERT_H
assert (view->growbuf_in_use); assert (view->growbuf_in_use);
#endif
if (view->growbuf_finished) if (view->growbuf_finished)
return; return;
@ -151,7 +157,9 @@ mcview_growbuf_read_until (mcview_t * view, off_t ofs)
} }
else else
{ {
#ifdef HAVE_ASSERT_H
assert (view->datasource == DS_VFS_PIPE); assert (view->datasource == DS_VFS_PIPE);
#endif
do do
{ {
nread = mc_read (view->ds_vfs_pipe, p, bytesfree); nread = mc_read (view->ds_vfs_pipe, p, bytesfree);
@ -184,7 +192,9 @@ mcview_get_byte_growing_buffer (mcview_t * view, off_t byte_index, int *retval)
pageno = byte_index / VIEW_PAGE_SIZE; pageno = byte_index / VIEW_PAGE_SIZE;
pageindex = byte_index % VIEW_PAGE_SIZE; pageindex = byte_index % VIEW_PAGE_SIZE;
#ifdef HAVE_ASSERT_H
assert (view->growbuf_in_use); assert (view->growbuf_in_use);
#endif
if (pageno < 0) if (pageno < 0)
return FALSE; return FALSE;
@ -216,7 +226,9 @@ mcview_get_ptr_growing_buffer (mcview_t * view, off_t byte_index)
off_t pageno = byte_index / VIEW_PAGE_SIZE; off_t pageno = byte_index / VIEW_PAGE_SIZE;
off_t pageindex = byte_index % VIEW_PAGE_SIZE; off_t pageindex = byte_index % VIEW_PAGE_SIZE;
#ifdef HAVE_ASSERT_H
assert (view->growbuf_in_use); assert (view->growbuf_in_use);
#endif
if (pageno < 0) if (pageno < 0)
return NULL; return NULL;

View File

@ -349,7 +349,9 @@ mcview_hexedit_save_changes (mcview_t * view)
char *text; char *text;
struct hexedit_change_node *curr, *next; struct hexedit_change_node *curr, *next;
#ifdef HAVE_ASSERT_H
assert (view->filename_vpath != NULL); assert (view->filename_vpath != NULL);
#endif
fp = mc_open (view->filename_vpath, O_WRONLY); fp = mc_open (view->filename_vpath, O_WRONLY);
if (fp != -1) if (fp != -1)

View File

@ -1,7 +1,9 @@
#ifndef MC__VIEWER_INLINES_H #ifndef MC__VIEWER_INLINES_H
#define MC__VIEWER_INLINES_H #define MC__VIEWER_INLINES_H
#ifdef HAVE_ASSERT_H
#include <assert.h> #include <assert.h>
#endif
/*** typedefs(not structures) and defined constants **********************************************/ /*** typedefs(not structures) and defined constants **********************************************/
@ -26,7 +28,9 @@ mcview_offset_doz (off_t a, off_t b)
static inline off_t static inline off_t
mcview_offset_rounddown (off_t a, off_t b) mcview_offset_rounddown (off_t a, off_t b)
{ {
#ifdef HAVE_ASSERT_H
assert (b != 0); assert (b != 0);
#endif
return a - a % b; return a - a % b;
} }
@ -80,7 +84,9 @@ mcview_already_loaded (off_t offset, off_t idx, size_t size)
static inline gboolean static inline gboolean
mcview_get_byte_file (mcview_t * view, off_t byte_index, int *retval) mcview_get_byte_file (mcview_t * view, off_t byte_index, int *retval)
{ {
#ifdef HAVE_ASSERT_H
assert (view->datasource == DS_FILE); assert (view->datasource == DS_FILE);
#endif
mcview_file_load_data (view, byte_index); mcview_file_load_data (view, byte_index);
if (mcview_already_loaded (view->ds_file_offset, byte_index, view->ds_file_datalen)) if (mcview_already_loaded (view->ds_file_offset, byte_index, view->ds_file_datalen))
@ -111,7 +117,9 @@ mcview_get_byte (mcview_t * view, off_t offset, int *retval)
case DS_NONE: case DS_NONE:
return mcview_get_byte_none (view, offset, retval); return mcview_get_byte_none (view, offset, retval);
} }
#ifdef HAVE_ASSERT_H
assert (!"Unknown datasource type"); assert (!"Unknown datasource type");
#endif
return -1; return -1;
} }

View File

@ -287,7 +287,9 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l
gboolean retval = FALSE; gboolean retval = FALSE;
vfs_path_t *vpath = NULL; vfs_path_t *vpath = NULL;
#ifdef HAVE_ASSERT_H
assert (view->bytes_per_line != 0); assert (view->bytes_per_line != 0);
#endif
view->filename_vpath = vfs_path_from_str (file); view->filename_vpath = vfs_path_from_str (file);

View File

@ -224,7 +224,9 @@ mcview_move_left (mcview_t * view, off_t columns)
if (view->hex_mode) if (view->hex_mode)
{ {
off_t old_cursor = view->hex_cursor; off_t old_cursor = view->hex_cursor;
#ifdef HAVE_ASSERT_H
assert (columns == 1); assert (columns == 1);
#endif
if (view->hexview_in_text || !view->hexedit_lownibble) if (view->hexview_in_text || !view->hexedit_lownibble)
{ {
if (view->hex_cursor > 0) if (view->hex_cursor > 0)
@ -254,7 +256,9 @@ mcview_move_right (mcview_t * view, off_t columns)
off_t last_byte; off_t last_byte;
off_t old_cursor = view->hex_cursor; off_t old_cursor = view->hex_cursor;
last_byte = mcview_offset_doz (mcview_get_filesize (view), 1); last_byte = mcview_offset_doz (mcview_get_filesize (view), 1);
#ifdef HAVE_ASSERT_H
assert (columns == 1); assert (columns == 1);
#endif
if (view->hexview_in_text || view->hexedit_lownibble) if (view->hexview_in_text || view->hexedit_lownibble)
{ {
if (view->hex_cursor < last_byte) if (view->hex_cursor < last_byte)