From: David Lawrence Ramsey Date: Thu, 26 May 2005 03:47:24 +0000 (+0000) Subject: replace all instances of strncpy() with charcpy(), since the only X-Git-Tag: v1.3.8~261 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=e3970f503c8cd62572645c4e42fbedf9112c4d30;p=nano.git replace all instances of strncpy() with charcpy(), since the only difference between them is that the former pads strings with nulls when they're longer than the number of characters specified, which doesn't appear to be used anywhere git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2542 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index c4b19680..738e597c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -29,6 +29,12 @@ CVS code - do_search(), do_replace(), nanogetstr(), and statusq(); removal of remove_node(), insert_node(), and get_history_completion(). (DLR) + - Replace all instances of strncpy() with charcpy(), since the + only difference between them is that the former pads strings + with nulls when they're longer than the number of characters + specified, which doesn't appear to be used anywhere. Changes + to input_tab(), do_browser(), do_enter(), replace_regexp(), + replace_line(), and mallocstrncpy(). (DLR) - cut.c: cut_line() - Set placewewant properly after cutting a line, to avoid a @@ -84,6 +90,8 @@ CVS code - since the first line in the file is 1. (DLR) - Start the search for a line from fileage instead of current (again). (DLR) + replace_regexp() + - Rename variable create_flag to create for consistency. (DLR) replace_line() - Make new_line_size and search_match_count size_t's, for consistency. (DLR) diff --git a/src/files.c b/src/files.c index b6611b9f..ed707eb6 100644 --- a/src/files.c +++ b/src/files.c @@ -2222,7 +2222,7 @@ char *input_tab(char *buf, size_t *place, bool *lastwastab, bool *list) *lastwastab = FALSE; buf = charealloc(buf, common_len + buflen - *place + 1); charmove(buf + common_len, buf + *place, buflen - *place + 1); - strncpy(buf, mzero, common_len); + charcpy(buf, mzero, common_len); *place = common_len; } else if (*lastwastab == FALSE || num_matches < 2) *lastwastab = TRUE; @@ -2718,12 +2718,12 @@ char *do_browser(char *path, DIR *dir) * mark it as such. */ if (stat(filelist[j], &st) == 0 && S_ISDIR(st.st_mode)) { - strncpy(foo, _("(dir)"), foo_len); + charcpy(foo, _("(dir)"), foo_len); foo[foo_len] = '\0'; } else strcpy(foo, "--"); } else if (S_ISDIR(st.st_mode)) { - strncpy(foo, _("(dir)"), foo_len); + charcpy(foo, _("(dir)"), foo_len); foo[foo_len] = '\0'; } else if (st.st_size < (1 << 10)) /* less than 1 k. */ sprintf(foo, "%4u B", (unsigned int)st.st_size); diff --git a/src/nano.c b/src/nano.c index a71af4df..caba0f48 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1413,7 +1413,7 @@ void do_enter(void) strcpy(&newnode->data[extra], current->data + current_x); #ifndef NANO_SMALL if (ISSET(AUTOINDENT)) { - strncpy(newnode->data, current->data, extra); + charcpy(newnode->data, current->data, extra); totsize += mbstrlen(newnode->data); } #endif diff --git a/src/proto.h b/src/proto.h index abdb3502..03aa79f8 100644 --- a/src/proto.h +++ b/src/proto.h @@ -513,7 +513,7 @@ void do_research(void); #endif void replace_abort(void); #ifdef HAVE_REGEX_H -int replace_regexp(char *string, bool create_flag); +int replace_regexp(char *string, bool create); #endif char *replace_line(const char *needle); ssize_t do_replace_loop(const char *needle, const filestruct diff --git a/src/search.c b/src/search.c index 6c670fa4..7236eb42 100644 --- a/src/search.c +++ b/src/search.c @@ -578,10 +578,10 @@ void replace_abort(void) } #ifdef HAVE_REGEX_H -int replace_regexp(char *string, bool create_flag) +int replace_regexp(char *string, bool create) { - /* Split personality here - if create_flag is FALSE, just calculate - * the size of the replacement line (necessary because of + /* We have a split personality here. If create is FALSE, just + * calculate the size of the replacement line (necessary because of * subexpressions \1 to \9 in the replaced text). */ const char *c = last_replace; @@ -595,7 +595,7 @@ int replace_regexp(char *string, bool create_flag) if (*c != '\\' || num < 1 || num > 9 || num > search_regexp.re_nsub) { - if (create_flag) + if (create) *string++ = *c; c++; new_size++; @@ -608,17 +608,17 @@ int replace_regexp(char *string, bool create_flag) /* But add the length of the subexpression to new_size. */ new_size += i; - /* And if create_flag is TRUE, append the result of the + /* And if create is TRUE, append the result of the * subexpression match to the new line. */ - if (create_flag) { - strncpy(string, current->data + current_x + + if (create) { + charcpy(string, current->data + current_x + regmatches[num].rm_so, i); string += i; } } } - if (create_flag) + if (create) *string = '\0'; return new_size; @@ -634,7 +634,7 @@ char *replace_line(const char *needle) #ifdef HAVE_REGEX_H if (ISSET(USE_REGEXP)) { search_match_count = regmatches[0].rm_eo - regmatches[0].rm_so; - new_line_size = replace_regexp(NULL, 0); + new_line_size = replace_regexp(NULL, FALSE); } else { #endif search_match_count = strlen(needle); @@ -648,7 +648,7 @@ char *replace_line(const char *needle) copy = charalloc(new_line_size); /* The head of the original line. */ - strncpy(copy, current->data, current_x); + charcpy(copy, current->data, current_x); /* The replacement text. */ #ifdef HAVE_REGEX_H diff --git a/src/utils.c b/src/utils.c index c2ca4356..350ccccd 100644 --- a/src/utils.c +++ b/src/utils.c @@ -350,7 +350,7 @@ char *mallocstrncpy(char *dest, const char *src, size_t n) free(dest); dest = charalloc(n); - strncpy(dest, src, n); + charcpy(dest, src, n); return dest; }