mirror of
git://git.sv.gnu.org/nano.git
synced 2025-01-07 01:52:19 +03:00
tweaks: delete a bunch of unneeded asserts
Nano would crash straight afterward if any of these asserts would fail, so they don't add anything. A few others are simply superfluous.
This commit is contained in:
parent
c5f49167ea
commit
0562d27b9c
36
src/chars.c
36
src/chars.c
@ -167,8 +167,6 @@ bool is_cntrl_char(int c)
|
|||||||
* their high bits set. */
|
* their high bits set. */
|
||||||
bool is_cntrl_mbchar(const char *c)
|
bool is_cntrl_mbchar(const char *c)
|
||||||
{
|
{
|
||||||
assert(c != NULL);
|
|
||||||
|
|
||||||
#ifdef ENABLE_UTF8
|
#ifdef ENABLE_UTF8
|
||||||
if (use_utf8) {
|
if (use_utf8) {
|
||||||
return ((c[0] & 0xE0) == 0 || c[0] == 127 ||
|
return ((c[0] & 0xE0) == 0 || c[0] == 127 ||
|
||||||
@ -203,8 +201,6 @@ bool is_punct_mbchar(const char *c)
|
|||||||
* punctuation when allow_punct is TRUE), and FALSE otherwise. */
|
* punctuation when allow_punct is TRUE), and FALSE otherwise. */
|
||||||
bool is_word_mbchar(const char *c, bool allow_punct)
|
bool is_word_mbchar(const char *c, bool allow_punct)
|
||||||
{
|
{
|
||||||
assert(c != NULL);
|
|
||||||
|
|
||||||
if (*c == '\0')
|
if (*c == '\0')
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
@ -229,8 +225,6 @@ bool is_word_mbchar(const char *c, bool allow_punct)
|
|||||||
/* Return the visible representation of control character c. */
|
/* Return the visible representation of control character c. */
|
||||||
char control_rep(const signed char c)
|
char control_rep(const signed char c)
|
||||||
{
|
{
|
||||||
assert(is_cntrl_char(c));
|
|
||||||
|
|
||||||
/* An embedded newline is an encoded null. */
|
/* An embedded newline is an encoded null. */
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
return '@';
|
return '@';
|
||||||
@ -247,8 +241,6 @@ char control_rep(const signed char c)
|
|||||||
/* Return the visible representation of multibyte control character c. */
|
/* Return the visible representation of multibyte control character c. */
|
||||||
char control_mbrep(const char *c)
|
char control_mbrep(const char *c)
|
||||||
{
|
{
|
||||||
assert(c != NULL);
|
|
||||||
|
|
||||||
#ifdef ENABLE_UTF8
|
#ifdef ENABLE_UTF8
|
||||||
if (use_utf8) {
|
if (use_utf8) {
|
||||||
if ((unsigned char)c[0] < 128)
|
if ((unsigned char)c[0] < 128)
|
||||||
@ -339,8 +331,6 @@ char *make_mbchar(long chr, int *chr_mb_len)
|
|||||||
{
|
{
|
||||||
char *chr_mb;
|
char *chr_mb;
|
||||||
|
|
||||||
assert(chr_mb_len != NULL);
|
|
||||||
|
|
||||||
#ifdef ENABLE_UTF8
|
#ifdef ENABLE_UTF8
|
||||||
if (use_utf8) {
|
if (use_utf8) {
|
||||||
chr_mb = charalloc(MB_CUR_MAX);
|
chr_mb = charalloc(MB_CUR_MAX);
|
||||||
@ -484,8 +474,6 @@ int nstrncasecmp(const char *s1, const char *s2, size_t n)
|
|||||||
if (s1 == s2)
|
if (s1 == s2)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
assert(s1 != NULL && s2 != NULL);
|
|
||||||
|
|
||||||
for (; *s1 != '\0' && *s2 != '\0' && n > 0; s1++, s2++, n--) {
|
for (; *s1 != '\0' && *s2 != '\0' && n > 0; s1++, s2++, n--) {
|
||||||
if (tolower(*s1) != tolower(*s2))
|
if (tolower(*s1) != tolower(*s2))
|
||||||
break;
|
break;
|
||||||
@ -502,8 +490,6 @@ int mbstrncasecmp(const char *s1, const char *s2, size_t n)
|
|||||||
if (use_utf8) {
|
if (use_utf8) {
|
||||||
wchar_t wc1, wc2;
|
wchar_t wc1, wc2;
|
||||||
|
|
||||||
assert(s1 != NULL && s2 != NULL);
|
|
||||||
|
|
||||||
while (*s1 != '\0' && *s2 != '\0' && n > 0) {
|
while (*s1 != '\0' && *s2 != '\0' && n > 0) {
|
||||||
bool bad1 = FALSE, bad2 = FALSE;
|
bool bad1 = FALSE, bad2 = FALSE;
|
||||||
|
|
||||||
@ -547,8 +533,6 @@ char *nstrcasestr(const char *haystack, const char *needle)
|
|||||||
{
|
{
|
||||||
size_t needle_len;
|
size_t needle_len;
|
||||||
|
|
||||||
assert(haystack != NULL && needle != NULL);
|
|
||||||
|
|
||||||
if (*needle == '\0')
|
if (*needle == '\0')
|
||||||
return (char *)haystack;
|
return (char *)haystack;
|
||||||
|
|
||||||
@ -572,8 +556,6 @@ char *mbstrcasestr(const char *haystack, const char *needle)
|
|||||||
if (use_utf8) {
|
if (use_utf8) {
|
||||||
size_t needle_len;
|
size_t needle_len;
|
||||||
|
|
||||||
assert(haystack != NULL && needle != NULL);
|
|
||||||
|
|
||||||
if (*needle == '\0')
|
if (*needle == '\0')
|
||||||
return (char *)haystack;
|
return (char *)haystack;
|
||||||
|
|
||||||
@ -599,8 +581,6 @@ char *revstrstr(const char *haystack, const char *needle, const char
|
|||||||
{
|
{
|
||||||
size_t rev_start_len, needle_len;
|
size_t rev_start_len, needle_len;
|
||||||
|
|
||||||
assert(haystack != NULL && needle != NULL && rev_start != NULL);
|
|
||||||
|
|
||||||
if (*needle == '\0')
|
if (*needle == '\0')
|
||||||
return (char *)rev_start;
|
return (char *)rev_start;
|
||||||
|
|
||||||
@ -627,8 +607,6 @@ char *revstrcasestr(const char *haystack, const char *needle, const char
|
|||||||
{
|
{
|
||||||
size_t rev_start_len, needle_len;
|
size_t rev_start_len, needle_len;
|
||||||
|
|
||||||
assert(haystack != NULL && needle != NULL && rev_start != NULL);
|
|
||||||
|
|
||||||
if (*needle == '\0')
|
if (*needle == '\0')
|
||||||
return (char *)rev_start;
|
return (char *)rev_start;
|
||||||
|
|
||||||
@ -657,8 +635,6 @@ char *mbrevstrcasestr(const char *haystack, const char *needle, const
|
|||||||
if (use_utf8) {
|
if (use_utf8) {
|
||||||
size_t rev_start_len, needle_len;
|
size_t rev_start_len, needle_len;
|
||||||
|
|
||||||
assert(haystack != NULL && needle != NULL && rev_start != NULL);
|
|
||||||
|
|
||||||
if (*needle == '\0')
|
if (*needle == '\0')
|
||||||
return (char *)rev_start;
|
return (char *)rev_start;
|
||||||
|
|
||||||
@ -698,8 +674,6 @@ size_t nstrnlen(const char *s, size_t maxlen)
|
|||||||
{
|
{
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
||||||
assert(s != NULL);
|
|
||||||
|
|
||||||
for (; *s != '\0' && maxlen > 0; s++, maxlen--, n++)
|
for (; *s != '\0' && maxlen > 0; s++, maxlen--, n++)
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -710,8 +684,6 @@ size_t nstrnlen(const char *s, size_t maxlen)
|
|||||||
/* This function is equivalent to strnlen() for multibyte strings. */
|
/* This function is equivalent to strnlen() for multibyte strings. */
|
||||||
size_t mbstrnlen(const char *s, size_t maxlen)
|
size_t mbstrnlen(const char *s, size_t maxlen)
|
||||||
{
|
{
|
||||||
assert(s != NULL);
|
|
||||||
|
|
||||||
#ifdef ENABLE_UTF8
|
#ifdef ENABLE_UTF8
|
||||||
if (use_utf8) {
|
if (use_utf8) {
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
@ -777,8 +749,6 @@ char *mbstrchr(const char *s, const char *c)
|
|||||||
/* This function is equivalent to strpbrk() for multibyte strings. */
|
/* This function is equivalent to strpbrk() for multibyte strings. */
|
||||||
char *mbstrpbrk(const char *s, const char *accept)
|
char *mbstrpbrk(const char *s, const char *accept)
|
||||||
{
|
{
|
||||||
assert(s != NULL && accept != NULL);
|
|
||||||
|
|
||||||
#ifdef ENABLE_UTF8
|
#ifdef ENABLE_UTF8
|
||||||
if (use_utf8) {
|
if (use_utf8) {
|
||||||
for (; *s != '\0'; s += move_mbright(s, 0)) {
|
for (; *s != '\0'; s += move_mbright(s, 0)) {
|
||||||
@ -849,8 +819,6 @@ char *mbrevstrpbrk(const char *s, const char *accept, const char
|
|||||||
* and FALSE otherwise. */
|
* and FALSE otherwise. */
|
||||||
bool has_blank_chars(const char *s)
|
bool has_blank_chars(const char *s)
|
||||||
{
|
{
|
||||||
assert(s != NULL);
|
|
||||||
|
|
||||||
for (; *s != '\0'; s++) {
|
for (; *s != '\0'; s++) {
|
||||||
if (isblank(*s))
|
if (isblank(*s))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -863,8 +831,6 @@ bool has_blank_chars(const char *s)
|
|||||||
* multibyte characters, and FALSE otherwise. */
|
* multibyte characters, and FALSE otherwise. */
|
||||||
bool has_blank_mbchars(const char *s)
|
bool has_blank_mbchars(const char *s)
|
||||||
{
|
{
|
||||||
assert(s != NULL);
|
|
||||||
|
|
||||||
#ifdef ENABLE_UTF8
|
#ifdef ENABLE_UTF8
|
||||||
if (use_utf8) {
|
if (use_utf8) {
|
||||||
bool retval = FALSE;
|
bool retval = FALSE;
|
||||||
@ -904,8 +870,6 @@ bool is_valid_unicode(wchar_t wc)
|
|||||||
* is, and FALSE otherwise. */
|
* is, and FALSE otherwise. */
|
||||||
bool is_valid_mbstring(const char *s)
|
bool is_valid_mbstring(const char *s)
|
||||||
{
|
{
|
||||||
assert(s != NULL);
|
|
||||||
|
|
||||||
#ifdef ENABLE_UTF8
|
#ifdef ENABLE_UTF8
|
||||||
if (use_utf8)
|
if (use_utf8)
|
||||||
return (mbstowcs(NULL, s, 0) != (size_t)-1);
|
return (mbstowcs(NULL, s, 0) != (size_t)-1);
|
||||||
|
14
src/files.c
14
src/files.c
@ -750,8 +750,6 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw
|
|||||||
/* 0 = *nix, 1 = DOS, 2 = Mac, 3 = both DOS and Mac. */
|
/* 0 = *nix, 1 = DOS, 2 = Mac, 3 = both DOS and Mac. */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
assert(openfile->fileage != NULL && openfile->current != NULL);
|
|
||||||
|
|
||||||
buf = charalloc(bufx);
|
buf = charalloc(bufx);
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
@ -1700,8 +1698,6 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
|
|||||||
char *tempname = NULL;
|
char *tempname = NULL;
|
||||||
/* The name of the temporary file we write to on prepend. */
|
/* The name of the temporary file we write to on prepend. */
|
||||||
|
|
||||||
assert(name != NULL);
|
|
||||||
|
|
||||||
if (*name == '\0')
|
if (*name == '\0')
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -1994,10 +1990,6 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* There might not be a magicline. There won't be when writing out
|
|
||||||
* a selection. */
|
|
||||||
assert(openfile->fileage != NULL && openfile->filebot != NULL);
|
|
||||||
|
|
||||||
while (fileptr != NULL) {
|
while (fileptr != NULL) {
|
||||||
size_t data_len = strlen(fileptr->data), size;
|
size_t data_len = strlen(fileptr->data), size;
|
||||||
|
|
||||||
@ -2145,8 +2137,6 @@ bool write_marked_file(const char *name, FILE *f_open, bool tmp,
|
|||||||
filestruct *top, *bot;
|
filestruct *top, *bot;
|
||||||
size_t top_x, bot_x;
|
size_t top_x, bot_x;
|
||||||
|
|
||||||
assert(openfile->mark_set);
|
|
||||||
|
|
||||||
/* Partition the filestruct so that it contains only the marked text. */
|
/* Partition the filestruct so that it contains only the marked text. */
|
||||||
mark_order((const filestruct **)&top, &top_x,
|
mark_order((const filestruct **)&top, &top_x,
|
||||||
(const filestruct **)&bot, &bot_x, NULL);
|
(const filestruct **)&bot, &bot_x, NULL);
|
||||||
@ -2460,8 +2450,6 @@ char *real_dir_from_tilde(const char *buf)
|
|||||||
{
|
{
|
||||||
char *retval;
|
char *retval;
|
||||||
|
|
||||||
assert(buf != NULL);
|
|
||||||
|
|
||||||
if (*buf == '~') {
|
if (*buf == '~') {
|
||||||
size_t i = 1;
|
size_t i = 1;
|
||||||
char *tilde_dir;
|
char *tilde_dir;
|
||||||
@ -2544,8 +2532,6 @@ bool is_dir(const char *buf)
|
|||||||
struct stat fileinfo;
|
struct stat fileinfo;
|
||||||
bool retval;
|
bool retval;
|
||||||
|
|
||||||
assert(buf != NULL);
|
|
||||||
|
|
||||||
dirptr = real_dir_from_tilde(buf);
|
dirptr = real_dir_from_tilde(buf);
|
||||||
|
|
||||||
retval = (stat(dirptr, &fileinfo) != -1 && S_ISDIR(fileinfo.st_mode));
|
retval = (stat(dirptr, &fileinfo) != -1 && S_ISDIR(fileinfo.st_mode));
|
||||||
|
17
src/nano.c
17
src/nano.c
@ -78,8 +78,6 @@ filestruct *copy_node(const filestruct *src)
|
|||||||
{
|
{
|
||||||
filestruct *dst;
|
filestruct *dst;
|
||||||
|
|
||||||
assert(src != NULL);
|
|
||||||
|
|
||||||
dst = (filestruct *)nmalloc(sizeof(filestruct));
|
dst = (filestruct *)nmalloc(sizeof(filestruct));
|
||||||
|
|
||||||
dst->data = mallocstrcpy(NULL, src->data);
|
dst->data = mallocstrcpy(NULL, src->data);
|
||||||
@ -96,8 +94,6 @@ filestruct *copy_node(const filestruct *src)
|
|||||||
/* Splice a new node into an existing linked list of filestructs. */
|
/* Splice a new node into an existing linked list of filestructs. */
|
||||||
void splice_node(filestruct *afterthis, filestruct *newnode)
|
void splice_node(filestruct *afterthis, filestruct *newnode)
|
||||||
{
|
{
|
||||||
assert(afterthis != NULL && newnode != NULL);
|
|
||||||
|
|
||||||
newnode->next = afterthis->next;
|
newnode->next = afterthis->next;
|
||||||
newnode->prev = afterthis;
|
newnode->prev = afterthis;
|
||||||
if (afterthis->next != NULL)
|
if (afterthis->next != NULL)
|
||||||
@ -112,8 +108,6 @@ void splice_node(filestruct *afterthis, filestruct *newnode)
|
|||||||
/* Disconnect a node from a linked list of filestructs and delete it. */
|
/* Disconnect a node from a linked list of filestructs and delete it. */
|
||||||
void unlink_node(filestruct *fileptr)
|
void unlink_node(filestruct *fileptr)
|
||||||
{
|
{
|
||||||
assert(fileptr != NULL);
|
|
||||||
|
|
||||||
if (fileptr->prev != NULL)
|
if (fileptr->prev != NULL)
|
||||||
fileptr->prev->next = fileptr->next;
|
fileptr->prev->next = fileptr->next;
|
||||||
if (fileptr->next != NULL)
|
if (fileptr->next != NULL)
|
||||||
@ -129,8 +123,6 @@ void unlink_node(filestruct *fileptr)
|
|||||||
/* Free the data structures in the given node. */
|
/* Free the data structures in the given node. */
|
||||||
void delete_node(filestruct *fileptr)
|
void delete_node(filestruct *fileptr)
|
||||||
{
|
{
|
||||||
assert(fileptr != NULL && fileptr->data != NULL);
|
|
||||||
|
|
||||||
free(fileptr->data);
|
free(fileptr->data);
|
||||||
#ifndef DISABLE_COLOR
|
#ifndef DISABLE_COLOR
|
||||||
free(fileptr->multidata);
|
free(fileptr->multidata);
|
||||||
@ -143,8 +135,6 @@ filestruct *copy_filestruct(const filestruct *src)
|
|||||||
{
|
{
|
||||||
filestruct *head, *copy;
|
filestruct *head, *copy;
|
||||||
|
|
||||||
assert(src != NULL);
|
|
||||||
|
|
||||||
copy = copy_node(src);
|
copy = copy_node(src);
|
||||||
copy->prev = NULL;
|
copy->prev = NULL;
|
||||||
head = copy;
|
head = copy;
|
||||||
@ -513,8 +503,7 @@ openfilestruct *make_new_opennode(void)
|
|||||||
/* Unlink a node from the rest of the openfilestruct, and delete it. */
|
/* Unlink a node from the rest of the openfilestruct, and delete it. */
|
||||||
void unlink_opennode(openfilestruct *fileptr)
|
void unlink_opennode(openfilestruct *fileptr)
|
||||||
{
|
{
|
||||||
assert(fileptr != NULL && fileptr->prev != NULL && fileptr->next != NULL &&
|
assert(fileptr != fileptr->prev && fileptr != fileptr->next);
|
||||||
fileptr != fileptr->prev && fileptr != fileptr->next);
|
|
||||||
|
|
||||||
fileptr->prev->next = fileptr->next;
|
fileptr->prev->next = fileptr->next;
|
||||||
fileptr->next->prev = fileptr->prev;
|
fileptr->next->prev = fileptr->prev;
|
||||||
@ -525,8 +514,6 @@ void unlink_opennode(openfilestruct *fileptr)
|
|||||||
/* Free all the memory in the given open-file node. */
|
/* Free all the memory in the given open-file node. */
|
||||||
void delete_opennode(openfilestruct *fileptr)
|
void delete_opennode(openfilestruct *fileptr)
|
||||||
{
|
{
|
||||||
assert(fileptr != NULL && fileptr->filename != NULL && fileptr->fileage != NULL);
|
|
||||||
|
|
||||||
free(fileptr->filename);
|
free(fileptr->filename);
|
||||||
free_filestruct(fileptr->fileage);
|
free_filestruct(fileptr->fileage);
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
@ -1828,8 +1815,6 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
|
|||||||
char *char_buf = charalloc(mb_cur_max());
|
char *char_buf = charalloc(mb_cur_max());
|
||||||
int char_buf_len;
|
int char_buf_len;
|
||||||
|
|
||||||
assert(openfile->current != NULL && openfile->current->data != NULL);
|
|
||||||
|
|
||||||
current_len = strlen(openfile->current->data);
|
current_len = strlen(openfile->current->data);
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
|
12
src/utils.c
12
src/utils.c
@ -153,8 +153,6 @@ void align(char **str)
|
|||||||
/* Null a string at a certain index and align it. */
|
/* Null a string at a certain index and align it. */
|
||||||
void null_at(char **data, size_t index)
|
void null_at(char **data, size_t index)
|
||||||
{
|
{
|
||||||
assert(data != NULL);
|
|
||||||
|
|
||||||
*data = charealloc(*data, index + 1);
|
*data = charealloc(*data, index + 1);
|
||||||
(*data)[index] = '\0';
|
(*data)[index] = '\0';
|
||||||
}
|
}
|
||||||
@ -163,8 +161,6 @@ void null_at(char **data, size_t index)
|
|||||||
* normally have newlines in it, so encode its nulls as newlines. */
|
* normally have newlines in it, so encode its nulls as newlines. */
|
||||||
void unsunder(char *str, size_t true_len)
|
void unsunder(char *str, size_t true_len)
|
||||||
{
|
{
|
||||||
assert(str != NULL);
|
|
||||||
|
|
||||||
for (; true_len > 0; true_len--, str++) {
|
for (; true_len > 0; true_len--, str++) {
|
||||||
if (*str == '\0')
|
if (*str == '\0')
|
||||||
*str = '\n';
|
*str = '\n';
|
||||||
@ -175,8 +171,6 @@ void unsunder(char *str, size_t true_len)
|
|||||||
* normally have newlines in it, so decode its newlines as nulls. */
|
* normally have newlines in it, so decode its newlines as nulls. */
|
||||||
void sunder(char *str)
|
void sunder(char *str)
|
||||||
{
|
{
|
||||||
assert(str != NULL);
|
|
||||||
|
|
||||||
for (; *str != '\0'; str++) {
|
for (; *str != '\0'; str++) {
|
||||||
if (*str == '\n')
|
if (*str == '\n')
|
||||||
*str = '\0';
|
*str = '\0';
|
||||||
@ -475,8 +469,6 @@ size_t get_page_start(size_t column)
|
|||||||
* column position of the cursor. */
|
* column position of the cursor. */
|
||||||
size_t xplustabs(void)
|
size_t xplustabs(void)
|
||||||
{
|
{
|
||||||
assert(openfile->current != NULL);
|
|
||||||
|
|
||||||
return strnlenpt(openfile->current->data, openfile->current_x);
|
return strnlenpt(openfile->current->data, openfile->current_x);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -489,8 +481,6 @@ size_t actual_x(const char *text, size_t column)
|
|||||||
size_t width = 0;
|
size_t width = 0;
|
||||||
/* The screen display width to text[index], in columns. */
|
/* The screen display width to text[index], in columns. */
|
||||||
|
|
||||||
assert(text != NULL);
|
|
||||||
|
|
||||||
while (*text != '\0') {
|
while (*text != '\0') {
|
||||||
int charlen = parse_mbchar(text, NULL, &width);
|
int charlen = parse_mbchar(text, NULL, &width);
|
||||||
|
|
||||||
@ -514,8 +504,6 @@ size_t strnlenpt(const char *text, size_t maxlen)
|
|||||||
if (maxlen == 0)
|
if (maxlen == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
assert(text != NULL);
|
|
||||||
|
|
||||||
while (*text != '\0') {
|
while (*text != '\0') {
|
||||||
int charlen = parse_mbchar(text, NULL, &width);
|
int charlen = parse_mbchar(text, NULL, &width);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user